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