Show More
@@ -1,82 +1,86 b'' | |||||
1 | from boards.abstracts.settingsmanager import get_settings_manager, \ |
|
1 | from boards.abstracts.settingsmanager import get_settings_manager, \ | |
2 | SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER |
|
2 | SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER | |
3 | from boards.models.user import Notification |
|
3 | from boards.models.user import Notification | |
4 |
|
4 | |||
5 | __author__ = 'neko259' |
|
5 | __author__ = 'neko259' | |
6 |
|
6 | |||
|
7 | import neboard | |||
7 | from boards import settings |
|
8 | from boards import settings | |
8 | from boards.models import Post, Tag, Thread |
|
9 | from boards.models import Post, Tag, Thread | |
9 |
|
10 | |||
10 | CONTEXT_SITE_NAME = 'site_name' |
|
11 | CONTEXT_SITE_NAME = 'site_name' | |
11 | CONTEXT_VERSION = 'version' |
|
12 | CONTEXT_VERSION = 'version' | |
12 | CONTEXT_THEME_CSS = 'theme_css' |
|
13 | CONTEXT_THEME_CSS = 'theme_css' | |
13 | CONTEXT_THEME = 'theme' |
|
14 | CONTEXT_THEME = 'theme' | |
14 | CONTEXT_PPD = 'posts_per_day' |
|
15 | CONTEXT_PPD = 'posts_per_day' | |
15 | CONTEXT_TAGS = 'tags' |
|
16 | CONTEXT_TAGS = 'tags' | |
16 | CONTEXT_USER = 'user' |
|
17 | CONTEXT_USER = 'user' | |
17 | CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_notifications_count' |
|
18 | CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_notifications_count' | |
18 | CONTEXT_USERNAMES = 'usernames' |
|
19 | CONTEXT_USERNAMES = 'usernames' | |
19 | CONTEXT_TAGS_STR = 'tags_str' |
|
20 | CONTEXT_TAGS_STR = 'tags_str' | |
20 | CONTEXT_IMAGE_VIEWER = 'image_viewer' |
|
21 | CONTEXT_IMAGE_VIEWER = 'image_viewer' | |
21 | CONTEXT_HAS_FAV_THREADS = 'has_fav_threads' |
|
22 | CONTEXT_HAS_FAV_THREADS = 'has_fav_threads' | |
22 | CONTEXT_POW_DIFFICULTY = 'pow_difficulty' |
|
23 | CONTEXT_POW_DIFFICULTY = 'pow_difficulty' | |
23 | CONTEXT_NEW_POST_COUNT = 'new_post_count' |
|
24 | CONTEXT_NEW_POST_COUNT = 'new_post_count' | |
|
25 | CONTEXT_SEARCH_ENABLED = 'search_enabled' | |||
24 |
|
26 | |||
25 |
|
27 | |||
26 | def get_notifications(context, request): |
|
28 | def get_notifications(context, request): | |
27 | settings_manager = get_settings_manager(request) |
|
29 | settings_manager = get_settings_manager(request) | |
28 | usernames = settings_manager.get_notification_usernames() |
|
30 | usernames = settings_manager.get_notification_usernames() | |
29 | new_notifications_count = 0 |
|
31 | new_notifications_count = 0 | |
30 | if usernames is not None: |
|
32 | if usernames is not None: | |
31 | last_notification_id = settings_manager.get_setting( |
|
33 | last_notification_id = settings_manager.get_setting( | |
32 | SETTING_LAST_NOTIFICATION_ID) |
|
34 | SETTING_LAST_NOTIFICATION_ID) | |
33 |
|
35 | |||
34 | new_notifications_count = Notification.objects.get_notification_posts( |
|
36 | new_notifications_count = Notification.objects.get_notification_posts( | |
35 | usernames=usernames, last=last_notification_id).only('id').count() |
|
37 | usernames=usernames, last=last_notification_id).only('id').count() | |
36 | context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count |
|
38 | context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count | |
37 | context[CONTEXT_USERNAMES] = usernames |
|
39 | context[CONTEXT_USERNAMES] = usernames | |
38 |
|
40 | |||
39 |
|
41 | |||
40 | def get_new_post_count(context, request): |
|
42 | def get_new_post_count(context, request): | |
41 | settings_manager = get_settings_manager(request) |
|
43 | settings_manager = get_settings_manager(request) | |
42 | fav_threads = settings_manager.get_fav_threads() |
|
44 | fav_threads = settings_manager.get_fav_threads() | |
43 | fav_thread_ops = Post.objects.filter(id__in=fav_threads.keys()) \ |
|
45 | fav_thread_ops = Post.objects.filter(id__in=fav_threads.keys()) \ | |
44 | .order_by('-pub_time').only('thread_id', 'pub_time') |
|
46 | .order_by('-pub_time').only('thread_id', 'pub_time') | |
45 |
|
47 | |||
46 | ops = [{'op': op, 'last_id': fav_threads[str(op.id)]} for op in fav_thread_ops] |
|
48 | ops = [{'op': op, 'last_id': fav_threads[str(op.id)]} for op in fav_thread_ops] | |
47 | count = Thread.objects.get_new_post_count(ops) |
|
49 | count = Thread.objects.get_new_post_count(ops) | |
48 | if count > 0: |
|
50 | if count > 0: | |
49 | context[CONTEXT_NEW_POST_COUNT] = '(+{})'.format(count) |
|
51 | context[CONTEXT_NEW_POST_COUNT] = '(+{})'.format(count) | |
50 |
|
52 | |||
51 |
|
53 | |||
52 | def user_and_ui_processor(request): |
|
54 | def user_and_ui_processor(request): | |
53 | context = dict() |
|
55 | context = dict() | |
54 |
|
56 | |||
55 | context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day()) |
|
57 | context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day()) | |
56 |
|
58 | |||
57 | settings_manager = get_settings_manager(request) |
|
59 | settings_manager = get_settings_manager(request) | |
58 | fav_tags = settings_manager.get_fav_tags() |
|
60 | fav_tags = settings_manager.get_fav_tags() | |
59 | context[CONTEXT_TAGS] = fav_tags |
|
61 | context[CONTEXT_TAGS] = fav_tags | |
60 |
|
62 | |||
61 | context[CONTEXT_TAGS_STR] = Tag.objects.get_tag_url_list(fav_tags) |
|
63 | context[CONTEXT_TAGS_STR] = Tag.objects.get_tag_url_list(fav_tags) | |
62 | theme = settings_manager.get_theme() |
|
64 | theme = settings_manager.get_theme() | |
63 | context[CONTEXT_THEME] = theme |
|
65 | context[CONTEXT_THEME] = theme | |
64 | context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css' |
|
66 | context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css' | |
65 |
|
67 | |||
66 | context[CONTEXT_VERSION] = settings.get('Version', 'Version') |
|
68 | context[CONTEXT_VERSION] = settings.get('Version', 'Version') | |
67 | context[CONTEXT_SITE_NAME] = settings.get('Version', 'SiteName') |
|
69 | context[CONTEXT_SITE_NAME] = settings.get('Version', 'SiteName') | |
68 |
|
70 | |||
69 | if settings.get_bool('Forms', 'LimitPostingSpeed'): |
|
71 | if settings.get_bool('Forms', 'LimitPostingSpeed'): | |
70 | context[CONTEXT_POW_DIFFICULTY] = settings.get_int('Forms', 'PowDifficulty') |
|
72 | context[CONTEXT_POW_DIFFICULTY] = settings.get_int('Forms', 'PowDifficulty') | |
71 |
|
73 | |||
72 | context[CONTEXT_IMAGE_VIEWER] = settings_manager.get_setting( |
|
74 | context[CONTEXT_IMAGE_VIEWER] = settings_manager.get_setting( | |
73 | SETTING_IMAGE_VIEWER, |
|
75 | SETTING_IMAGE_VIEWER, | |
74 | default=settings.get('View', 'DefaultImageViewer')) |
|
76 | default=settings.get('View', 'DefaultImageViewer')) | |
75 |
|
77 | |||
76 | context[CONTEXT_HAS_FAV_THREADS] =\ |
|
78 | context[CONTEXT_HAS_FAV_THREADS] =\ | |
77 | len(settings_manager.get_fav_threads()) > 0 |
|
79 | len(settings_manager.get_fav_threads()) > 0 | |
78 |
|
80 | |||
|
81 | context[CONTEXT_SEARCH_ENABLED] = 'haystack' in neboard.settings.INSTALLED_APPS | |||
|
82 | ||||
79 | get_notifications(context, request) |
|
83 | get_notifications(context, request) | |
80 | get_new_post_count(context, request) |
|
84 | get_new_post_count(context, request) | |
81 |
|
85 | |||
82 | return context |
|
86 | return context |
@@ -1,90 +1,92 b'' | |||||
1 | {% load staticfiles %} |
|
1 | {% load staticfiles %} | |
2 | {% load i18n %} |
|
2 | {% load i18n %} | |
3 | {% load l10n %} |
|
3 | {% load l10n %} | |
4 | {% load static from staticfiles %} |
|
4 | {% load static from staticfiles %} | |
5 |
|
5 | |||
6 | <!DOCTYPE html> |
|
6 | <!DOCTYPE html> | |
7 | <html> |
|
7 | <html> | |
8 | <head> |
|
8 | <head> | |
9 | <link rel="stylesheet" type="text/css" href="{% static 'css/base.css' %}" media="all"/> |
|
9 | <link rel="stylesheet" type="text/css" href="{% static 'css/base.css' %}" media="all"/> | |
10 | <link rel="stylesheet" type="text/css" href="{% static 'css/3party/highlight.css' %}" media="all"/> |
|
10 | <link rel="stylesheet" type="text/css" href="{% static 'css/3party/highlight.css' %}" media="all"/> | |
11 | <link rel="stylesheet" type="text/css" href="{% static 'css/3party/jquery-ui.min.css' %}" media="all"/> |
|
11 | <link rel="stylesheet" type="text/css" href="{% static 'css/3party/jquery-ui.min.css' %}" media="all"/> | |
12 | <link rel="stylesheet" type="text/css" href="{% static theme_css %}" media="all"/> |
|
12 | <link rel="stylesheet" type="text/css" href="{% static theme_css %}" media="all"/> | |
13 |
|
13 | |||
14 | {% if rss_url %} |
|
14 | {% if rss_url %} | |
15 | <link rel="alternate" type="application/rss+xml" href="{{ rss_url }}" title="{% trans 'Feed' %}"/> |
|
15 | <link rel="alternate" type="application/rss+xml" href="{{ rss_url }}" title="{% trans 'Feed' %}"/> | |
16 | {% endif %} |
|
16 | {% endif %} | |
17 |
|
17 | |||
18 | <link rel="icon" type="image/png" |
|
18 | <link rel="icon" type="image/png" | |
19 | href="{% static 'favicon.png' %}"> |
|
19 | href="{% static 'favicon.png' %}"> | |
20 |
|
20 | |||
21 | <meta name="viewport" content="width=device-width, initial-scale=1"/> |
|
21 | <meta name="viewport" content="width=device-width, initial-scale=1"/> | |
22 | <meta charset="utf-8"/> |
|
22 | <meta charset="utf-8"/> | |
23 |
|
23 | |||
24 | {% block head %}{% endblock %} |
|
24 | {% block head %}{% endblock %} | |
25 | </head> |
|
25 | </head> | |
26 | <body data-image-viewer="{{ image_viewer }}" |
|
26 | <body data-image-viewer="{{ image_viewer }}" | |
27 | data-pow-difficulty="{{ pow_difficulty }}" |
|
27 | data-pow-difficulty="{{ pow_difficulty }}" | |
28 | data-update-script="{% static 'js/updates.js' %}"> |
|
28 | data-update-script="{% static 'js/updates.js' %}"> | |
29 | <script src="{% static 'js/jquery-2.2.0.min.js' %}"></script> |
|
29 | <script src="{% static 'js/jquery-2.2.0.min.js' %}"></script> | |
30 |
|
30 | |||
31 | <div class="navigation_panel header"> |
|
31 | <div class="navigation_panel header"> | |
32 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> |
|
32 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> | |
33 | {% if tags_str %} |
|
33 | {% if tags_str %} | |
34 | <a href="{% url 'index' %}?filter=fav_tags">{% trans "interesting" %}</a>, |
|
34 | <a href="{% url 'index' %}?filter=fav_tags">{% trans "interesting" %}</a>, | |
35 | {% autoescape off %} |
|
35 | {% autoescape off %} | |
36 | {{ tags_str }}, |
|
36 | {{ tags_str }}, | |
37 | {% endautoescape %} |
|
37 | {% endautoescape %} | |
38 | {% else %} |
|
38 | {% else %} | |
39 | {% trans 'Add tags' %} β |
|
39 | {% trans 'Add tags' %} β | |
40 | {% endif %} |
|
40 | {% endif %} | |
41 | <a href="{% url 'tags' 'required'%}" title="{% trans 'Tag management' %}">{% trans "tags" %}</a>, |
|
41 | <a href="{% url 'tags' 'required'%}" title="{% trans 'Tag management' %}">{% trans "tags" %}</a>, | |
42 | <a href="{% url 'search' %}" title="{% trans 'Search' %}">{% trans 'search' %}</a>, |
|
42 | {% if search_enabled %} | |
|
43 | <a href="{% url 'search' %}" title="{% trans 'Search' %}">{% trans 'search' %}</a>, | |||
|
44 | {% endif %} | |||
43 | <a href="{% url 'feed' %}" title="{% trans 'Feed' %}">{% trans 'feed' %}</a>, |
|
45 | <a href="{% url 'feed' %}" title="{% trans 'Feed' %}">{% trans 'feed' %}</a>, | |
44 | <a href="{% url 'random' %}" title="{% trans 'Random images' %}">{% trans 'random' %}</a>{% if has_fav_threads %}, |
|
46 | <a href="{% url 'random' %}" title="{% trans 'Random images' %}">{% trans 'random' %}</a>{% if has_fav_threads %}, | |
45 |
|
47 | |||
46 | <a href="{% url 'feed' %}?favorites" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count" {% if not new_post_count %}style="display: none" {% endif %}>{{ new_post_count }}</span></a> |
|
48 | <a href="{% url 'feed' %}?favorites" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count" {% if not new_post_count %}style="display: none" {% endif %}>{{ new_post_count }}</span></a> | |
47 | {% endif %} |
|
49 | {% endif %} | |
48 |
|
50 | |||
49 | {% if usernames %} |
|
51 | {% if usernames %} | |
50 | <a class="right-link link" href="{% url 'notifications' %}" title="{% trans 'Notifications' %}"> |
|
52 | <a class="right-link link" href="{% url 'notifications' %}" title="{% trans 'Notifications' %}"> | |
51 | {% trans 'Notifications' %} |
|
53 | {% trans 'Notifications' %} | |
52 | {% ifnotequal new_notifications_count 0 %} |
|
54 | {% ifnotequal new_notifications_count 0 %} | |
53 | (<b>{{ new_notifications_count }}</b>) |
|
55 | (<b>{{ new_notifications_count }}</b>) | |
54 | {% endifnotequal %} |
|
56 | {% endifnotequal %} | |
55 | </a> |
|
57 | </a> | |
56 | {% endif %} |
|
58 | {% endif %} | |
57 |
|
59 | |||
58 | <a class="right-link link" href="{% url 'settings' %}">{% trans 'Settings' %}</a> |
|
60 | <a class="right-link link" href="{% url 'settings' %}">{% trans 'Settings' %}</a> | |
59 | </div> |
|
61 | </div> | |
60 |
|
62 | |||
61 | <div id="fav-panel"><div class="post">{% trans "Loading..." %}</div></div> |
|
63 | <div id="fav-panel"><div class="post">{% trans "Loading..." %}</div></div> | |
62 |
|
64 | |||
63 | {% block content %}{% endblock %} |
|
65 | {% block content %}{% endblock %} | |
64 |
|
66 | |||
65 | <script src="{% static 'js/3party/jquery-ui.min.js' %}"></script> |
|
67 | <script src="{% static 'js/3party/jquery-ui.min.js' %}"></script> | |
66 | <script src="{% static 'js/jquery.mousewheel.js' %}"></script> |
|
68 | <script src="{% static 'js/jquery.mousewheel.js' %}"></script> | |
67 | <script src="{% static 'js/3party/highlight.min.js' %}"></script> |
|
69 | <script src="{% static 'js/3party/highlight.min.js' %}"></script> | |
68 |
|
70 | |||
69 | <script src="{% url 'js_info_dict' %}"></script> |
|
71 | <script src="{% url 'js_info_dict' %}"></script> | |
70 |
|
72 | |||
71 | <script src="{% static 'js/popup.js' %}"></script> |
|
73 | <script src="{% static 'js/popup.js' %}"></script> | |
72 | <script src="{% static 'js/image.js' %}"></script> |
|
74 | <script src="{% static 'js/image.js' %}"></script> | |
73 | <script src="{% static 'js/refpopup.js' %}"></script> |
|
75 | <script src="{% static 'js/refpopup.js' %}"></script> | |
74 | <script src="{% static 'js/main.js' %}"></script> |
|
76 | <script src="{% static 'js/main.js' %}"></script> | |
75 |
|
77 | |||
76 | <div class="navigation_panel footer"> |
|
78 | <div class="navigation_panel footer"> | |
77 | {% block metapanel %}{% endblock %} |
|
79 | {% block metapanel %}{% endblock %} | |
78 | {% if rss_url %} |
|
80 | {% if rss_url %} | |
79 | [<a href="{{ rss_url }}">RSS</a>] |
|
81 | [<a href="{{ rss_url }}">RSS</a>] | |
80 | {% endif %} |
|
82 | {% endif %} | |
81 | [<a href="{% url 'admin:index' %}">{% trans 'Admin' %}</a>] |
|
83 | [<a href="{% url 'admin:index' %}">{% trans 'Admin' %}</a>] | |
82 | [<a href="{% url 'index' %}?order=pub">{% trans 'New threads' %}</a>] |
|
84 | [<a href="{% url 'index' %}?order=pub">{% trans 'New threads' %}</a>] | |
83 | {% with ppd=posts_per_day|floatformat:2 %} |
|
85 | {% with ppd=posts_per_day|floatformat:2 %} | |
84 | {% blocktrans %}Speed: {{ ppd }} posts per day{% endblocktrans %} |
|
86 | {% blocktrans %}Speed: {{ ppd }} posts per day{% endblocktrans %} | |
85 | {% endwith %} |
|
87 | {% endwith %} | |
86 | <a class="link" href="#top" id="up">{% trans 'Up' %}</a> |
|
88 | <a class="link" href="#top" id="up">{% trans 'Up' %}</a> | |
87 | </div> |
|
89 | </div> | |
88 |
|
90 | |||
89 | </body> |
|
91 | </body> | |
90 | </html> |
|
92 | </html> |
General Comments 0
You need to be logged in to leave comments.
Login now