##// END OF EJS Templates
Fixed calls to render shortcut to use dict instead of context instance
neko259 -
r918:06775760 default
parent child Browse files
Show More
@@ -7,8 +7,8 b' from boards.models.tag import Tag'
7 7 class AllTagsView(BaseBoardView):
8 8
9 9 def get(self, request):
10 context = self.get_context_data(request=request)
11 context['all_tags'] = Tag.objects.get_not_empty_tags()
10 params = dict()
12 11
13 # TODO Use dict here
14 return render(request, 'boards/tags.html', context_instance=context)
12 params['all_tags'] = Tag.objects.get_not_empty_tags()
13
14 return render(request, 'boards/tags.html', params)
@@ -33,7 +33,7 b' class AllThreadsView(PostMixin, BaseBoar'
33 33 super(AllThreadsView, self).__init__()
34 34
35 35 def get(self, request, page=DEFAULT_PAGE, form=None):
36 context = self.get_context_data(request=request)
36 params = dict()
37 37
38 38 if not form:
39 39 form = ThreadForm(error_class=PlainErrorList)
@@ -45,13 +45,12 b' class AllThreadsView(PostMixin, BaseBoar'
45 45
46 46 threads = paginator.page(page).object_list
47 47
48 context[PARAMETER_THREADS] = threads
49 context[CONTEXT_FORM] = form
48 params[PARAMETER_THREADS] = threads
49 params[CONTEXT_FORM] = form
50 50
51 self._get_page_context(paginator, context, page)
51 self._get_page_context(paginator, params, page)
52 52
53 # TODO Use dict here
54 return render(request, TEMPLATE, context_instance=context)
53 return render(request, TEMPLATE, params)
55 54
56 55 def post(self, request, page=DEFAULT_PAGE):
57 56 form = ThreadForm(request.POST, request.FILES,
@@ -66,14 +65,13 b' class AllThreadsView(PostMixin, BaseBoar'
66 65
67 66 return self.get(request, page, form)
68 67
69 @staticmethod
70 def _get_page_context(paginator, context, page):
68 def _get_page_context(self, paginator, params, page):
71 69 """
72 70 Get pagination context variables
73 71 """
74 72
75 context[PARAMETER_PAGINATOR] = paginator
76 context[PARAMETER_CURRENT_PAGE] = paginator.page(int(page))
73 params[PARAMETER_PAGINATOR] = paginator
74 params[PARAMETER_CURRENT_PAGE] = paginator.page(int(page))
77 75
78 76 @staticmethod
79 77 def parse_tags_string(tag_strings):
@@ -7,8 +7,7 b' from boards.views.base import BaseBoardV'
7 7 class AuthorsView(BaseBoardView):
8 8
9 9 def get(self, request):
10 context = self.get_context_data(request=request)
11 context['authors'] = authors
10 params = dict()
11 params['authors'] = authors
12 12
13 # TODO Use dict here
14 return render(request, 'boards/authors.html', context_instance=context)
13 return render(request, 'boards/authors.html', params)
@@ -9,11 +9,9 b' class BannedView(BaseBoardView):'
9 9 def get(self, request):
10 10 """Show the page that notifies that user is banned"""
11 11
12 context = self.get_context_data(request=request)
12 params = dict()
13 13
14 14 ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
15 context['ban_reason'] = ban.reason
15 params['ban_reason'] = ban.reason
16 16
17 # TODO Use dict here
18 return render(request, 'boards/staticpages/banned.html',
19 context_instance=context)
17 return render(request, 'boards/staticpages/banned.html', params)
@@ -53,45 +53,44 b' class ThreadView(BaseBoardView, PostMixi'
53 53
54 54 thread_to_show = opening_post.get_thread()
55 55
56 context = self.get_context_data(request=request)
56 params = dict()
57 57
58 context[CONTEXT_FORM] = form
59 context[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch(
58 params[CONTEXT_FORM] = form
59 params[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch(
60 60 thread_to_show.last_edit_time))
61 context[CONTEXT_THREAD] = thread_to_show
62 context[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD
61 params[CONTEXT_THREAD] = thread_to_show
62 params[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD
63 63
64 64 if settings.WEBSOCKETS_ENABLED:
65 context[CONTEXT_WS_TOKEN] = utils.get_websocket_token(
66 timestamp=context[CONTEXT_LASTUPDATE])
67 context[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID
68 context[CONTEXT_WS_HOST] = request.get_host().split(':')[0]
69 context[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT
65 params[CONTEXT_WS_TOKEN] = utils.get_websocket_token(
66 timestamp=params[CONTEXT_LASTUPDATE])
67 params[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID
68 params[CONTEXT_WS_HOST] = request.get_host().split(':')[0]
69 params[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT
70 70
71 71 # TODO Move this to subclasses: NormalThreadView, GalleryThreadView etc
72 72 if MODE_NORMAL == mode:
73 73 bumpable = thread_to_show.can_bump()
74 context[CONTEXT_BUMPABLE] = bumpable
74 params[CONTEXT_BUMPABLE] = bumpable
75 75 if bumpable:
76 76 left_posts = settings.MAX_POSTS_PER_THREAD \
77 77 - thread_to_show.get_reply_count()
78 context[CONTEXT_POSTS_LEFT] = left_posts
79 context[CONTEXT_BUMPLIMIT_PRG] = str(
78 params[CONTEXT_POSTS_LEFT] = left_posts
79 params[CONTEXT_BUMPLIMIT_PRG] = str(
80 80 float(left_posts) / settings.MAX_POSTS_PER_THREAD * 100)
81 81
82 context[CONTEXT_OP] = opening_post
82 params[CONTEXT_OP] = opening_post
83 83
84 84 document = TEMPLATE_NORMAL
85 85 elif MODE_GALLERY == mode:
86 context[CONTEXT_POSTS] = thread_to_show.get_replies_with_images(
86 params[CONTEXT_POSTS] = thread_to_show.get_replies_with_images(
87 87 view_fields_only=True)
88 88
89 89 document = TEMPLATE_GALLERY
90 90 else:
91 91 raise Http404
92 92
93 # TODO Use dict here
94 return render(request, document, context_instance=context)
93 return render(request, document, params)
95 94
96 95 def post(self, request, post_id, mode=MODE_NORMAL):
97 96 opening_post = get_object_or_404(Post, id=post_id)
General Comments 0
You need to be logged in to leave comments. Login now