Show More
@@ -1,63 +1,62 b'' | |||
|
1 | 1 | {% load staticfiles %} |
|
2 | 2 | {% load i18n %} |
|
3 | 3 | {% load l10n %} |
|
4 | 4 | {% load static from staticfiles %} |
|
5 | 5 | |
|
6 | 6 | <!DOCTYPE html> |
|
7 | 7 | <html> |
|
8 | 8 | <head> |
|
9 | 9 | <link rel="stylesheet" type="text/css" |
|
10 | 10 | href="{% static 'css/base.css' %}" media="all"/> |
|
11 | 11 | <link rel="stylesheet" type="text/css" |
|
12 | 12 | href="{% static theme_css %}" media="all"/> |
|
13 | 13 | <link rel="alternate" type="application/rss+xml" href="rss/" title= |
|
14 | 14 | "{% trans 'Feed' %}"/> |
|
15 | 15 | |
|
16 | 16 | <link rel="icon" type="image/png" |
|
17 | 17 | href="{% static 'favicon.png' %}"> |
|
18 | 18 | |
|
19 | 19 | <meta name="viewport" content="width=device-width, initial-scale=1"/> |
|
20 | 20 | <meta charset="utf-8"/> |
|
21 | 21 | |
|
22 | 22 | {% block head %}{% endblock %} |
|
23 | 23 | </head> |
|
24 | 24 | <body> |
|
25 | 25 | <script src="{% static 'js/jquery-2.0.1.min.js' %}"></script> |
|
26 | 26 | <script src="{% static 'js/jquery-ui-1.10.3.custom.min.js' %}"></script> |
|
27 | 27 | <script src="{% static 'js/jquery.mousewheel.js' %}"></script> |
|
28 | 28 | <script src="{% url 'js_info_dict' %}"></script> |
|
29 | 29 | |
|
30 | 30 | <div class="navigation_panel"> |
|
31 | 31 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> |
|
32 | 32 | {% for tag in tags %} |
|
33 | 33 | <a class="tag" href="{% url 'tag' tag_name=tag.name %}" |
|
34 | 34 | >#{{ tag.name }}</a>, |
|
35 | 35 | {% endfor %} |
|
36 | 36 | <a href="{% url 'tags' %}" title="{% trans 'Tag management' %}" |
|
37 | 37 | >[...]</a> |
|
38 | 38 | <a class="link" href="{% url 'settings' %}">{% trans 'Settings' %}</a> |
|
39 | 39 | </div> |
|
40 | 40 | |
|
41 | 41 | {% block content %}{% endblock %} |
|
42 | 42 | |
|
43 | 43 | <script src="{% static 'js/popup.js' %}"></script> |
|
44 | 44 | <script src="{% static 'js/image.js' %}"></script> |
|
45 | 45 | <script src="{% static 'js/refpopup.js' %}"></script> |
|
46 | 46 | <script src="{% static 'js/main.js' %}"></script> |
|
47 | 47 | |
|
48 | 48 | <div class="navigation_panel"> |
|
49 | 49 | {% block metapanel %}{% endblock %} |
|
50 | 50 | [<a href="{% url "login" %}">{% trans 'Login' %}</a>] |
|
51 | [<a href="{% url "archive" %}">{% trans 'Archive' %}</a>] | |
|
52 | 51 | {% with ppd=posts_per_day|floatformat:2 %} |
|
53 | 52 | {% blocktrans %}Speed: {{ ppd }} posts per day{% endblocktrans %} |
|
54 | 53 | {% endwith %} |
|
55 | 54 | <a class="link" href="#top">{% trans 'Up' %}</a> |
|
56 | 55 | </div> |
|
57 | 56 | |
|
58 | 57 | <div class="footer"> |
|
59 | 58 | <!-- Put your banners here --> |
|
60 | 59 | </div> |
|
61 | 60 | |
|
62 | 61 | </body> |
|
63 | 62 | </html> |
@@ -1,85 +1,81 b'' | |||
|
1 | 1 | from django.conf.urls import patterns, url, include |
|
2 | 2 | from boards import views |
|
3 | 3 | from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed |
|
4 |
from boards.views import api, tag_threads, all_threads, |
|
|
4 | from boards.views import api, tag_threads, all_threads, \ | |
|
5 | 5 | login, settings, all_tags |
|
6 | 6 | from boards.views.authors import AuthorsView |
|
7 | 7 | from boards.views.delete_post import DeletePostView |
|
8 | 8 | from boards.views.ban import BanUserView |
|
9 | 9 | from boards.views.static import StaticPageView |
|
10 | 10 | from boards.views.post_admin import PostAdminView |
|
11 | 11 | |
|
12 | 12 | js_info_dict = { |
|
13 | 13 | 'packages': ('boards',), |
|
14 | 14 | } |
|
15 | 15 | |
|
16 | 16 | urlpatterns = patterns('', |
|
17 | 17 | |
|
18 | 18 | # /boards/ |
|
19 | 19 | url(r'^$', all_threads.AllThreadsView.as_view(), name='index'), |
|
20 | 20 | # /boards/page/ |
|
21 | 21 | url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(), |
|
22 | 22 | name='index'), |
|
23 | 23 | |
|
24 | url(r'^archive/$', archived_threads.ArchiveView.as_view(), name='archive'), | |
|
25 | url(r'^archive/page/(?P<page>\w+)/$', | |
|
26 | archived_threads.ArchiveView.as_view(), name='archive'), | |
|
27 | ||
|
28 | 24 | # login page |
|
29 | 25 | url(r'^login/$', login.LoginView.as_view(), name='login'), |
|
30 | 26 | |
|
31 | 27 | # /boards/tag/tag_name/ |
|
32 | 28 | url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(), |
|
33 | 29 | name='tag'), |
|
34 | 30 | # /boards/tag/tag_id/page/ |
|
35 | 31 | url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$', |
|
36 | 32 | tag_threads.TagView.as_view(), name='tag'), |
|
37 | 33 | |
|
38 | 34 | # /boards/thread/ |
|
39 | 35 | url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(), |
|
40 | 36 | name='thread'), |
|
41 | 37 | url(r'^thread/(?P<post_id>\w+)/mode/(?P<mode>\w+)/$', views.thread.ThreadView |
|
42 | 38 | .as_view(), name='thread_mode'), |
|
43 | 39 | |
|
44 | 40 | # /boards/post_admin/ |
|
45 | 41 | url(r'^post_admin/(?P<post_id>\w+)/$', PostAdminView.as_view(), |
|
46 | 42 | name='post_admin'), |
|
47 | 43 | |
|
48 | 44 | url(r'^settings/$', settings.SettingsView.as_view(), name='settings'), |
|
49 | 45 | url(r'^tags/$', all_tags.AllTagsView.as_view(), name='tags'), |
|
50 | 46 | url(r'^captcha/', include('captcha.urls')), |
|
51 | 47 | url(r'^authors/$', AuthorsView.as_view(), name='authors'), |
|
52 | 48 | url(r'^delete/(?P<post_id>\w+)/$', DeletePostView.as_view(), |
|
53 | 49 | name='delete'), |
|
54 | 50 | url(r'^ban/(?P<post_id>\w+)/$', BanUserView.as_view(), name='ban'), |
|
55 | 51 | |
|
56 | 52 | url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'), |
|
57 | 53 | url(r'^staticpage/(?P<name>\w+)/$', StaticPageView.as_view(), |
|
58 | 54 | name='staticpage'), |
|
59 | 55 | |
|
60 | 56 | # RSS feeds |
|
61 | 57 | url(r'^rss/$', AllThreadsFeed()), |
|
62 | 58 | url(r'^page/(?P<page>\w+)/rss/$', AllThreadsFeed()), |
|
63 | 59 | url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()), |
|
64 | 60 | url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()), |
|
65 | 61 | url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()), |
|
66 | 62 | |
|
67 | 63 | # i18n |
|
68 | 64 | url(r'^jsi18n/$', 'boards.views.cached_js_catalog', js_info_dict, |
|
69 | 65 | name='js_info_dict'), |
|
70 | 66 | |
|
71 | 67 | # API |
|
72 | 68 | url(r'^api/post/(?P<post_id>\w+)/$', api.get_post, name="get_post"), |
|
73 | 69 | url(r'^api/diff_thread/(?P<thread_id>\w+)/(?P<last_update_time>\w+)/$', |
|
74 | 70 | api.api_get_threaddiff, name="get_thread_diff"), |
|
75 | 71 | url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads, |
|
76 | 72 | name='get_threads'), |
|
77 | 73 | url(r'^api/tags/$', api.api_get_tags, name='get_tags'), |
|
78 | 74 | url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts, |
|
79 | 75 | name='get_thread'), |
|
80 | 76 | url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post, |
|
81 | 77 | name='add_post'), |
|
82 | 78 | url(r'api/get_tag_popularity/(?P<tag_name>\w+)$', api.get_tag_popularity, |
|
83 | 79 | name='get_tag_popularity'), |
|
84 | 80 | |
|
85 | 81 | ) |
@@ -1,134 +1,134 b'' | |||
|
1 | 1 | import string |
|
2 | 2 | |
|
3 | 3 | from django.core.urlresolvers import reverse |
|
4 | 4 | from django.db import transaction |
|
5 | 5 | from django.shortcuts import render, redirect |
|
6 | 6 | |
|
7 | 7 | from boards import utils |
|
8 | 8 | from boards.abstracts.paginator import get_paginator |
|
9 | 9 | from boards.forms import ThreadForm, PlainErrorList |
|
10 | 10 | from boards.models import Post, Thread, Ban, Tag |
|
11 | 11 | from boards.views.banned import BannedView |
|
12 | 12 | from boards.views.base import BaseBoardView, PARAMETER_FORM |
|
13 | 13 | from boards.views.posting_mixin import PostMixin |
|
14 | 14 | import neboard |
|
15 | 15 | |
|
16 | 16 | TAG_DELIMITER = ' ' |
|
17 | 17 | |
|
18 | 18 | PARAMETER_CURRENT_PAGE = 'current_page' |
|
19 | 19 | PARAMETER_PAGINATOR = 'paginator' |
|
20 | 20 | PARAMETER_THREADS = 'threads' |
|
21 | 21 | |
|
22 | 22 | TEMPLATE = 'boards/posting_general.html' |
|
23 | 23 | DEFAULT_PAGE = 1 |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | class AllThreadsView(PostMixin, BaseBoardView): |
|
27 | 27 | |
|
28 | 28 | user = None |
|
29 | 29 | |
|
30 | 30 | def get(self, request, page=DEFAULT_PAGE, form=None): |
|
31 | 31 | context = self.get_context_data(request=request) |
|
32 | 32 | |
|
33 | 33 | self.user = context['user'] |
|
34 | 34 | |
|
35 | 35 | if not form: |
|
36 | 36 | form = ThreadForm(error_class=PlainErrorList) |
|
37 | 37 | |
|
38 | 38 | paginator = get_paginator(self.get_threads(), |
|
39 | 39 | neboard.settings.THREADS_PER_PAGE) |
|
40 | 40 | paginator.current_page = int(page) |
|
41 | 41 | |
|
42 | 42 | threads = paginator.page(page).object_list |
|
43 | 43 | |
|
44 | 44 | context[PARAMETER_THREADS] = threads |
|
45 | 45 | context[PARAMETER_FORM] = form |
|
46 | 46 | |
|
47 | 47 | self._get_page_context(paginator, context, page) |
|
48 | 48 | |
|
49 | 49 | return render(request, TEMPLATE, context) |
|
50 | 50 | |
|
51 | 51 | def post(self, request, page=DEFAULT_PAGE): |
|
52 | 52 | form = ThreadForm(request.POST, request.FILES, |
|
53 | 53 | error_class=PlainErrorList) |
|
54 | 54 | form.session = request.session |
|
55 | 55 | |
|
56 | 56 | if form.is_valid(): |
|
57 | 57 | return self.create_thread(request, form) |
|
58 | 58 | if form.need_to_ban: |
|
59 | 59 | # Ban user because he is suspected to be a bot |
|
60 | 60 | self._ban_current_user(request) |
|
61 | 61 | |
|
62 | 62 | return self.get(request, page, form) |
|
63 | 63 | |
|
64 | 64 | @staticmethod |
|
65 | 65 | def _get_page_context(paginator, context, page): |
|
66 | 66 | """ |
|
67 | 67 | Get pagination context variables |
|
68 | 68 | """ |
|
69 | 69 | |
|
70 | 70 | context[PARAMETER_PAGINATOR] = paginator |
|
71 | 71 | context[PARAMETER_CURRENT_PAGE] = paginator.page(int(page)) |
|
72 | 72 | |
|
73 | 73 | def parse_tags_string(self, tag_strings): |
|
74 | 74 | """ |
|
75 | 75 | Parses tag list string and returns tag object list. |
|
76 | 76 | """ |
|
77 | 77 | |
|
78 | 78 | tags = [] |
|
79 | 79 | |
|
80 | 80 | if tag_strings: |
|
81 | 81 | tag_strings = tag_strings.split(TAG_DELIMITER) |
|
82 | 82 | for tag_name in tag_strings: |
|
83 | 83 | tag_name = string.lower(tag_name.strip()) |
|
84 | 84 | if len(tag_name) > 0: |
|
85 | 85 | tag, created = Tag.objects.get_or_create(name=tag_name) |
|
86 | 86 | tags.append(tag) |
|
87 | 87 | |
|
88 | 88 | return tags |
|
89 | 89 | |
|
90 | 90 | @transaction.atomic |
|
91 | 91 | def create_thread(self, request, form, html_response=True): |
|
92 | 92 | """ |
|
93 | 93 | Creates a new thread with an opening post. |
|
94 | 94 | """ |
|
95 | 95 | |
|
96 | 96 | ip = utils.get_client_ip(request) |
|
97 | 97 | is_banned = Ban.objects.filter(ip=ip).exists() |
|
98 | 98 | |
|
99 | 99 | if is_banned: |
|
100 | 100 | if html_response: |
|
101 | 101 | return redirect(BannedView().as_view()) |
|
102 | 102 | else: |
|
103 | 103 | return |
|
104 | 104 | |
|
105 | 105 | data = form.cleaned_data |
|
106 | 106 | |
|
107 | 107 | title = data['title'] |
|
108 | 108 | text = data['text'] |
|
109 | 109 | |
|
110 | 110 | text = self._remove_invalid_links(text) |
|
111 | 111 | |
|
112 | 112 | if 'image' in data.keys(): |
|
113 | 113 | image = data['image'] |
|
114 | 114 | else: |
|
115 | 115 | image = None |
|
116 | 116 | |
|
117 | 117 | tag_strings = data['tags'] |
|
118 | 118 | |
|
119 | 119 | tags = self.parse_tags_string(tag_strings) |
|
120 | 120 | |
|
121 | 121 | post = Post.objects.create_post(title=title, text=text, ip=ip, |
|
122 | 122 | image=image, tags=tags, |
|
123 | 123 | user=self._get_user(request)) |
|
124 | 124 | |
|
125 | 125 | if html_response: |
|
126 | 126 | return redirect(post.get_url()) |
|
127 | 127 | |
|
128 | 128 | def get_threads(self): |
|
129 | 129 | """ |
|
130 | 130 | Gets list of threads that will be shown on a page. |
|
131 | 131 | """ |
|
132 | 132 | |
|
133 |
return Thread.objects. |
|
|
134 | .exclude(tags__in=self.user.hidden_tags.all()) No newline at end of file | |
|
133 | return Thread.objects.all().order_by('-bump_time')\ | |
|
134 | .exclude(tags__in=self.user.hidden_tags.all()) |
@@ -1,86 +1,86 b'' | |||
|
1 | 1 | from django.shortcuts import get_object_or_404 |
|
2 | 2 | from boards.models import Tag, Post |
|
3 | 3 | from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE |
|
4 | 4 | from boards.views.mixins import DispatcherMixin, RedirectNextMixin |
|
5 | 5 | from boards.forms import ThreadForm, PlainErrorList |
|
6 | 6 | |
|
7 | 7 | __author__ = 'neko259' |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | class TagView(AllThreadsView, DispatcherMixin, RedirectNextMixin): |
|
11 | 11 | |
|
12 | 12 | tag_name = None |
|
13 | 13 | |
|
14 | 14 | def get_threads(self): |
|
15 | 15 | tag = get_object_or_404(Tag, name=self.tag_name) |
|
16 | 16 | |
|
17 |
return tag.threads. |
|
|
17 | return tag.threads.all().order_by('-bump_time') | |
|
18 | 18 | |
|
19 | 19 | def get_context_data(self, **kwargs): |
|
20 | 20 | context = super(TagView, self).get_context_data(**kwargs) |
|
21 | 21 | |
|
22 | 22 | tag = get_object_or_404(Tag, name=self.tag_name) |
|
23 | 23 | context['tag'] = tag |
|
24 | 24 | |
|
25 | 25 | return context |
|
26 | 26 | |
|
27 | 27 | def get(self, request, tag_name, page=DEFAULT_PAGE, form=None): |
|
28 | 28 | self.tag_name = tag_name |
|
29 | 29 | |
|
30 | 30 | dispatch_result = self.dispatch_method(request) |
|
31 | 31 | if dispatch_result: |
|
32 | 32 | return dispatch_result |
|
33 | 33 | else: |
|
34 | 34 | return super(TagView, self).get(request, page, form) |
|
35 | 35 | |
|
36 | 36 | def post(self, request, tag_name, page=DEFAULT_PAGE): |
|
37 | 37 | form = ThreadForm(request.POST, request.FILES, |
|
38 | 38 | error_class=PlainErrorList) |
|
39 | 39 | form.session = request.session |
|
40 | 40 | |
|
41 | 41 | if form.is_valid(): |
|
42 | 42 | return self.create_thread(request, form) |
|
43 | 43 | if form.need_to_ban: |
|
44 | 44 | # Ban user because he is suspected to be a bot |
|
45 | 45 | self._ban_current_user(request) |
|
46 | 46 | |
|
47 | 47 | return self.get(request, tag_name, page, form) |
|
48 | 48 | |
|
49 | 49 | def subscribe(self, request): |
|
50 | 50 | user = self._get_user(request) |
|
51 | 51 | tag = get_object_or_404(Tag, name=self.tag_name) |
|
52 | 52 | |
|
53 | 53 | if not tag in user.fav_tags.all(): |
|
54 | 54 | user.add_tag(tag) |
|
55 | 55 | |
|
56 | 56 | return self.redirect_to_next(request) |
|
57 | 57 | |
|
58 | 58 | def unsubscribe(self, request): |
|
59 | 59 | user = self._get_user(request) |
|
60 | 60 | tag = get_object_or_404(Tag, name=self.tag_name) |
|
61 | 61 | |
|
62 | 62 | if tag in user.fav_tags.all(): |
|
63 | 63 | user.remove_tag(tag) |
|
64 | 64 | |
|
65 | 65 | return self.redirect_to_next(request) |
|
66 | 66 | |
|
67 | 67 | def hide(self, request): |
|
68 | 68 | """ |
|
69 | 69 | Adds tag to user's hidden tags. Threads with this tag will not be |
|
70 | 70 | shown. |
|
71 | 71 | """ |
|
72 | 72 | |
|
73 | 73 | user = self._get_user(request) |
|
74 | 74 | tag = get_object_or_404(Tag, name=self.tag_name) |
|
75 | 75 | |
|
76 | 76 | user.hide_tag(tag) |
|
77 | 77 | |
|
78 | 78 | def unhide(self, request): |
|
79 | 79 | """ |
|
80 | 80 | Removed tag from user's hidden tags. |
|
81 | 81 | """ |
|
82 | 82 | |
|
83 | 83 | user = self._get_user(request) |
|
84 | 84 | tag = get_object_or_404(Tag, name=self.tag_name) |
|
85 | 85 | |
|
86 | 86 | user.unhide_tag(tag) |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now