Show More
@@ -1,84 +1,90 | |||
|
1 | 1 | from boards.abstracts.settingsmanager import get_settings_manager, \ |
|
2 | 2 | SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER, SETTING_ONLY_FAVORITES |
|
3 | 3 | from boards.models import Banner |
|
4 | 4 | from boards.models.user import Notification |
|
5 | 5 | from boards import settings |
|
6 | 6 | from boards.models import Post, Tag, Thread |
|
7 | 7 | from boards.settings import SECTION_FORMS, SECTION_VIEW, SECTION_VERSION |
|
8 | 8 | |
|
9 | PATTERN_NEW_POSTS_COUNT = '(+{})' | |
|
10 | ||
|
9 | 11 | THEME_CSS = 'css/{}/base_page.css' |
|
10 | 12 | |
|
11 | 13 | CONTEXT_SITE_NAME = 'site_name' |
|
12 | 14 | CONTEXT_VERSION = 'version' |
|
13 | 15 | CONTEXT_THEME_CSS = 'theme_css' |
|
14 | 16 | CONTEXT_THEME = 'theme' |
|
15 | 17 | CONTEXT_PPD = 'posts_per_day' |
|
16 | 18 | CONTEXT_USER = 'user' |
|
17 | 19 | CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_notifications_count' |
|
18 | 20 | CONTEXT_USERNAMES = 'usernames' |
|
19 | 21 | CONTEXT_TAGS_STR = 'tags_str' |
|
20 | 22 | CONTEXT_IMAGE_VIEWER = 'image_viewer' |
|
21 | 23 | CONTEXT_HAS_FAV_THREADS = 'has_fav_threads' |
|
22 | 24 | CONTEXT_POW_DIFFICULTY = 'pow_difficulty' |
|
23 | 25 | CONTEXT_NEW_POST_COUNT = 'new_post_count' |
|
24 | 26 | CONTEXT_BANNERS = 'banners' |
|
25 | 27 | CONTEXT_ONLY_FAVORITES = 'only_favorites' |
|
26 | 28 | |
|
27 | 29 | |
|
28 | def get_notifications(context, settings_manager): | |
|
30 | def get_notifications(context, settings_manager, fav_tags): | |
|
29 | 31 | usernames = settings_manager.get_notification_usernames() |
|
30 | fav_tags = settings_manager.get_fav_tags() | |
|
32 | ||
|
31 | 33 | new_notifications_count = 0 |
|
34 | ||
|
32 | 35 | if usernames or fav_tags: |
|
33 | 36 | last_notification_id = settings_manager.get_setting( |
|
34 | 37 | SETTING_LAST_NOTIFICATION_ID) |
|
35 | 38 | |
|
36 | 39 | new_notifications_count = Notification.objects.get_notification_posts( |
|
37 | usernames=usernames, last=last_notification_id, user_settings=settings_manager.get_user_settings()).count() | |
|
40 | usernames=usernames, | |
|
41 | last=last_notification_id, | |
|
42 | user_settings=settings_manager.get_user_settings()).count() | |
|
43 | ||
|
38 | 44 | context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count |
|
39 | 45 | context[CONTEXT_USERNAMES] = usernames |
|
40 | 46 | |
|
41 | 47 | |
|
42 | 48 | def get_new_post_count(context, settings_manager): |
|
43 | 49 | last_posts = settings_manager.get_last_posts() |
|
44 | 50 | count = Thread.objects.get_new_post_count(last_posts) |
|
45 | 51 | if count > 0: |
|
46 |
context[CONTEXT_NEW_POST_COUNT] = |
|
|
52 | context[CONTEXT_NEW_POST_COUNT] = PATTERN_NEW_POSTS_COUNT.format(count) | |
|
47 | 53 | |
|
48 | 54 | |
|
49 | 55 | def user_and_ui_processor(request): |
|
50 | 56 | context = dict() |
|
51 | 57 | |
|
52 | 58 | context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day()) |
|
53 | 59 | |
|
54 | 60 | settings_manager = get_settings_manager(request) |
|
55 | 61 | fav_tags = settings_manager.get_fav_tags() |
|
56 | 62 | |
|
57 | 63 | context[CONTEXT_TAGS_STR] = Tag.objects.get_tag_url_list(fav_tags) |
|
58 | 64 | theme = settings_manager.get_theme() |
|
59 | 65 | context[CONTEXT_THEME] = theme |
|
60 | 66 | |
|
61 | 67 | # TODO Use static here |
|
62 | 68 | context[CONTEXT_THEME_CSS] = THEME_CSS.format(theme) |
|
63 | 69 | |
|
64 | 70 | context[CONTEXT_VERSION] = settings.get(SECTION_VERSION, 'Version') |
|
65 | 71 | context[CONTEXT_SITE_NAME] = settings.get(SECTION_VERSION, 'SiteName') |
|
66 | 72 | |
|
67 | 73 | if settings.get_bool(SECTION_FORMS, 'LimitFirstPosting'): |
|
68 | 74 | context[CONTEXT_POW_DIFFICULTY] = settings.get_int(SECTION_FORMS, 'PowDifficulty') |
|
69 | 75 | |
|
70 | 76 | context[CONTEXT_IMAGE_VIEWER] = settings_manager.get_setting( |
|
71 | 77 | SETTING_IMAGE_VIEWER, |
|
72 | 78 | default=settings.get(SECTION_VIEW, 'DefaultImageViewer')) |
|
73 | 79 | |
|
74 | 80 | context[CONTEXT_HAS_FAV_THREADS] =\ |
|
75 | 81 | len(settings_manager.get_last_posts()) > 0 |
|
76 | 82 | |
|
77 | 83 | context[CONTEXT_BANNERS] = Banner.objects.order_by('-id') |
|
78 | 84 | context[CONTEXT_ONLY_FAVORITES] = settings_manager.get_setting( |
|
79 | 85 | SETTING_ONLY_FAVORITES, default=False) |
|
80 | 86 | |
|
81 | get_notifications(context, settings_manager) | |
|
87 | get_notifications(context, settings_manager, fav_tags) | |
|
82 | 88 | get_new_post_count(context, settings_manager) |
|
83 | 89 | |
|
84 | 90 | return context |
General Comments 0
You need to be logged in to leave comments.
Login now