# HG changeset patch # User neko259 # Date 2015-01-04 19:52:26 # Node ID 06775760875bc2dbef3c05d6ebd70fc19339d83d # Parent 3aa27a4d0229c842d5de514411fed4784cc312ed Fixed calls to render shortcut to use dict instead of context instance diff --git a/boards/views/all_tags.py b/boards/views/all_tags.py --- a/boards/views/all_tags.py +++ b/boards/views/all_tags.py @@ -7,8 +7,8 @@ from boards.models.tag import Tag class AllTagsView(BaseBoardView): def get(self, request): - context = self.get_context_data(request=request) - context['all_tags'] = Tag.objects.get_not_empty_tags() + params = dict() - # TODO Use dict here - return render(request, 'boards/tags.html', context_instance=context) + params['all_tags'] = Tag.objects.get_not_empty_tags() + + return render(request, 'boards/tags.html', params) diff --git a/boards/views/all_threads.py b/boards/views/all_threads.py --- a/boards/views/all_threads.py +++ b/boards/views/all_threads.py @@ -33,7 +33,7 @@ class AllThreadsView(PostMixin, BaseBoar super(AllThreadsView, self).__init__() def get(self, request, page=DEFAULT_PAGE, form=None): - context = self.get_context_data(request=request) + params = dict() if not form: form = ThreadForm(error_class=PlainErrorList) @@ -45,13 +45,12 @@ class AllThreadsView(PostMixin, BaseBoar threads = paginator.page(page).object_list - context[PARAMETER_THREADS] = threads - context[CONTEXT_FORM] = form + params[PARAMETER_THREADS] = threads + params[CONTEXT_FORM] = form - self._get_page_context(paginator, context, page) + self._get_page_context(paginator, params, page) - # TODO Use dict here - return render(request, TEMPLATE, context_instance=context) + return render(request, TEMPLATE, params) def post(self, request, page=DEFAULT_PAGE): form = ThreadForm(request.POST, request.FILES, @@ -66,14 +65,13 @@ class AllThreadsView(PostMixin, BaseBoar return self.get(request, page, form) - @staticmethod - def _get_page_context(paginator, context, page): + def _get_page_context(self, paginator, params, page): """ Get pagination context variables """ - context[PARAMETER_PAGINATOR] = paginator - context[PARAMETER_CURRENT_PAGE] = paginator.page(int(page)) + params[PARAMETER_PAGINATOR] = paginator + params[PARAMETER_CURRENT_PAGE] = paginator.page(int(page)) @staticmethod def parse_tags_string(tag_strings): diff --git a/boards/views/authors.py b/boards/views/authors.py --- a/boards/views/authors.py +++ b/boards/views/authors.py @@ -7,8 +7,7 @@ from boards.views.base import BaseBoardV class AuthorsView(BaseBoardView): def get(self, request): - context = self.get_context_data(request=request) - context['authors'] = authors + params = dict() + params['authors'] = authors - # TODO Use dict here - return render(request, 'boards/authors.html', context_instance=context) + return render(request, 'boards/authors.html', params) diff --git a/boards/views/banned.py b/boards/views/banned.py --- a/boards/views/banned.py +++ b/boards/views/banned.py @@ -9,11 +9,9 @@ class BannedView(BaseBoardView): def get(self, request): """Show the page that notifies that user is banned""" - context = self.get_context_data(request=request) + params = dict() ban = get_object_or_404(Ban, ip=utils.get_client_ip(request)) - context['ban_reason'] = ban.reason + params['ban_reason'] = ban.reason - # TODO Use dict here - return render(request, 'boards/staticpages/banned.html', - context_instance=context) + return render(request, 'boards/staticpages/banned.html', params) diff --git a/boards/views/thread.py b/boards/views/thread.py --- a/boards/views/thread.py +++ b/boards/views/thread.py @@ -53,45 +53,44 @@ class ThreadView(BaseBoardView, PostMixi thread_to_show = opening_post.get_thread() - context = self.get_context_data(request=request) + params = dict() - context[CONTEXT_FORM] = form - context[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch( + params[CONTEXT_FORM] = form + params[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch( thread_to_show.last_edit_time)) - context[CONTEXT_THREAD] = thread_to_show - context[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD + params[CONTEXT_THREAD] = thread_to_show + params[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD if settings.WEBSOCKETS_ENABLED: - context[CONTEXT_WS_TOKEN] = utils.get_websocket_token( - timestamp=context[CONTEXT_LASTUPDATE]) - context[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID - context[CONTEXT_WS_HOST] = request.get_host().split(':')[0] - context[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT + params[CONTEXT_WS_TOKEN] = utils.get_websocket_token( + timestamp=params[CONTEXT_LASTUPDATE]) + params[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID + params[CONTEXT_WS_HOST] = request.get_host().split(':')[0] + params[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT # TODO Move this to subclasses: NormalThreadView, GalleryThreadView etc if MODE_NORMAL == mode: bumpable = thread_to_show.can_bump() - context[CONTEXT_BUMPABLE] = bumpable + params[CONTEXT_BUMPABLE] = bumpable if bumpable: left_posts = settings.MAX_POSTS_PER_THREAD \ - thread_to_show.get_reply_count() - context[CONTEXT_POSTS_LEFT] = left_posts - context[CONTEXT_BUMPLIMIT_PRG] = str( + params[CONTEXT_POSTS_LEFT] = left_posts + params[CONTEXT_BUMPLIMIT_PRG] = str( float(left_posts) / settings.MAX_POSTS_PER_THREAD * 100) - context[CONTEXT_OP] = opening_post + params[CONTEXT_OP] = opening_post document = TEMPLATE_NORMAL elif MODE_GALLERY == mode: - context[CONTEXT_POSTS] = thread_to_show.get_replies_with_images( + params[CONTEXT_POSTS] = thread_to_show.get_replies_with_images( view_fields_only=True) document = TEMPLATE_GALLERY else: raise Http404 - # TODO Use dict here - return render(request, document, context_instance=context) + return render(request, document, params) def post(self, request, post_id, mode=MODE_NORMAL): opening_post = get_object_or_404(Post, id=post_id)