##// END OF EJS Templates
Added attachment alias categories
neko259 -
r1701:99ec870f default
parent child Browse files
Show More
@@ -0,0 +1,17 b''
1 {% extends "boards/base.html" %}
2
3 {% load i18n %}
4 {% load tz %}
5
6 {% block head %}
7 <meta name="robots" content="noindex">
8 <title>{% trans 'Aliases' %} - {{ site_name }}</title>
9 {% endblock %}
10
11 {% block content %}
12 <div class="post">
13 {% for image in image_aliases %}
14 <div>{{ image.alias }}: {{ image.get_view|safe }}</div>
15 {% endfor %}
16 </div>
17 {% endblock %}
@@ -0,0 +1,32 b''
1 from django.db import transaction
2 from django.shortcuts import render, redirect
3 from django.utils import timezone
4 from django.utils.decorators import method_decorator
5 from django.views.decorators.csrf import csrf_protect
6
7 from boards.abstracts.settingsmanager import get_settings_manager, \
8 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER
9 from boards.middlewares import SESSION_TIMEZONE
10 from boards.views.base import BaseBoardView, CONTEXT_FORM
11 from boards.forms import SettingsForm, PlainErrorList
12 from boards import settings
13 from boards.models import Attachment
14
15 CONTEXT_IMAGE_ALIASES = 'image_aliases'
16
17 TEMPLATE = 'boards/aliases.html'
18
19
20 class AliasesView(BaseBoardView):
21 @method_decorator(csrf_protect)
22 def get(self, request, category):
23 params = dict()
24 settings_manager = get_settings_manager(request)
25
26 selected_theme = settings_manager.get_theme()
27
28 params[CONTEXT_IMAGE_ALIASES] = Attachment.objects.exclude(alias='')\
29 .exclude(alias=None).filter(alias__startswith=(category + '/'))
30
31 return render(request, TEMPLATE, params)
32
@@ -1,44 +1,40 b''
1 1 {% extends "boards/base.html" %}
2 2
3 3 {% load i18n %}
4 4 {% load tz %}
5 5
6 6 {% block head %}
7 7 <meta name="robots" content="noindex">
8 8 <title>{% trans 'Settings' %} - {{ site_name }}</title>
9 9 {% endblock %}
10 10
11 11 {% block content %}
12 12 <div class="post">
13 13 <p>
14 14 {% if moderator %}
15 15 {% trans 'You are moderator.' %}
16 16 {% endif %}
17 17 </p>
18 18 {% if hidden_tags %}
19 19 <p>{% trans 'Hidden tags:' %}
20 20 {% for tag in hidden_tags %}
21 21 {{ tag.get_view|safe }}
22 22 {% endfor %}
23 23 </p>
24 24 {% else %}
25 25 <p>{% trans 'No hidden tags.' %}</p>
26 26 {% endif %}
27
28 {% for image in image_aliases %}
29 <div>{{ image.alias }}: {{ image.get_view|safe }}</div>
30 {% endfor %}
31 27 </div>
32 28
33 29 <div class="post-form-w">
34 30 <div class="post-form">
35 31 <form method="post">{% csrf_token %}
36 32 {{ form.as_div }}
37 33 <div class="form-submit">
38 34 <input type="submit" value="{% trans "Save" %}" />
39 35 </div>
40 36 </form>
41 37 </div>
42 38 </div>
43 39
44 40 {% endblock %}
@@ -1,96 +1,97 b''
1 1 from django.conf.urls import url
2 2
3 3 import neboard
4 4
5 5 from boards import views
6 6 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
7 7 from boards.views import api, tag_threads, all_threads, \
8 settings, all_tags, feed
8 settings, all_tags, feed, alias
9 9 from boards.views.authors import AuthorsView
10 10 from boards.views.notifications import NotificationView
11 11 from boards.views.static import StaticPageView
12 12 from boards.views.preview import PostPreviewView
13 13 from boards.views.sync import get_post_sync_data, response_get, response_list
14 14 from boards.views.random import RandomImageView
15 15 from boards.views.tag_gallery import TagGalleryView
16 16 from boards.views.translation import cached_javascript_catalog
17 17
18 18
19 19 js_info_dict = {
20 20 'packages': ('boards',),
21 21 }
22 22
23 23 urlpatterns = [
24 24 # /boards/
25 25 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
26 26
27 27 # /boards/tag/tag_name/
28 28 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
29 29 name='tag'),
30 30
31 31 # /boards/thread/
32 32 url(r'^thread/(?P<post_id>\d+)/$', views.thread.NormalThreadView.as_view(),
33 33 name='thread'),
34 34 url(r'^thread/(?P<post_id>\d+)/mode/gallery/$', views.thread.GalleryThreadView.as_view(),
35 35 name='thread_gallery'),
36 36 url(r'^thread/(?P<post_id>\d+)/mode/tree/$', views.thread.TreeThreadView.as_view(),
37 37 name='thread_tree'),
38 38 # /feed/
39 39 url(r'^feed/$', views.feed.FeedView.as_view(), name='feed'),
40 40
41 41 url(r'^settings/$', settings.SettingsView.as_view(), name='settings'),
42 url(r'^aliases/(?P<category>\w+)/$', alias.AliasesView.as_view(), name='aliases'),
42 43 url(r'^tags/(?P<query>\w+)?/?$', all_tags.AllTagsView.as_view(), name='tags'),
43 44 url(r'^authors/$', AuthorsView.as_view(), name='authors'),
44 45
45 46 url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'),
46 47 url(r'^staticpage/(?P<name>\w+)/$', StaticPageView.as_view(),
47 48 name='staticpage'),
48 49
49 50 url(r'^random/$', RandomImageView.as_view(), name='random'),
50 51 url(r'^tag/(?P<tag_name>\w+)/gallery/$', TagGalleryView.as_view(), name='tag_gallery'),
51 52
52 53 # RSS feeds
53 54 url(r'^rss/$', AllThreadsFeed()),
54 55 url(r'^page/(?P<page>\d+)/rss/$', AllThreadsFeed()),
55 56 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
56 57 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
57 58 url(r'^thread/(?P<post_id>\d+)/rss/$', ThreadPostsFeed()),
58 59
59 60 # i18n
60 61 url(r'^jsi18n/$', cached_javascript_catalog, js_info_dict,
61 62 name='js_info_dict'),
62 63
63 64 # API
64 65 url(r'^api/post/(?P<post_id>\d+)/$', api.get_post, name="get_post"),
65 66 url(r'^api/diff_thread/$', api.api_get_threaddiff, name="get_thread_diff"),
66 67 url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads,
67 68 name='get_threads'),
68 69 url(r'^api/tags/$', api.api_get_tags, name='get_tags'),
69 70 url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts,
70 71 name='get_thread'),
71 72 url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post,
72 73 name='add_post'),
73 74 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
74 75 name='api_notifications'),
75 76 url(r'^api/preview/$', api.api_get_preview, name='preview'),
76 77 url(r'^api/new_posts/$', api.api_get_new_posts, name='new_posts'),
77 78
78 79 # Sync protocol API
79 80 url(r'^api/sync/list/$', response_list, name='api_sync_list'),
80 81 url(r'^api/sync/get/$', response_get, name='api_sync_get'),
81 82
82 83 # Notifications
83 84 url(r'^notifications/(?P<username>\w+)/$', NotificationView.as_view(), name='notifications'),
84 85 url(r'^notifications/$', NotificationView.as_view(), name='notifications'),
85 86
86 87 # Post preview
87 88 url(r'^preview/$', PostPreviewView.as_view(), name='preview'),
88 89 url(r'^post_xml/(?P<post_id>\d+)$', get_post_sync_data,
89 90 name='post_sync_data'),
90 91 ]
91 92
92 93 # Search
93 94 if 'haystack' in neboard.settings.INSTALLED_APPS:
94 95 from boards.views.search import BoardSearchView
95 96 urlpatterns.append(url(r'^search/$', BoardSearchView.as_view(), name='search'))
96 97
@@ -1,82 +1,80 b''
1 1 from django.db import transaction
2 2 from django.shortcuts import render, redirect
3 3 from django.utils import timezone
4 4 from django.utils.decorators import method_decorator
5 5 from django.views.decorators.csrf import csrf_protect
6 6
7 7 from boards.abstracts.settingsmanager import get_settings_manager, \
8 8 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER
9 9 from boards.middlewares import SESSION_TIMEZONE
10 10 from boards.views.base import BaseBoardView, CONTEXT_FORM
11 11 from boards.forms import SettingsForm, PlainErrorList
12 12 from boards import settings
13 13 from boards.models import Attachment
14 14
15 15 FORM_THEME = 'theme'
16 16 FORM_USERNAME = 'username'
17 17 FORM_TIMEZONE = 'timezone'
18 18 FORM_IMAGE_VIEWER = 'image_viewer'
19 19
20 20 CONTEXT_HIDDEN_TAGS = 'hidden_tags'
21 CONTEXT_IMAGE_ALIASES = 'image_aliases'
22 21
23 22 TEMPLATE = 'boards/settings.html'
24 23
25 24
26 25 class SettingsView(BaseBoardView):
27 26 @method_decorator(csrf_protect)
28 27 def get(self, request):
29 28 params = dict()
30 29 settings_manager = get_settings_manager(request)
31 30
32 31 selected_theme = settings_manager.get_theme()
33 32
34 33 form = SettingsForm(
35 34 initial={
36 35 FORM_THEME: selected_theme,
37 36 FORM_IMAGE_VIEWER: settings_manager.get_setting(
38 37 SETTING_IMAGE_VIEWER,
39 38 default=settings.get('View', 'DefaultImageViewer')),
40 39 FORM_USERNAME: settings_manager.get_setting(SETTING_USERNAME),
41 40 FORM_TIMEZONE: request.session.get(
42 41 SESSION_TIMEZONE, timezone.get_current_timezone()),
43 42 },
44 43 error_class=PlainErrorList)
45 44
46 45 params[CONTEXT_FORM] = form
47 46 params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
48 params[CONTEXT_IMAGE_ALIASES] = Attachment.objects.exclude(alias='').exclude(alias=None)
49 47
50 48 return render(request, TEMPLATE, params)
51 49
52 50 @method_decorator(csrf_protect)
53 51 def post(self, request):
54 52 settings_manager = get_settings_manager(request)
55 53
56 54 with transaction.atomic():
57 55 form = SettingsForm(request.POST, error_class=PlainErrorList)
58 56
59 57 if form.is_valid():
60 58 selected_theme = form.cleaned_data[FORM_THEME]
61 59 username = form.cleaned_data[FORM_USERNAME].lower()
62 60
63 61 settings_manager.set_theme(selected_theme)
64 62 settings_manager.set_setting(SETTING_IMAGE_VIEWER,
65 63 form.cleaned_data[FORM_IMAGE_VIEWER])
66 64
67 65 old_username = settings_manager.get_setting(SETTING_USERNAME)
68 66 if username != old_username:
69 67 settings_manager.set_setting(SETTING_USERNAME, username)
70 68 settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, None)
71 69
72 70 request.session[SESSION_TIMEZONE] = form.cleaned_data[FORM_TIMEZONE]
73 71
74 72 return redirect('settings')
75 73 else:
76 74 params = dict()
77 75
78 76 params[CONTEXT_FORM] = form
79 77 params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
80 78
81 79 return render(request, TEMPLATE, params)
82 80
General Comments 0
You need to be logged in to leave comments. Login now