##// END OF EJS Templates
Show moderator controls when downloading a single post over API. Removed duplicate code from get_post_data
neko259 -
r1109:d995bcab default
parent child Browse files
Show More
@@ -4,7 +4,7 b' from boards.models.user import Notificat'
4 4
5 5 __author__ = 'neko259'
6 6
7 from boards import settings
7 from boards import settings, utils
8 8 from boards.models import Post, Tag
9 9
10 10 CONTEXT_SITE_NAME = 'site_name'
@@ -19,7 +19,6 b" CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_n"
19 19 CONTEXT_USERNAME = 'username'
20 20 CONTEXT_TAGS_STR = 'tags_str'
21 21
22 PERMISSION_MODERATE = 'moderation'
23 22
24 23
25 24 def get_notifications(context, request):
@@ -36,14 +35,6 b' def get_notifications(context, request):'
36 35 context[CONTEXT_USERNAME] = username
37 36
38 37
39 def get_moderator_permissions(context, request):
40 try:
41 moderate = request.user.has_perm(PERMISSION_MODERATE)
42 except AttributeError:
43 moderate = False
44 context[CONTEXT_MODERATOR] = moderate
45
46
47 38 def user_and_ui_processor(request):
48 39 context = dict()
49 40
@@ -58,7 +49,7 b' def user_and_ui_processor(request):'
58 49 context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css'
59 50
60 51 # This shows the moderator panel
61 get_moderator_permissions(context, request)
52 context[CONTEXT_MODERATOR] = utils.is_moderator(request)
62 53
63 54 context[CONTEXT_VERSION] = settings.VERSION
64 55 context[CONTEXT_SITE_NAME] = settings.SITE_NAME
@@ -14,7 +14,7 b' from boards import settings'
14 14 from boards.mdx_neboard import Parser
15 15 from boards.models import PostImage
16 16 from boards.models.base import Viewable
17 from boards.utils import datetime_to_epoch, cached_result
17 from boards import utils
18 18 from boards.models.user import Notification, Ban
19 19 import boards.models.thread
20 20
@@ -122,7 +122,7 b' class PostManager(models.Manager):'
122 122 for post in posts:
123 123 post.delete()
124 124
125 @cached_result()
125 @utils.cached_result()
126 126 def get_posts_per_day(self) -> float:
127 127 """
128 128 Gets average count of posts per day for the last 7 days
@@ -209,7 +209,7 b' class Post(models.Model, Viewable):'
209 209
210 210 return self.get_thread().get_opening_post_id() == self.id
211 211
212 @cached_result()
212 @utils.cached_result()
213 213 def get_url(self):
214 214 """
215 215 Gets full url to the post.
@@ -294,6 +294,7 b' class Post(models.Model, Viewable):'
294 294 logging.getLogger('boards.post.delete').info(
295 295 'Deleted post {}'.format(self))
296 296
297 # TODO Implement this with OOP, e.g. use the factory and HtmlPostData class
297 298 def get_post_data(self, format_type=DIFF_TYPE_JSON, request=None,
298 299 include_last_update=False) -> str:
299 300 """
@@ -302,14 +303,15 b' class Post(models.Model, Viewable):'
302 303 """
303 304
304 305 if format_type == DIFF_TYPE_HTML:
305 params = dict()
306 params['post'] = self
307 306 if PARAMETER_TRUNCATED in request.GET:
308 params[PARAMETER_TRUNCATED] = True
307 truncated = True
308 reply_link = False
309 309 else:
310 params[PARAMETER_REPLY_LINK] = True
310 truncated = False
311 reply_link = True
311 312
312 return render_to_string('boards/api_post.html', params)
313 return self.get_view(truncated=truncated, reply_link=reply_link,
314 moderator=utils.is_moderator(request))
313 315 elif format_type == DIFF_TYPE_JSON:
314 316 post_json = {
315 317 'id': self.id,
@@ -321,7 +323,7 b' class Post(models.Model, Viewable):'
321 323 post_json['image'] = post_image.image.url
322 324 post_json['image_preview'] = post_image.image.url_200x150
323 325 if include_last_update:
324 post_json['bump_time'] = datetime_to_epoch(
326 post_json['bump_time'] = utils.datetime_to_epoch(
325 327 self.get_thread().bump_time)
326 328 return post_json
327 329
@@ -14,7 +14,7 b' from neboard import settings'
14 14
15 15
16 16 CACHE_KEY_DELIMITER = '_'
17
17 PERMISSION_MODERATE = 'moderation'
18 18
19 19 def get_client_ip(request):
20 20 x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
@@ -74,3 +74,12 b' def cached_result(key_method=None):'
74 74
75 75 return inner_func
76 76 return _cached_result
77
78
79 def is_moderator(request):
80 try:
81 moderate = request.user.has_perm(PERMISSION_MODERATE)
82 except AttributeError:
83 moderate = False
84
85 return moderate No newline at end of file
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now