##// END OF EJS Templates
Small code cleanups
neko259 -
r721:1814d7a8 default
parent child Browse files
Show More
@@ -1,6 +1,10 b''
1 __author__ = 'neko259'
2
1 3 from django.utils.translation import ugettext_lazy as _
2 4
3 __author__ = 'neko259'
5 ATTR_ROLES = 'roles'
6 ATTR_CONTACTS = 'contacts'
7 ATTR_NAME = 'name'
4 8
5 9 ROLE_AUTHOR = _('author')
6 10 ROLE_DEVELOPER = _('developer')
@@ -9,23 +13,23 b" ROLE_DESIGNER = _('designer')"
9 13
10 14 authors = {
11 15 'neko259': {
12 'name': 'Pavel Ryapolov',
13 'contacts': ['neko259@gmail.com'],
14 'roles': [ROLE_AUTHOR, ROLE_DEVELOPER],
16 ATTR_NAME: 'Pavel Ryapolov',
17 ATTR_CONTACTS: ['neko259@gmail.com'],
18 ATTR_ROLES: [ROLE_AUTHOR, ROLE_DEVELOPER],
15 19 },
16 20 'ilyas': {
17 'name': 'Ilyas Babayev',
18 'contacts': ['zamesilyasa@gmail.com'],
19 'roles': [ROLE_AUTHOR, ROLE_DEVELOPER],
21 ATTR_NAME: 'Ilyas Babayev',
22 ATTR_CONTACTS: ['zamesilyasa@gmail.com'],
23 ATTR_ROLES: [ROLE_AUTHOR, ROLE_DEVELOPER],
20 24 },
21 25 'ritsufag': {
22 'name': 'Aiko Kirino',
23 'contacts': ['ritsufag@gmail.com'],
24 'roles': [ROLE_JS_DEV, ROLE_DESIGNER],
26 ATTR_NAME: 'Aiko Kirino',
27 ATTR_CONTACTS: ['ritsufag@gmail.com'],
28 ATTR_ROLES: [ROLE_JS_DEV, ROLE_DESIGNER],
25 29 },
26 30 'Tenno Seremel': {
27 'name': 'anonymous',
28 'contacts': ['html@serenareem.net'],
29 'roles': [ROLE_JS_DEV, ROLE_DESIGNER],
31 ATTR_NAME: 'anonymous',
32 ATTR_CONTACTS: ['html@serenareem.net'],
33 ATTR_ROLES: [ROLE_JS_DEV, ROLE_DESIGNER],
30 34 },
31 35 } No newline at end of file
@@ -1,30 +1,39 b''
1 __author__ = 'neko259'
2
1 3 from boards import utils, settings
2 4 from boards.models import Post
3 5 from boards.models.post import SETTING_MODERATE
4 6
5 __author__ = 'neko259'
7 CONTEXT_SITE_NAME = 'site_name'
8 CONTEXT_VERSION = 'version'
9 CONTEXT_MODERATOR = 'moderator'
10 CONTEXT_THEME_CSS = 'theme_css'
11 CONTEXT_THEME = 'theme'
12 CONTEXT_PPD = 'posts_per_day'
13 CONTEXT_TAGS = 'tags'
14 CONTEXT_USER = 'user'
6 15
7 16
8 17 def user_and_ui_processor(request):
9 18 context = {}
10 19
11 20 user = utils.get_user(request)
12 context['user'] = user
13 context['tags'] = user.fav_tags.all()
14 context['posts_per_day'] = float(Post.objects.get_posts_per_day())
21 context[CONTEXT_USER] = user
22 context[CONTEXT_TAGS] = user.fav_tags.all()
23 context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day())
15 24
16 25 theme = utils.get_theme(request, user)
17 context['theme'] = theme
18 context['theme_css'] = 'css/' + theme + '/base_page.css'
26 context[CONTEXT_THEME] = theme
27 context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css'
19 28
20 29 # This shows the moderator panel
21 30 moderate = user.get_setting(SETTING_MODERATE)
22 31 if moderate == 'True':
23 context['moderator'] = user.is_moderator()
32 context[CONTEXT_MODERATOR] = user.is_moderator()
24 33 else:
25 context['moderator'] = False
34 context[CONTEXT_MODERATOR] = False
26 35
27 context['version'] = settings.VERSION
28 context['site_name'] = settings.SITE_NAME
36 context[CONTEXT_VERSION] = settings.VERSION
37 context[CONTEXT_SITE_NAME] = settings.SITE_NAME
29 38
30 39 return context No newline at end of file
@@ -107,7 +107,8 b' class PostForm(NeboardForm):'
107 107 widget=FormatPanel(attrs={ATTRIBUTE_PLACEHOLDER: TEXT_PLACEHOLDER}),
108 108 required=False, label=LABEL_TEXT)
109 109 image = forms.ImageField(required=False, label=_('Image'),
110 widget=forms.ClearableFileInput(attrs={'accept': 'image/*'}))
110 widget=forms.ClearableFileInput(
111 attrs={'accept': 'image/*'}))
111 112
112 113 # This field is for spam prevention only
113 114 email = forms.CharField(max_length=100, required=False, label=_('e-mail'),
@@ -139,7 +140,7 b' class PostForm(NeboardForm):'
139 140 def clean_image(self):
140 141 image = self.cleaned_data['image']
141 142 if image:
142 if image._size > board_settings.MAX_IMAGE_SIZE:
143 if image.size > board_settings.MAX_IMAGE_SIZE:
143 144 raise forms.ValidationError(
144 145 _('Image must be less than %s bytes')
145 146 % str(board_settings.MAX_IMAGE_SIZE))
@@ -1,10 +1,12 b''
1 1 # coding=utf-8
2 2
3 3 import markdown
4 from markdown.inlinepatterns import Pattern, SubstituteTagPattern
4 from markdown.inlinepatterns import Pattern
5 5 from markdown.util import etree
6
6 7 import boards
7 8
9
8 10 __author__ = 'neko259'
9 11
10 12
@@ -22,6 +24,9 b' class TextFormatter():'
22 24 An interface for formatter that can be used in the text format panel
23 25 """
24 26
27 def __init__(self):
28 pass
29
25 30 name = ''
26 31
27 32 # Left and right tags for the button preview
@@ -16,6 +16,9 b' class BanMiddleware:'
16 16 anything
17 17 """
18 18
19 def __init__(self):
20 pass
21
19 22 def process_view(self, request, view_func, view_args, view_kwargs):
20 23
21 24 if view_func != BannedView.as_view:
@@ -36,7 +39,8 b' class MinifyHTMLMiddleware(object):'
36 39 compress_html = False
37 40
38 41 if RESPONSE_CONTENT_TYPE in response\
39 and TYPE_HTML in response[RESPONSE_CONTENT_TYPE] and compress_html:
42 and TYPE_HTML in response[RESPONSE_CONTENT_TYPE]\
43 and compress_html:
40 44 response.content = strip_spaces_between_tags(
41 45 response.content.strip())
42 46 return response No newline at end of file
@@ -4,7 +4,10 b' from django.conf import settings'
4 4 import line_profiler
5 5
6 6
7 class ProfilerMiddleware(object):
7 class ProfilerMiddleware():
8 def __init__(self):
9 self.profiler = None
10
8 11 def process_view(self, request, callback, callback_args, callback_kwargs):
9 12 if settings.DEBUG and 'prof' in request.GET:
10 13 self.profiler = line_profiler.LineProfiler()
@@ -5,6 +5,14 b' from haystack.query import SearchQuerySe'
5 5 from boards.abstracts.paginator import get_paginator
6 6 from boards.forms import SearchForm, PlainErrorList
7 7
8 FORM_QUERY = 'query'
9
10 CONTEXT_QUERY = 'query'
11 CONTEXT_FORM = 'form'
12 CONTEXT_PAGE = 'page'
13
14 REQUEST_PAGE = 'page'
15
8 16 __author__ = 'neko259'
9 17
10 18 TEMPLATE = 'search/search.html'
@@ -14,20 +22,20 b' class BoardSearchView(View):'
14 22 def get(self, request):
15 23 context = RequestContext(request)
16 24 form = SearchForm(request.GET, error_class=PlainErrorList)
17 context['form'] = form
25 context[CONTEXT_FORM] = form
18 26
19 27 if form.is_valid():
20 query = form.cleaned_data['query']
28 query = form.cleaned_data[FORM_QUERY]
21 29 if len(query) >= 3:
22 30 results = SearchQuerySet().auto_query(query).order_by('-id') \
23 31 .highlight()
24 32 paginator = get_paginator(results, 10)
25 33
26 if 'page' in request.GET:
27 page = int(request.GET['page'])
34 if REQUEST_PAGE in request.GET:
35 page = int(request.GET[REQUEST_PAGE])
28 36 else:
29 37 page = 1
30 context['page'] = paginator.page(page)
31 context['query'] = query
38 context[CONTEXT_PAGE] = paginator.page(page)
39 context[CONTEXT_QUERY] = query
32 40
33 41 return render(request, TEMPLATE, context) No newline at end of file
@@ -1,3 +1,4 b''
1 line_profiler
1 2 haystack
2 3 pillow
3 4 django>=1.6
General Comments 0
You need to be logged in to leave comments. Login now