diff --git a/boards/authors.py b/boards/authors.py --- a/boards/authors.py +++ b/boards/authors.py @@ -1,6 +1,10 @@ +__author__ = 'neko259' + from django.utils.translation import ugettext_lazy as _ -__author__ = 'neko259' +ATTR_ROLES = 'roles' +ATTR_CONTACTS = 'contacts' +ATTR_NAME = 'name' ROLE_AUTHOR = _('author') ROLE_DEVELOPER = _('developer') @@ -9,23 +13,23 @@ ROLE_DESIGNER = _('designer') authors = { 'neko259': { - 'name': 'Pavel Ryapolov', - 'contacts': ['neko259@gmail.com'], - 'roles': [ROLE_AUTHOR, ROLE_DEVELOPER], + ATTR_NAME: 'Pavel Ryapolov', + ATTR_CONTACTS: ['neko259@gmail.com'], + ATTR_ROLES: [ROLE_AUTHOR, ROLE_DEVELOPER], }, 'ilyas': { - 'name': 'Ilyas Babayev', - 'contacts': ['zamesilyasa@gmail.com'], - 'roles': [ROLE_AUTHOR, ROLE_DEVELOPER], + ATTR_NAME: 'Ilyas Babayev', + ATTR_CONTACTS: ['zamesilyasa@gmail.com'], + ATTR_ROLES: [ROLE_AUTHOR, ROLE_DEVELOPER], }, 'ritsufag': { - 'name': 'Aiko Kirino', - 'contacts': ['ritsufag@gmail.com'], - 'roles': [ROLE_JS_DEV, ROLE_DESIGNER], + ATTR_NAME: 'Aiko Kirino', + ATTR_CONTACTS: ['ritsufag@gmail.com'], + ATTR_ROLES: [ROLE_JS_DEV, ROLE_DESIGNER], }, 'Tenno Seremel': { - 'name': 'anonymous', - 'contacts': ['html@serenareem.net'], - 'roles': [ROLE_JS_DEV, ROLE_DESIGNER], + ATTR_NAME: 'anonymous', + ATTR_CONTACTS: ['html@serenareem.net'], + ATTR_ROLES: [ROLE_JS_DEV, ROLE_DESIGNER], }, } \ No newline at end of file diff --git a/boards/context_processors.py b/boards/context_processors.py --- a/boards/context_processors.py +++ b/boards/context_processors.py @@ -1,30 +1,39 @@ +__author__ = 'neko259' + from boards import utils, settings from boards.models import Post from boards.models.post import SETTING_MODERATE -__author__ = 'neko259' +CONTEXT_SITE_NAME = 'site_name' +CONTEXT_VERSION = 'version' +CONTEXT_MODERATOR = 'moderator' +CONTEXT_THEME_CSS = 'theme_css' +CONTEXT_THEME = 'theme' +CONTEXT_PPD = 'posts_per_day' +CONTEXT_TAGS = 'tags' +CONTEXT_USER = 'user' def user_and_ui_processor(request): context = {} user = utils.get_user(request) - context['user'] = user - context['tags'] = user.fav_tags.all() - context['posts_per_day'] = float(Post.objects.get_posts_per_day()) + context[CONTEXT_USER] = user + context[CONTEXT_TAGS] = user.fav_tags.all() + context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day()) theme = utils.get_theme(request, user) - context['theme'] = theme - context['theme_css'] = 'css/' + theme + '/base_page.css' + context[CONTEXT_THEME] = theme + context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css' # This shows the moderator panel moderate = user.get_setting(SETTING_MODERATE) if moderate == 'True': - context['moderator'] = user.is_moderator() + context[CONTEXT_MODERATOR] = user.is_moderator() else: - context['moderator'] = False + context[CONTEXT_MODERATOR] = False - context['version'] = settings.VERSION - context['site_name'] = settings.SITE_NAME + context[CONTEXT_VERSION] = settings.VERSION + context[CONTEXT_SITE_NAME] = settings.SITE_NAME return context \ No newline at end of file diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -107,7 +107,8 @@ class PostForm(NeboardForm): widget=FormatPanel(attrs={ATTRIBUTE_PLACEHOLDER: TEXT_PLACEHOLDER}), required=False, label=LABEL_TEXT) image = forms.ImageField(required=False, label=_('Image'), - widget=forms.ClearableFileInput(attrs={'accept': 'image/*'})) + widget=forms.ClearableFileInput( + attrs={'accept': 'image/*'})) # This field is for spam prevention only email = forms.CharField(max_length=100, required=False, label=_('e-mail'), @@ -139,7 +140,7 @@ class PostForm(NeboardForm): def clean_image(self): image = self.cleaned_data['image'] if image: - if image._size > board_settings.MAX_IMAGE_SIZE: + if image.size > board_settings.MAX_IMAGE_SIZE: raise forms.ValidationError( _('Image must be less than %s bytes') % str(board_settings.MAX_IMAGE_SIZE)) diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -1,10 +1,12 @@ # coding=utf-8 import markdown -from markdown.inlinepatterns import Pattern, SubstituteTagPattern +from markdown.inlinepatterns import Pattern from markdown.util import etree + import boards + __author__ = 'neko259' @@ -22,6 +24,9 @@ class TextFormatter(): An interface for formatter that can be used in the text format panel """ + def __init__(self): + pass + name = '' # Left and right tags for the button preview diff --git a/boards/middlewares.py b/boards/middlewares.py --- a/boards/middlewares.py +++ b/boards/middlewares.py @@ -16,6 +16,9 @@ class BanMiddleware: anything """ + def __init__(self): + pass + def process_view(self, request, view_func, view_args, view_kwargs): if view_func != BannedView.as_view: @@ -36,7 +39,8 @@ class MinifyHTMLMiddleware(object): compress_html = False if RESPONSE_CONTENT_TYPE in response\ - and TYPE_HTML in response[RESPONSE_CONTENT_TYPE] and compress_html: + and TYPE_HTML in response[RESPONSE_CONTENT_TYPE]\ + and compress_html: response.content = strip_spaces_between_tags( response.content.strip()) return response \ No newline at end of file diff --git a/boards/profiler.py b/boards/profiler.py --- a/boards/profiler.py +++ b/boards/profiler.py @@ -4,7 +4,10 @@ from django.conf import settings import line_profiler -class ProfilerMiddleware(object): +class ProfilerMiddleware(): + def __init__(self): + self.profiler = None + def process_view(self, request, callback, callback_args, callback_kwargs): if settings.DEBUG and 'prof' in request.GET: self.profiler = line_profiler.LineProfiler() diff --git a/boards/views/search.py b/boards/views/search.py --- a/boards/views/search.py +++ b/boards/views/search.py @@ -5,6 +5,14 @@ from haystack.query import SearchQuerySe from boards.abstracts.paginator import get_paginator from boards.forms import SearchForm, PlainErrorList +FORM_QUERY = 'query' + +CONTEXT_QUERY = 'query' +CONTEXT_FORM = 'form' +CONTEXT_PAGE = 'page' + +REQUEST_PAGE = 'page' + __author__ = 'neko259' TEMPLATE = 'search/search.html' @@ -14,20 +22,20 @@ class BoardSearchView(View): def get(self, request): context = RequestContext(request) form = SearchForm(request.GET, error_class=PlainErrorList) - context['form'] = form + context[CONTEXT_FORM] = form if form.is_valid(): - query = form.cleaned_data['query'] + query = form.cleaned_data[FORM_QUERY] if len(query) >= 3: results = SearchQuerySet().auto_query(query).order_by('-id') \ .highlight() paginator = get_paginator(results, 10) - if 'page' in request.GET: - page = int(request.GET['page']) + if REQUEST_PAGE in request.GET: + page = int(request.GET[REQUEST_PAGE]) else: page = 1 - context['page'] = paginator.page(page) - context['query'] = query + context[CONTEXT_PAGE] = paginator.page(page) + context[CONTEXT_QUERY] = query return render(request, TEMPLATE, context) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +line_profiler haystack pillow django>=1.6