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