Show More
@@ -4,7 +4,7 b' from boards.models.user import Notificat' | |||||
4 |
|
4 | |||
5 | __author__ = 'neko259' |
|
5 | __author__ = 'neko259' | |
6 |
|
6 | |||
7 | from boards import settings |
|
7 | from boards import settings, utils | |
8 | from boards.models import Post, Tag |
|
8 | from boards.models import Post, Tag | |
9 |
|
9 | |||
10 | CONTEXT_SITE_NAME = 'site_name' |
|
10 | CONTEXT_SITE_NAME = 'site_name' | |
@@ -19,7 +19,6 b" CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_n" | |||||
19 | CONTEXT_USERNAME = 'username' |
|
19 | CONTEXT_USERNAME = 'username' | |
20 | CONTEXT_TAGS_STR = 'tags_str' |
|
20 | CONTEXT_TAGS_STR = 'tags_str' | |
21 |
|
21 | |||
22 | PERMISSION_MODERATE = 'moderation' |
|
|||
23 |
|
22 | |||
24 |
|
23 | |||
25 | def get_notifications(context, request): |
|
24 | def get_notifications(context, request): | |
@@ -36,14 +35,6 b' def get_notifications(context, request):' | |||||
36 | context[CONTEXT_USERNAME] = username |
|
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 | def user_and_ui_processor(request): |
|
38 | def user_and_ui_processor(request): | |
48 | context = dict() |
|
39 | context = dict() | |
49 |
|
40 | |||
@@ -58,7 +49,7 b' def user_and_ui_processor(request):' | |||||
58 | context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css' |
|
49 | context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css' | |
59 |
|
50 | |||
60 | # This shows the moderator panel |
|
51 | # This shows the moderator panel | |
61 | get_moderator_permissions(context, request) |
|
52 | context[CONTEXT_MODERATOR] = utils.is_moderator(request) | |
62 |
|
53 | |||
63 | context[CONTEXT_VERSION] = settings.VERSION |
|
54 | context[CONTEXT_VERSION] = settings.VERSION | |
64 | context[CONTEXT_SITE_NAME] = settings.SITE_NAME |
|
55 | context[CONTEXT_SITE_NAME] = settings.SITE_NAME |
@@ -277,8 +277,8 b' class PostForm(NeboardForm):' | |||||
277 |
|
277 | |||
278 | can_post = False |
|
278 | can_post = False | |
279 |
|
279 | |||
280 | if can_post: |
|
280 | if can_post: | |
281 | self.session[LAST_POST_TIME] = now |
|
281 | self.session[LAST_POST_TIME] = now | |
282 |
|
282 | |||
283 | def validate_image_size(self, size: int): |
|
283 | def validate_image_size(self, size: int): | |
284 | if size > board_settings.MAX_IMAGE_SIZE: |
|
284 | if size > board_settings.MAX_IMAGE_SIZE: |
@@ -14,7 +14,7 b' from boards import settings' | |||||
14 | from boards.mdx_neboard import Parser |
|
14 | from boards.mdx_neboard import Parser | |
15 | from boards.models import PostImage |
|
15 | from boards.models import PostImage | |
16 | from boards.models.base import Viewable |
|
16 | from boards.models.base import Viewable | |
17 | from boards.utils import datetime_to_epoch, cached_result |
|
17 | from boards import utils | |
18 | from boards.models.user import Notification, Ban |
|
18 | from boards.models.user import Notification, Ban | |
19 | import boards.models.thread |
|
19 | import boards.models.thread | |
20 |
|
20 | |||
@@ -122,7 +122,7 b' class PostManager(models.Manager):' | |||||
122 | for post in posts: |
|
122 | for post in posts: | |
123 | post.delete() |
|
123 | post.delete() | |
124 |
|
124 | |||
125 | @cached_result() |
|
125 | @utils.cached_result() | |
126 | def get_posts_per_day(self) -> float: |
|
126 | def get_posts_per_day(self) -> float: | |
127 | """ |
|
127 | """ | |
128 | Gets average count of posts per day for the last 7 days |
|
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 | return self.get_thread().get_opening_post_id() == self.id |
|
210 | return self.get_thread().get_opening_post_id() == self.id | |
211 |
|
211 | |||
212 | @cached_result() |
|
212 | @utils.cached_result() | |
213 | def get_url(self): |
|
213 | def get_url(self): | |
214 | """ |
|
214 | """ | |
215 | Gets full url to the post. |
|
215 | Gets full url to the post. | |
@@ -294,6 +294,7 b' class Post(models.Model, Viewable):' | |||||
294 | logging.getLogger('boards.post.delete').info( |
|
294 | logging.getLogger('boards.post.delete').info( | |
295 | 'Deleted post {}'.format(self)) |
|
295 | 'Deleted post {}'.format(self)) | |
296 |
|
296 | |||
|
297 | # TODO Implement this with OOP, e.g. use the factory and HtmlPostData class | |||
297 | def get_post_data(self, format_type=DIFF_TYPE_JSON, request=None, |
|
298 | def get_post_data(self, format_type=DIFF_TYPE_JSON, request=None, | |
298 | include_last_update=False) -> str: |
|
299 | include_last_update=False) -> str: | |
299 | """ |
|
300 | """ | |
@@ -302,14 +303,15 b' class Post(models.Model, Viewable):' | |||||
302 | """ |
|
303 | """ | |
303 |
|
304 | |||
304 | if format_type == DIFF_TYPE_HTML: |
|
305 | if format_type == DIFF_TYPE_HTML: | |
305 | params = dict() |
|
|||
306 | params['post'] = self |
|
|||
307 | if PARAMETER_TRUNCATED in request.GET: |
|
306 | if PARAMETER_TRUNCATED in request.GET: | |
308 | params[PARAMETER_TRUNCATED] = True |
|
307 | truncated = True | |
|
308 | reply_link = False | |||
309 | else: |
|
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 | elif format_type == DIFF_TYPE_JSON: |
|
315 | elif format_type == DIFF_TYPE_JSON: | |
314 | post_json = { |
|
316 | post_json = { | |
315 | 'id': self.id, |
|
317 | 'id': self.id, | |
@@ -321,7 +323,7 b' class Post(models.Model, Viewable):' | |||||
321 | post_json['image'] = post_image.image.url |
|
323 | post_json['image'] = post_image.image.url | |
322 | post_json['image_preview'] = post_image.image.url_200x150 |
|
324 | post_json['image_preview'] = post_image.image.url_200x150 | |
323 | if include_last_update: |
|
325 | if include_last_update: | |
324 | post_json['bump_time'] = datetime_to_epoch( |
|
326 | post_json['bump_time'] = utils.datetime_to_epoch( | |
325 | self.get_thread().bump_time) |
|
327 | self.get_thread().bump_time) | |
326 | return post_json |
|
328 | return post_json | |
327 |
|
329 |
@@ -14,7 +14,7 b' from neboard import settings' | |||||
14 |
|
14 | |||
15 |
|
15 | |||
16 | CACHE_KEY_DELIMITER = '_' |
|
16 | CACHE_KEY_DELIMITER = '_' | |
17 |
|
17 | PERMISSION_MODERATE = 'moderation' | ||
18 |
|
18 | |||
19 | def get_client_ip(request): |
|
19 | def get_client_ip(request): | |
20 | x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') |
|
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 | return inner_func |
|
75 | return inner_func | |
76 | return _cached_result |
|
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 |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now