##// END OF EJS Templates
Added noindex to the pages without unique content or user-specific ones
neko259 -
r1040:e158fb64 default
parent child Browse files
Show More
@@ -1,30 +1,31 b''
1 {% extends 'boards/base.html' %}
1 {% extends 'boards/base.html' %}
2
2
3 {% load board %}
3 {% load board %}
4 {% load i18n %}
4 {% load i18n %}
5
5
6 {% block head %}
6 {% block head %}
7 <meta name="robots" content="noindex">
7 <title>{{ site_name }} - {% trans 'Notifications' %} - {{ notification_username }}</title>
8 <title>{{ site_name }} - {% trans 'Notifications' %} - {{ notification_username }}</title>
8 {% endblock %}
9 {% endblock %}
9
10
10 {% block content %}
11 {% block content %}
11 <div class="tag_info"><a href="{% url 'notifications' notification_username %}" class="user-cast">@{{ notification_username }}</a></div>
12 <div class="tag_info"><a href="{% url 'notifications' notification_username %}" class="user-cast">@{{ notification_username }}</a></div>
12
13
13 {% if page %}
14 {% if page %}
14 {% if page.has_previous %}
15 {% if page.has_previous %}
15 <div class="page_link">
16 <div class="page_link">
16 <a href="?page={{ page.previous_page_number }}">{% trans "Previous page" %}</a>
17 <a href="?page={{ page.previous_page_number }}">{% trans "Previous page" %}</a>
17 </div>
18 </div>
18 {% endif %}
19 {% endif %}
19
20
20 {% for post in page.object_list %}
21 {% for post in page.object_list %}
21 {% post_view post %}
22 {% post_view post %}
22 {% endfor %}
23 {% endfor %}
23
24
24 {% if page.has_next %}
25 {% if page.has_next %}
25 <div class="page_link">
26 <div class="page_link">
26 <a href="?page={{ page.next_page_number }}">{% trans "Next page" %}</a>
27 <a href="?page={{ page.next_page_number }}">{% trans "Next page" %}</a>
27 </div>
28 </div>
28 {% endif %}
29 {% endif %}
29 {% endif %}
30 {% endif %}
30 {% endblock %}
31 {% endblock %}
@@ -1,188 +1,190 b''
1 {% extends "boards/base.html" %}
1 {% extends "boards/base.html" %}
2
2
3 {% load i18n %}
3 {% load i18n %}
4 {% load cache %}
4 {% load cache %}
5 {% load board %}
5 {% load board %}
6 {% load static %}
6 {% load static %}
7
7
8 {% block head %}
8 {% block head %}
9 <meta name="robots" content="noindex">
10
9 {% if tag %}
11 {% if tag %}
10 <title>{{ tag.name }} - {{ site_name }}</title>
12 <title>{{ tag.name }} - {{ site_name }}</title>
11 {% else %}
13 {% else %}
12 <title>{{ site_name }}</title>
14 <title>{{ site_name }}</title>
13 {% endif %}
15 {% endif %}
14
16
15 {% if current_page.has_previous %}
17 {% if current_page.has_previous %}
16 <link rel="prev" href="
18 <link rel="prev" href="
17 {% if tag %}
19 {% if tag %}
18 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
20 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
19 {% else %}
21 {% else %}
20 {% url "index" page=current_page.previous_page_number %}
22 {% url "index" page=current_page.previous_page_number %}
21 {% endif %}
23 {% endif %}
22 " />
24 " />
23 {% endif %}
25 {% endif %}
24 {% if current_page.has_next %}
26 {% if current_page.has_next %}
25 <link rel="next" href="
27 <link rel="next" href="
26 {% if tag %}
28 {% if tag %}
27 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
29 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
28 {% else %}
30 {% else %}
29 {% url "index" page=current_page.next_page_number %}
31 {% url "index" page=current_page.next_page_number %}
30 {% endif %}
32 {% endif %}
31 " />
33 " />
32 {% endif %}
34 {% endif %}
33
35
34 {% endblock %}
36 {% endblock %}
35
37
36 {% block content %}
38 {% block content %}
37
39
38 {% get_current_language as LANGUAGE_CODE %}
40 {% get_current_language as LANGUAGE_CODE %}
39
41
40 {% if tag %}
42 {% if tag %}
41 <div class="tag_info">
43 <div class="tag_info">
42 <h2>
44 <h2>
43 <form action="{% url 'tag' tag.name %}" method="post" class="post-button-form">
45 <form action="{% url 'tag' tag.name %}" method="post" class="post-button-form">
44 {% if is_favorite %}
46 {% if is_favorite %}
45 <button name="method" value="unsubscribe" class="fav">β˜…</button>
47 <button name="method" value="unsubscribe" class="fav">β˜…</button>
46 {% else %}
48 {% else %}
47 <button name="method" value="subscribe" class="not_fav">β˜…</button>
49 <button name="method" value="subscribe" class="not_fav">β˜…</button>
48 {% endif %}
50 {% endif %}
49 </form>
51 </form>
50 <form action="{% url 'tag' tag.name %}" method="post" class="post-button-form">
52 <form action="{% url 'tag' tag.name %}" method="post" class="post-button-form">
51 {% if is_hidden %}
53 {% if is_hidden %}
52 <button name="method" value="unhide" class="fav">H</button>
54 <button name="method" value="unhide" class="fav">H</button>
53 {% else %}
55 {% else %}
54 <button name="method" value="hide" class="not_fav">H</button>
56 <button name="method" value="hide" class="not_fav">H</button>
55 {% endif %}
57 {% endif %}
56 </form>
58 </form>
57 {% autoescape off %}
59 {% autoescape off %}
58 {{ tag.get_view }}
60 {{ tag.get_view }}
59 {% endautoescape %}
61 {% endautoescape %}
60 {% if moderator %}
62 {% if moderator %}
61 <span class="moderator_info">[<a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a>]</span>
63 <span class="moderator_info">[<a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a>]</span>
62 {% endif %}
64 {% endif %}
63 </h2>
65 </h2>
64 <p>{% blocktrans with thread_count=tag.get_thread_count post_count=tag.get_post_count %}This tag has {{ thread_count }} threads and {{ post_count }} posts.{% endblocktrans %}</p>
66 <p>{% blocktrans with thread_count=tag.get_thread_count post_count=tag.get_post_count %}This tag has {{ thread_count }} threads and {{ post_count }} posts.{% endblocktrans %}</p>
65 </div>
67 </div>
66 {% endif %}
68 {% endif %}
67
69
68 {% if threads %}
70 {% if threads %}
69 {% if current_page.has_previous %}
71 {% if current_page.has_previous %}
70 <div class="page_link">
72 <div class="page_link">
71 <a href="
73 <a href="
72 {% if tag %}
74 {% if tag %}
73 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
75 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
74 {% else %}
76 {% else %}
75 {% url "index" page=current_page.previous_page_number %}
77 {% url "index" page=current_page.previous_page_number %}
76 {% endif %}
78 {% endif %}
77 ">{% trans "Previous page" %}</a>
79 ">{% trans "Previous page" %}</a>
78 </div>
80 </div>
79 {% endif %}
81 {% endif %}
80
82
81 {% for thread in threads %}
83 {% for thread in threads %}
82 {% cache 600 thread_short thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
84 {% cache 600 thread_short thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
83 <div class="thread">
85 <div class="thread">
84 {% post_view thread.get_opening_post moderator is_opening=True thread=thread truncated=True need_open_link=True %}
86 {% post_view thread.get_opening_post moderator is_opening=True thread=thread truncated=True need_open_link=True %}
85 {% if not thread.archived %}
87 {% if not thread.archived %}
86 {% with last_replies=thread.get_last_replies %}
88 {% with last_replies=thread.get_last_replies %}
87 {% if last_replies %}
89 {% if last_replies %}
88 {% with skipped_replies_count=thread.get_skipped_replies_count %}
90 {% with skipped_replies_count=thread.get_skipped_replies_count %}
89 {% if skipped_replies_count %}
91 {% if skipped_replies_count %}
90 <div class="skipped_replies">
92 <div class="skipped_replies">
91 <a href="{% url 'thread' thread.get_opening_post_id %}">
93 <a href="{% url 'thread' thread.get_opening_post_id %}">
92 {% blocktrans with count=skipped_replies_count %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %}
94 {% blocktrans with count=skipped_replies_count %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %}
93 </a>
95 </a>
94 </div>
96 </div>
95 {% endif %}
97 {% endif %}
96 {% endwith %}
98 {% endwith %}
97 <div class="last-replies">
99 <div class="last-replies">
98 {% for post in last_replies %}
100 {% for post in last_replies %}
99 {% post_view post is_opening=False moderator=moderator truncated=True %}
101 {% post_view post is_opening=False moderator=moderator truncated=True %}
100 {% endfor %}
102 {% endfor %}
101 </div>
103 </div>
102 {% endif %}
104 {% endif %}
103 {% endwith %}
105 {% endwith %}
104 {% endif %}
106 {% endif %}
105 </div>
107 </div>
106 {% endcache %}
108 {% endcache %}
107 {% endfor %}
109 {% endfor %}
108
110
109 {% if current_page.has_next %}
111 {% if current_page.has_next %}
110 <div class="page_link">
112 <div class="page_link">
111 <a href="
113 <a href="
112 {% if tag %}
114 {% if tag %}
113 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
115 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
114 {% else %}
116 {% else %}
115 {% url "index" page=current_page.next_page_number %}
117 {% url "index" page=current_page.next_page_number %}
116 {% endif %}
118 {% endif %}
117 ">{% trans "Next page" %}</a>
119 ">{% trans "Next page" %}</a>
118 </div>
120 </div>
119 {% endif %}
121 {% endif %}
120 {% else %}
122 {% else %}
121 <div class="post">
123 <div class="post">
122 {% trans 'No threads exist. Create the first one!' %}</div>
124 {% trans 'No threads exist. Create the first one!' %}</div>
123 {% endif %}
125 {% endif %}
124
126
125 <div class="post-form-w">
127 <div class="post-form-w">
126 <script src="{% static 'js/panel.js' %}"></script>
128 <script src="{% static 'js/panel.js' %}"></script>
127 <div class="post-form">
129 <div class="post-form">
128 <div class="form-title">{% trans "Create new thread" %}</div>
130 <div class="form-title">{% trans "Create new thread" %}</div>
129 <div class="swappable-form-full">
131 <div class="swappable-form-full">
130 <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %}
132 <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %}
131 {{ form.as_div }}
133 {{ form.as_div }}
132 <div class="form-submit">
134 <div class="form-submit">
133 <input type="submit" value="{% trans "Post" %}"/>
135 <input type="submit" value="{% trans "Post" %}"/>
134 </div>
136 </div>
135 (ctrl-enter)
137 (ctrl-enter)
136 </form>
138 </form>
137 </div>
139 </div>
138 <div>
140 <div>
139 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
141 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
140 </div>
142 </div>
141 <div><a href="{% url "staticpage" name="help" %}">
143 <div><a href="{% url "staticpage" name="help" %}">
142 {% trans 'Text syntax' %}</a></div>
144 {% trans 'Text syntax' %}</a></div>
143 </div>
145 </div>
144 </div>
146 </div>
145
147
146 <script src="{% static 'js/form.js' %}"></script>
148 <script src="{% static 'js/form.js' %}"></script>
147
149
148 {% endblock %}
150 {% endblock %}
149
151
150 {% block metapanel %}
152 {% block metapanel %}
151
153
152 <span class="metapanel">
154 <span class="metapanel">
153 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
155 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
154 {% trans "Pages:" %}
156 {% trans "Pages:" %}
155 <a href="
157 <a href="
156 {% if tag %}
158 {% if tag %}
157 {% url "tag" tag_name=tag.name page=paginator.page_range|first %}
159 {% url "tag" tag_name=tag.name page=paginator.page_range|first %}
158 {% else %}
160 {% else %}
159 {% url "index" page=paginator.page_range|first %}
161 {% url "index" page=paginator.page_range|first %}
160 {% endif %}
162 {% endif %}
161 ">&lt;&lt;</a>
163 ">&lt;&lt;</a>
162 [
164 [
163 {% for page in paginator.center_range %}
165 {% for page in paginator.center_range %}
164 <a
166 <a
165 {% ifequal page current_page.number %}
167 {% ifequal page current_page.number %}
166 class="current_page"
168 class="current_page"
167 {% endifequal %}
169 {% endifequal %}
168 href="
170 href="
169 {% if tag %}
171 {% if tag %}
170 {% url "tag" tag_name=tag.name page=page %}
172 {% url "tag" tag_name=tag.name page=page %}
171 {% else %}
173 {% else %}
172 {% url "index" page=page %}
174 {% url "index" page=page %}
173 {% endif %}
175 {% endif %}
174 ">{{ page }}</a>
176 ">{{ page }}</a>
175 {% if not forloop.last %},{% endif %}
177 {% if not forloop.last %},{% endif %}
176 {% endfor %}
178 {% endfor %}
177 ]
179 ]
178 <a href="
180 <a href="
179 {% if tag %}
181 {% if tag %}
180 {% url "tag" tag_name=tag.name page=paginator.page_range|last %}
182 {% url "tag" tag_name=tag.name page=paginator.page_range|last %}
181 {% else %}
183 {% else %}
182 {% url "index" page=paginator.page_range|last %}
184 {% url "index" page=paginator.page_range|last %}
183 {% endif %}
185 {% endif %}
184 ">&gt;&gt;</a>
186 ">&gt;&gt;</a>
185 [<a href="rss/">RSS</a>]
187 [<a href="rss/">RSS</a>]
186 </span>
188 </span>
187
189
188 {% endblock %}
190 {% endblock %}
@@ -1,42 +1,43 b''
1 {% extends "boards/base.html" %}
1 {% extends "boards/base.html" %}
2
2
3 {% load i18n %}
3 {% load i18n %}
4 {% load humanize %}
4 {% load humanize %}
5
5
6 {% block head %}
6 {% block head %}
7 <meta name="robots" content="noindex">
7 <title>{% trans 'Settings' %} - {{ site_name }}</title>
8 <title>{% trans 'Settings' %} - {{ site_name }}</title>
8 {% endblock %}
9 {% endblock %}
9
10
10 {% block content %}
11 {% block content %}
11
12
12 <div class="post">
13 <div class="post">
13 <p>
14 <p>
14 {% if moderator %}
15 {% if moderator %}
15 {% trans 'You are moderator.' %}
16 {% trans 'You are moderator.' %}
16 {% endif %}
17 {% endif %}
17 </p>
18 </p>
18 {% if hidden_tags %}
19 {% if hidden_tags %}
19 <p>{% trans 'Hidden tags:' %}
20 <p>{% trans 'Hidden tags:' %}
20 {% for tag in hidden_tags %}
21 {% for tag in hidden_tags %}
21 {% autoescape off %}
22 {% autoescape off %}
22 {{ tag.get_view }}
23 {{ tag.get_view }}
23 {% endautoescape %}
24 {% endautoescape %}
24 {% endfor %}
25 {% endfor %}
25 </p>
26 </p>
26 {% else %}
27 {% else %}
27 <p>{% trans 'No hidden tags.' %}</p>
28 <p>{% trans 'No hidden tags.' %}</p>
28 {% endif %}
29 {% endif %}
29 </div>
30 </div>
30
31
31 <div class="post-form-w">
32 <div class="post-form-w">
32 <div class="post-form">
33 <div class="post-form">
33 <form method="post">{% csrf_token %}
34 <form method="post">{% csrf_token %}
34 {{ form.as_div }}
35 {{ form.as_div }}
35 <div class="form-submit">
36 <div class="form-submit">
36 <input type="submit" value="{% trans "Save" %}" />
37 <input type="submit" value="{% trans "Save" %}" />
37 </div>
38 </div>
38 </form>
39 </form>
39 </div>
40 </div>
40 </div>
41 </div>
41
42
42 {% endblock %}
43 {% endblock %}
@@ -1,68 +1,69 b''
1 {% extends "boards/base.html" %}
1 {% extends "boards/base.html" %}
2
2
3 {% load i18n %}
3 {% load i18n %}
4 {% load cache %}
4 {% load cache %}
5 {% load static from staticfiles %}
5 {% load static from staticfiles %}
6 {% load board %}
6 {% load board %}
7
7
8 {% block head %}
8 {% block head %}
9 <meta name="robots" content="noindex">
9 <title>{{ thread.get_opening_post.get_title|striptags|truncatewords:10 }}
10 <title>{{ thread.get_opening_post.get_title|striptags|truncatewords:10 }}
10 - {{ site_name }}</title>
11 - {{ site_name }}</title>
11 {% endblock %}
12 {% endblock %}
12
13
13 {% block content %}
14 {% block content %}
14 {% spaceless %}
15 {% spaceless %}
15 {% get_current_language as LANGUAGE_CODE %}
16 {% get_current_language as LANGUAGE_CODE %}
16
17
17 {% cache 600 thread_gallery_view thread.id thread.last_edit_time LANGUAGE_CODE request.get_host %}
18 {% cache 600 thread_gallery_view thread.id thread.last_edit_time LANGUAGE_CODE request.get_host %}
18 <div class="image-mode-tab">
19 <div class="image-mode-tab">
19 <a href="{% url 'thread' thread.get_opening_post.id %}">{% trans 'Normal mode' %}</a>,
20 <a href="{% url 'thread' thread.get_opening_post.id %}">{% trans 'Normal mode' %}</a>,
20 <a class="current_mode" href="{% url 'thread_gallery' thread.get_opening_post.id %}">{% trans 'Gallery mode' %}</a>
21 <a class="current_mode" href="{% url 'thread_gallery' thread.get_opening_post.id %}">{% trans 'Gallery mode' %}</a>
21 </div>
22 </div>
22
23
23 <div id="posts-table">
24 <div id="posts-table">
24 {% for post in posts %}
25 {% for post in posts %}
25 <div class="gallery_image">
26 <div class="gallery_image">
26 {% with post.get_first_image as image %}
27 {% with post.get_first_image as image %}
27 <div>
28 <div>
28 <a
29 <a
29 class="thumb"
30 class="thumb"
30 href="{{ image.image.url }}"><img
31 href="{{ image.image.url }}"><img
31 src="{{ image.image.url_200x150 }}"
32 src="{{ image.image.url_200x150 }}"
32 alt="{{ post.id }}"
33 alt="{{ post.id }}"
33 width="{{ image.pre_width }}"
34 width="{{ image.pre_width }}"
34 height="{{ image.pre_height }}"
35 height="{{ image.pre_height }}"
35 data-width="{{ image.width }}"
36 data-width="{{ image.width }}"
36 data-height="{{ image.height }}"/>
37 data-height="{{ image.height }}"/>
37 </a>
38 </a>
38 </div>
39 </div>
39 <div class="gallery_image_metadata">
40 <div class="gallery_image_metadata">
40 {{ image.width }}x{{ image.height }}
41 {{ image.width }}x{{ image.height }}
41 {% image_actions image.image.url request.get_host %}
42 {% image_actions image.image.url request.get_host %}
42 <br />
43 <br />
43 <a href="{{ post.get_url }}">>>{{ post.id }}</a>
44 <a href="{{ post.get_url }}">>>{{ post.id }}</a>
44 </div>
45 </div>
45 {% endwith %}
46 {% endwith %}
46 </div>
47 </div>
47 {% endfor %}
48 {% endfor %}
48 </div>
49 </div>
49 {% endcache %}
50 {% endcache %}
50
51
51 {% endspaceless %}
52 {% endspaceless %}
52 {% endblock %}
53 {% endblock %}
53
54
54 {% block metapanel %}
55 {% block metapanel %}
55
56
56 {% get_current_language as LANGUAGE_CODE %}
57 {% get_current_language as LANGUAGE_CODE %}
57
58
58 <span class="metapanel" data-last-update="{{ last_update }}">
59 <span class="metapanel" data-last-update="{{ last_update }}">
59 {% cache 600 thread_gallery_meta thread.last_edit_time moderator LANGUAGE_CODE %}
60 {% cache 600 thread_gallery_meta thread.last_edit_time moderator LANGUAGE_CODE %}
60 <span id="reply-count">{{ thread.get_reply_count }}</span>/{{ max_replies }}
61 <span id="reply-count">{{ thread.get_reply_count }}</span>/{{ max_replies }}
61 {% trans 'messages' %},
62 {% trans 'messages' %},
62 <span id="image-count">{{ thread.get_images_count }}</span> {% trans 'images' %}.
63 <span id="image-count">{{ thread.get_images_count }}</span> {% trans 'images' %}.
63 {% trans 'Last update: ' %}<time datetime="{{ thread.last_edit_time|date:'c' }}">{{ thread.last_edit_time|date:'r' }}</time>
64 {% trans 'Last update: ' %}<time datetime="{{ thread.last_edit_time|date:'c' }}">{{ thread.last_edit_time|date:'r' }}</time>
64 [<a href="rss/">RSS</a>]
65 [<a href="rss/">RSS</a>]
65 {% endcache %}
66 {% endcache %}
66 </span>
67 </span>
67
68
68 {% endblock %}
69 {% endblock %}
@@ -1,38 +1,42 b''
1 {% extends 'boards/base.html' %}
1 {% extends 'boards/base.html' %}
2
2
3 {% load board %}
3 {% load board %}
4 {% load i18n %}
4 {% load i18n %}
5
5
6 {% block head %}
7 <meta name="robots" content="noindex">
8 {% endblock %}
9
6 {% block content %}
10 {% block content %}
7 <div class="post-form-w">
11 <div class="post-form-w">
8 <div class="post-form">
12 <div class="post-form">
9 <h3>{% trans 'Search' %}</h3>
13 <h3>{% trans 'Search' %}</h3>
10 <form method="get" action="">
14 <form method="get" action="">
11 {{ form.as_div }}
15 {{ form.as_div }}
12 <div class="form-submit">
16 <div class="form-submit">
13 <input type="submit" value="{% trans 'Search' %}">
17 <input type="submit" value="{% trans 'Search' %}">
14 </div>
18 </div>
15 </form>
19 </form>
16 </div>
20 </div>
17 </div>
21 </div>
18
22
19 {% if page %}
23 {% if page %}
20 {% if page.has_previous %}
24 {% if page.has_previous %}
21 <div class="page_link">
25 <div class="page_link">
22 <a href="?query={{ query }}&amp;page={{ page.previous_page_number }}">{% trans "Previous page" %}
26 <a href="?query={{ query }}&amp;page={{ page.previous_page_number }}">{% trans "Previous page" %}
23 </a>
27 </a>
24 </div>
28 </div>
25 {% endif %}
29 {% endif %}
26
30
27 {% for result in page.object_list %}
31 {% for result in page.object_list %}
28 {{ result.object.get_search_view }}
32 {{ result.object.get_search_view }}
29 {% endfor %}
33 {% endfor %}
30
34
31 {% if page.has_next %}
35 {% if page.has_next %}
32 <div class="page_link">
36 <div class="page_link">
33 <a href="?query={{ query }}&amp;page={{ page.next_page_number }}">{% trans "Next page" %}
37 <a href="?query={{ query }}&amp;page={{ page.next_page_number }}">{% trans "Next page" %}
34 </a>
38 </a>
35 </div>
39 </div>
36 {% endif %}
40 {% endif %}
37 {% endif %}
41 {% endif %}
38 {% endblock %}
42 {% endblock %}
@@ -1,133 +1,131 b''
1 from django.core.urlresolvers import reverse
2 from django.core.exceptions import ObjectDoesNotExist
1 from django.core.exceptions import ObjectDoesNotExist
3 from django.db import transaction
4 from django.http import Http404
2 from django.http import Http404
5 from django.shortcuts import get_object_or_404, render, redirect
3 from django.shortcuts import get_object_or_404, render, redirect
6 from django.views.generic.edit import FormMixin
4 from django.views.generic.edit import FormMixin
7
5
8 from boards import utils, settings
6 from boards import utils, settings
9 from boards.forms import PostForm, PlainErrorList
7 from boards.forms import PostForm, PlainErrorList
10 from boards.models import Post, Ban
8 from boards.models import Post
11 from boards.views.banned import BannedView
12 from boards.views.base import BaseBoardView, CONTEXT_FORM
9 from boards.views.base import BaseBoardView, CONTEXT_FORM
13 from boards.views.posting_mixin import PostMixin
10 from boards.views.posting_mixin import PostMixin
14 import neboard
11 import neboard
15
12
13
16 TEMPLATE_GALLERY = 'boards/thread_gallery.html'
14 TEMPLATE_GALLERY = 'boards/thread_gallery.html'
17 TEMPLATE_NORMAL = 'boards/thread.html'
15 TEMPLATE_NORMAL = 'boards/thread.html'
18
16
19 CONTEXT_POSTS = 'posts'
17 CONTEXT_POSTS = 'posts'
20 CONTEXT_OP = 'opening_post'
18 CONTEXT_OP = 'opening_post'
21 CONTEXT_BUMPLIMIT_PRG = 'bumplimit_progress'
19 CONTEXT_BUMPLIMIT_PRG = 'bumplimit_progress'
22 CONTEXT_POSTS_LEFT = 'posts_left'
20 CONTEXT_POSTS_LEFT = 'posts_left'
23 CONTEXT_LASTUPDATE = "last_update"
21 CONTEXT_LASTUPDATE = "last_update"
24 CONTEXT_MAX_REPLIES = 'max_replies'
22 CONTEXT_MAX_REPLIES = 'max_replies'
25 CONTEXT_THREAD = 'thread'
23 CONTEXT_THREAD = 'thread'
26 CONTEXT_BUMPABLE = 'bumpable'
24 CONTEXT_BUMPABLE = 'bumpable'
27 CONTEXT_WS_TOKEN = 'ws_token'
25 CONTEXT_WS_TOKEN = 'ws_token'
28 CONTEXT_WS_PROJECT = 'ws_project'
26 CONTEXT_WS_PROJECT = 'ws_project'
29 CONTEXT_WS_HOST = 'ws_host'
27 CONTEXT_WS_HOST = 'ws_host'
30 CONTEXT_WS_PORT = 'ws_port'
28 CONTEXT_WS_PORT = 'ws_port'
31
29
32 FORM_TITLE = 'title'
30 FORM_TITLE = 'title'
33 FORM_TEXT = 'text'
31 FORM_TEXT = 'text'
34 FORM_IMAGE = 'image'
32 FORM_IMAGE = 'image'
35
33
36
34
37 class ThreadView(BaseBoardView, PostMixin, FormMixin):
35 class ThreadView(BaseBoardView, PostMixin, FormMixin):
38
36
39 def get(self, request, post_id, form: PostForm=None):
37 def get(self, request, post_id, form: PostForm=None):
40 try:
38 try:
41 opening_post = Post.objects.get(id=post_id)
39 opening_post = Post.objects.get(id=post_id)
42 except ObjectDoesNotExist:
40 except ObjectDoesNotExist:
43 raise Http404
41 raise Http404
44
42
45 # If this is not OP, don't show it as it is
43 # If this is not OP, don't show it as it is
46 if not opening_post.is_opening():
44 if not opening_post.is_opening():
47 return redirect(opening_post.get_thread().get_opening_post().get_url())
45 return redirect(opening_post.get_thread().get_opening_post().get_url())
48
46
49 if not form:
47 if not form:
50 form = PostForm(error_class=PlainErrorList)
48 form = PostForm(error_class=PlainErrorList)
51
49
52 thread_to_show = opening_post.get_thread()
50 thread_to_show = opening_post.get_thread()
53
51
54 params = dict()
52 params = dict()
55
53
56 params[CONTEXT_FORM] = form
54 params[CONTEXT_FORM] = form
57 params[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch(
55 params[CONTEXT_LASTUPDATE] = str(utils.datetime_to_epoch(
58 thread_to_show.last_edit_time))
56 thread_to_show.last_edit_time))
59 params[CONTEXT_THREAD] = thread_to_show
57 params[CONTEXT_THREAD] = thread_to_show
60 params[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD
58 params[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD
61
59
62 if settings.WEBSOCKETS_ENABLED:
60 if settings.WEBSOCKETS_ENABLED:
63 params[CONTEXT_WS_TOKEN] = utils.get_websocket_token(
61 params[CONTEXT_WS_TOKEN] = utils.get_websocket_token(
64 timestamp=params[CONTEXT_LASTUPDATE])
62 timestamp=params[CONTEXT_LASTUPDATE])
65 params[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID
63 params[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID
66 params[CONTEXT_WS_HOST] = request.get_host().split(':')[0]
64 params[CONTEXT_WS_HOST] = request.get_host().split(':')[0]
67 params[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT
65 params[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT
68
66
69 params.update(self.get_data(thread_to_show))
67 params.update(self.get_data(thread_to_show))
70
68
71 return render(request, self.get_template(), params)
69 return render(request, self.get_template(), params)
72
70
73 def post(self, request, post_id):
71 def post(self, request, post_id):
74 opening_post = get_object_or_404(Post, id=post_id)
72 opening_post = get_object_or_404(Post, id=post_id)
75
73
76 # If this is not OP, don't show it as it is
74 # If this is not OP, don't show it as it is
77 if not opening_post.is_opening():
75 if not opening_post.is_opening():
78 raise Http404
76 raise Http404
79
77
80 if not opening_post.get_thread().archived:
78 if not opening_post.get_thread().archived:
81 form = PostForm(request.POST, request.FILES,
79 form = PostForm(request.POST, request.FILES,
82 error_class=PlainErrorList)
80 error_class=PlainErrorList)
83 form.session = request.session
81 form.session = request.session
84
82
85 if form.is_valid():
83 if form.is_valid():
86 return self.new_post(request, form, opening_post)
84 return self.new_post(request, form, opening_post)
87 if form.need_to_ban:
85 if form.need_to_ban:
88 # Ban user because he is suspected to be a bot
86 # Ban user because he is suspected to be a bot
89 self._ban_current_user(request)
87 self._ban_current_user(request)
90
88
91 return self.get(request, post_id, form)
89 return self.get(request, post_id, form)
92
90
93 def new_post(self, request, form: PostForm, opening_post: Post=None,
91 def new_post(self, request, form: PostForm, opening_post: Post=None,
94 html_response=True):
92 html_response=True):
95 """
93 """
96 Adds a new post (in thread or as a reply).
94 Adds a new post (in thread or as a reply).
97 """
95 """
98
96
99 ip = utils.get_client_ip(request)
97 ip = utils.get_client_ip(request)
100
98
101 data = form.cleaned_data
99 data = form.cleaned_data
102
100
103 title = data[FORM_TITLE]
101 title = data[FORM_TITLE]
104 text = data[FORM_TEXT]
102 text = data[FORM_TEXT]
105 image = form.get_image()
103 image = form.get_image()
106
104
107 text = self._remove_invalid_links(text)
105 text = self._remove_invalid_links(text)
108
106
109 post_thread = opening_post.get_thread()
107 post_thread = opening_post.get_thread()
110
108
111 post = Post.objects.create_post(title=title, text=text, image=image,
109 post = Post.objects.create_post(title=title, text=text, image=image,
112 thread=post_thread, ip=ip)
110 thread=post_thread, ip=ip)
113 post.send_to_websocket(request)
111 post.send_to_websocket(request)
114
112
115 if html_response:
113 if html_response:
116 if opening_post:
114 if opening_post:
117 return redirect(post.get_url())
115 return redirect(post.get_url())
118 else:
116 else:
119 return post
117 return post
120
118
121 def get_data(self, thread):
119 def get_data(self, thread):
122 """
120 """
123 Returns context params for the view.
121 Returns context params for the view.
124 """
122 """
125
123
126 pass
124 pass
127
125
128 def get_template(self):
126 def get_template(self):
129 """
127 """
130 Gets template to show the thread mode on.
128 Gets template to show the thread mode on.
131 """
129 """
132
130
133 pass
131 pass
General Comments 0
You need to be logged in to leave comments. Login now