Show More
@@ -0,0 +1,3 b'' | |||||
|
1 | from boards.views.thread.thread import ThreadView | |||
|
2 | from boards.views.thread.normal import NormalThreadView | |||
|
3 | from boards.views.thread.gallery import GalleryThreadView |
@@ -0,0 +1,19 b'' | |||||
|
1 | from boards.views.thread import ThreadView | |||
|
2 | ||||
|
3 | TEMPLATE_GALLERY = 'boards/thread_gallery.html' | |||
|
4 | ||||
|
5 | CONTEXT_POSTS = 'posts' | |||
|
6 | ||||
|
7 | ||||
|
8 | class GalleryThreadView(ThreadView): | |||
|
9 | ||||
|
10 | def get_template(self): | |||
|
11 | return TEMPLATE_GALLERY | |||
|
12 | ||||
|
13 | def get_data(self, thread): | |||
|
14 | params = dict() | |||
|
15 | ||||
|
16 | params[CONTEXT_POSTS] = thread.get_replies_with_images( | |||
|
17 | view_fields_only=True) | |||
|
18 | ||||
|
19 | return params |
@@ -0,0 +1,38 b'' | |||||
|
1 | from boards import settings | |||
|
2 | from boards.views.thread import ThreadView | |||
|
3 | ||||
|
4 | TEMPLATE_NORMAL = 'boards/thread.html' | |||
|
5 | ||||
|
6 | CONTEXT_OP = 'opening_post' | |||
|
7 | CONTEXT_BUMPLIMIT_PRG = 'bumplimit_progress' | |||
|
8 | CONTEXT_POSTS_LEFT = 'posts_left' | |||
|
9 | CONTEXT_BUMPABLE = 'bumpable' | |||
|
10 | ||||
|
11 | FORM_TITLE = 'title' | |||
|
12 | FORM_TEXT = 'text' | |||
|
13 | FORM_IMAGE = 'image' | |||
|
14 | ||||
|
15 | MODE_GALLERY = 'gallery' | |||
|
16 | MODE_NORMAL = 'normal' | |||
|
17 | ||||
|
18 | ||||
|
19 | class NormalThreadView(ThreadView): | |||
|
20 | ||||
|
21 | def get_template(self): | |||
|
22 | return TEMPLATE_NORMAL | |||
|
23 | ||||
|
24 | def get_data(self, thread): | |||
|
25 | params = dict() | |||
|
26 | ||||
|
27 | bumpable = thread.can_bump() | |||
|
28 | params[CONTEXT_BUMPABLE] = bumpable | |||
|
29 | if bumpable: | |||
|
30 | left_posts = settings.MAX_POSTS_PER_THREAD \ | |||
|
31 | - thread.get_reply_count() | |||
|
32 | params[CONTEXT_POSTS_LEFT] = left_posts | |||
|
33 | params[CONTEXT_BUMPLIMIT_PRG] = str( | |||
|
34 | float(left_posts) / settings.MAX_POSTS_PER_THREAD * 100) | |||
|
35 | ||||
|
36 | params[CONTEXT_OP] = thread.get_opening_post() | |||
|
37 | ||||
|
38 | return params |
@@ -0,0 +1,135 b'' | |||||
|
1 | from django.core.urlresolvers import reverse | |||
|
2 | from django.db import transaction | |||
|
3 | from django.http import Http404 | |||
|
4 | from django.shortcuts import get_object_or_404, render, redirect | |||
|
5 | from django.views.generic.edit import FormMixin | |||
|
6 | ||||
|
7 | from boards import utils, settings | |||
|
8 | from boards.forms import PostForm, PlainErrorList | |||
|
9 | from boards.models import Post, Ban | |||
|
10 | from boards.views.banned import BannedView | |||
|
11 | from boards.views.base import BaseBoardView, CONTEXT_FORM | |||
|
12 | from boards.views.posting_mixin import PostMixin | |||
|
13 | import neboard | |||
|
14 | ||||
|
15 | TEMPLATE_GALLERY = 'boards/thread_gallery.html' | |||
|
16 | TEMPLATE_NORMAL = 'boards/thread.html' | |||
|
17 | ||||
|
18 | CONTEXT_POSTS = 'posts' | |||
|
19 | CONTEXT_OP = 'opening_post' | |||
|
20 | CONTEXT_BUMPLIMIT_PRG = 'bumplimit_progress' | |||
|
21 | CONTEXT_POSTS_LEFT = 'posts_left' | |||
|
22 | CONTEXT_LASTUPDATE = "last_update" | |||
|
23 | CONTEXT_MAX_REPLIES = 'max_replies' | |||
|
24 | CONTEXT_THREAD = 'thread' | |||
|
25 | CONTEXT_BUMPABLE = 'bumpable' | |||
|
26 | CONTEXT_WS_TOKEN = 'ws_token' | |||
|
27 | CONTEXT_WS_PROJECT = 'ws_project' | |||
|
28 | CONTEXT_WS_HOST = 'ws_host' | |||
|
29 | CONTEXT_WS_PORT = 'ws_port' | |||
|
30 | ||||
|
31 | FORM_TITLE = 'title' | |||
|
32 | FORM_TEXT = 'text' | |||
|
33 | FORM_IMAGE = 'image' | |||
|
34 | ||||
|
35 | ||||
|
36 | class ThreadView(BaseBoardView, PostMixin, FormMixin): | |||
|
37 | ||||
|
38 | def get(self, request, post_id, form=None): | |||
|
39 | try: | |||
|
40 | opening_post = Post.objects.filter(id=post_id).only('thread_new')[0] | |||
|
41 | except IndexError: | |||
|
42 | raise Http404 | |||
|
43 | ||||
|
44 | # If this is not OP, don't show it as it is | |||
|
45 | if not opening_post or not opening_post.is_opening(): | |||
|
46 | raise Http404 | |||
|
47 | ||||
|
48 | if not form: | |||
|
49 | form = PostForm(error_class=PlainErrorList) | |||
|
50 | ||||
|
51 | thread_to_show = opening_post.get_thread() | |||
|
52 | ||||
|
53 | params = dict() | |||
|
54 | ||||
|
55 | params[CONTEXT_FORM] = form | |||
|
56 | params[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch( | |||
|
57 | thread_to_show.last_edit_time)) | |||
|
58 | params[CONTEXT_THREAD] = thread_to_show | |||
|
59 | params[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD | |||
|
60 | ||||
|
61 | if settings.WEBSOCKETS_ENABLED: | |||
|
62 | params[CONTEXT_WS_TOKEN] = utils.get_websocket_token( | |||
|
63 | timestamp=params[CONTEXT_LASTUPDATE]) | |||
|
64 | params[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID | |||
|
65 | params[CONTEXT_WS_HOST] = request.get_host().split(':')[0] | |||
|
66 | params[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT | |||
|
67 | ||||
|
68 | params.update(self.get_data(thread_to_show)) | |||
|
69 | ||||
|
70 | return render(request, self.get_template(), params) | |||
|
71 | ||||
|
72 | def post(self, request, post_id): | |||
|
73 | opening_post = get_object_or_404(Post, id=post_id) | |||
|
74 | ||||
|
75 | # If this is not OP, don't show it as it is | |||
|
76 | if not opening_post.is_opening(): | |||
|
77 | raise Http404 | |||
|
78 | ||||
|
79 | if not opening_post.get_thread().archived: | |||
|
80 | form = PostForm(request.POST, request.FILES, | |||
|
81 | error_class=PlainErrorList) | |||
|
82 | form.session = request.session | |||
|
83 | ||||
|
84 | if form.is_valid(): | |||
|
85 | return self.new_post(request, form, opening_post) | |||
|
86 | if form.need_to_ban: | |||
|
87 | # Ban user because he is suspected to be a bot | |||
|
88 | self._ban_current_user(request) | |||
|
89 | ||||
|
90 | return self.get(request, post_id, form) | |||
|
91 | ||||
|
92 | def new_post(self, request, form, opening_post=None, html_response=True): | |||
|
93 | """ | |||
|
94 | Adds a new post (in thread or as a reply). | |||
|
95 | """ | |||
|
96 | ||||
|
97 | ip = utils.get_client_ip(request) | |||
|
98 | ||||
|
99 | data = form.cleaned_data | |||
|
100 | ||||
|
101 | title = data[FORM_TITLE] | |||
|
102 | text = data[FORM_TEXT] | |||
|
103 | image = data.get(FORM_IMAGE) | |||
|
104 | ||||
|
105 | text = self._remove_invalid_links(text) | |||
|
106 | ||||
|
107 | post_thread = opening_post.get_thread() | |||
|
108 | ||||
|
109 | post = Post.objects.create_post(title=title, text=text, image=image, | |||
|
110 | thread=post_thread, ip=ip) | |||
|
111 | post.send_to_websocket(request) | |||
|
112 | ||||
|
113 | thread_to_show = (opening_post.id if opening_post else post.id) | |||
|
114 | ||||
|
115 | if html_response: | |||
|
116 | if opening_post: | |||
|
117 | return redirect( | |||
|
118 | reverse('thread', kwargs={'post_id': thread_to_show}) | |||
|
119 | + '#' + str(post.id)) | |||
|
120 | else: | |||
|
121 | return post | |||
|
122 | ||||
|
123 | def get_data(self, thread): | |||
|
124 | """ | |||
|
125 | Returns context params for the view. | |||
|
126 | """ | |||
|
127 | ||||
|
128 | pass | |||
|
129 | ||||
|
130 | def get_template(self): | |||
|
131 | """ | |||
|
132 | Gets template to show the thread mode on. | |||
|
133 | """ | |||
|
134 | ||||
|
135 | pass |
@@ -30,7 +30,7 b'' | |||||
30 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> |
|
30 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> | |
31 | {% for tag in tags %} |
|
31 | {% for tag in tags %} | |
32 | {% autoescape off %} |
|
32 | {% autoescape off %} | |
33 |
{{ tag.get_view }} |
|
33 | {{ tag.get_view }}, | |
34 | {% endautoescape %} |
|
34 | {% endautoescape %} | |
35 | {% endfor %} |
|
35 | {% endfor %} | |
36 | <a href="{% url 'tags' %}" title="{% trans 'Tag management' %}" |
|
36 | <a href="{% url 'tags' %}" title="{% trans 'Tag management' %}" |
@@ -17,7 +17,7 b'' | |||||
17 |
|
17 | |||
18 | <div class="image-mode-tab"> |
|
18 | <div class="image-mode-tab"> | |
19 | <a class="current_mode" href="{% url 'thread' opening_post.id %}">{% trans 'Normal mode' %}</a>, |
|
19 | <a class="current_mode" href="{% url 'thread' opening_post.id %}">{% trans 'Normal mode' %}</a>, | |
20 |
<a href="{% url 'thread_ |
|
20 | <a href="{% url 'thread_gallery' opening_post.id %}">{% trans 'Gallery mode' %}</a> | |
21 | </div> |
|
21 | </div> | |
22 |
|
22 | |||
23 | {% if bumpable %} |
|
23 | {% if bumpable %} |
@@ -17,7 +17,7 b'' | |||||
17 | {% cache 600 thread_gallery_view thread.id thread.last_edit_time LANGUAGE_CODE request.get_host %} |
|
17 | {% cache 600 thread_gallery_view thread.id thread.last_edit_time LANGUAGE_CODE request.get_host %} | |
18 | <div class="image-mode-tab"> |
|
18 | <div class="image-mode-tab"> | |
19 | <a href="{% url 'thread' thread.get_opening_post.id %}">{% trans 'Normal mode' %}</a>, |
|
19 | <a href="{% url 'thread' thread.get_opening_post.id %}">{% trans 'Normal mode' %}</a>, | |
20 |
<a class="current_mode" href="{% url 'thread_ |
|
20 | <a class="current_mode" href="{% url 'thread_gallery' thread.get_opening_post.id %}">{% trans 'Gallery mode' %}</a> | |
21 | </div> |
|
21 | </div> | |
22 |
|
22 | |||
23 | <div id="posts-table"> |
|
23 | <div id="posts-table"> |
@@ -29,10 +29,10 b" urlpatterns = patterns(''," | |||||
29 | tag_threads.TagView.as_view(), name='tag'), |
|
29 | tag_threads.TagView.as_view(), name='tag'), | |
30 |
|
30 | |||
31 | # /boards/thread/ |
|
31 | # /boards/thread/ | |
32 | url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(), |
|
32 | url(r'^thread/(?P<post_id>\w+)/$', views.thread.normal.NormalThreadView.as_view(), | |
33 | name='thread'), |
|
33 | name='thread'), | |
34 |
url(r'^thread/(?P<post_id>\w+)/mode/ |
|
34 | url(r'^thread/(?P<post_id>\w+)/mode/gallery/$', views.thread.gallery.GalleryThreadView.as_view(), | |
35 |
|
|
35 | name='thread_gallery'), | |
36 |
|
36 | |||
37 | url(r'^settings/$', settings.SettingsView.as_view(), name='settings'), |
|
37 | url(r'^settings/$', settings.SettingsView.as_view(), name='settings'), | |
38 | url(r'^tags/$', all_tags.AllTagsView.as_view(), name='tags'), |
|
38 | url(r'^tags/$', all_tags.AllTagsView.as_view(), name='tags'), |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now