Show More
@@ -57,14 +57,13 b' class PostManager(models.Manager):' | |||
|
57 | 57 | |
|
58 | 58 | def delete_post(self, post): |
|
59 | 59 | children = self.filter(parent=post.id) |
|
60 | for child in children: | |
|
61 |
|
|
|
60 | ||
|
61 | map(self.delete_post, children) | |
|
62 | 62 | post.delete() |
|
63 | 63 | |
|
64 | 64 | def delete_posts_by_ip(self, ip): |
|
65 | 65 | posts = self.filter(poster_ip=ip) |
|
66 |
|
|
|
67 | self.delete_post(post) | |
|
66 | map(self.delete_post, posts) | |
|
68 | 67 | |
|
69 | 68 | def get_threads(self, tag=None, page=ALL_PAGES, |
|
70 | 69 | order_by='-last_edit_time'): |
@@ -133,8 +132,7 b' class PostManager(models.Manager):' | |||
|
133 | 132 | num_threads_to_delete = thread_count - settings.MAX_THREAD_COUNT |
|
134 | 133 | old_threads = threads[thread_count - num_threads_to_delete:] |
|
135 | 134 | |
|
136 |
|
|
|
137 | self.delete_post(thread) | |
|
135 | map(self.delete_post, old_threads) | |
|
138 | 136 | |
|
139 | 137 | def _bump_thread(self, thread_id): |
|
140 | 138 | thread = self.get(id=thread_id) |
@@ -172,8 +170,6 b' class Tag(models.Model):' | |||
|
172 | 170 | objects = TagManager() |
|
173 | 171 | |
|
174 | 172 | name = models.CharField(max_length=100) |
|
175 | # TODO Connect the tag to its posts to check the number of threads for | |
|
176 | # the tag. | |
|
177 | 173 | |
|
178 | 174 | def __unicode__(self): |
|
179 | 175 | return self.name |
@@ -235,6 +231,13 b' class Post(models.Model):' | |||
|
235 | 231 | return '#' + str(self.id) + ' ' + self.title + ' (' + \ |
|
236 | 232 | self.text.raw[:50] + ')' |
|
237 | 233 | |
|
234 | def get_title(self): | |
|
235 | title = self.title | |
|
236 | if len(title) == 0: | |
|
237 | title = self.text.raw[:20] | |
|
238 | ||
|
239 | return title | |
|
240 | ||
|
238 | 241 | def _get_replies(self): |
|
239 | 242 | return Post.objects.filter(parent=self.id) |
|
240 | 243 | |
@@ -249,14 +252,6 b' class Post(models.Model):' | |||
|
249 | 252 | |
|
250 | 253 | return images_count |
|
251 | 254 | |
|
252 | def get_gets_count(self): | |
|
253 | gets_count = 1 if self.is_get() else 0 | |
|
254 | for reply in self._get_replies(): | |
|
255 | if reply.is_get(): | |
|
256 | gets_count += 1 | |
|
257 | ||
|
258 | return gets_count | |
|
259 | ||
|
260 | 255 | def can_bump(self): |
|
261 | 256 | """Check if the thread can be bumped by replying""" |
|
262 | 257 | |
@@ -314,7 +309,7 b' class User(models.Model):' | |||
|
314 | 309 | return RANK_MODERATOR >= self.rank |
|
315 | 310 | |
|
316 | 311 | def __unicode__(self): |
|
317 | return self.user_id | |
|
312 | return self.user_id + '(' + self.rank + ')' | |
|
318 | 313 | |
|
319 | 314 | |
|
320 | 315 | class Setting(models.Model): |
@@ -28,10 +28,11 b'' | |||
|
28 | 28 | <div class="navigation_panel"> |
|
29 | 29 | <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a> |
|
30 | 30 | {% for tag in tags %} |
|
31 |
<a class="tag" href="{% url 'tag' tag_name=tag.name %}" |
|
|
32 | {{ tag.name }}</a> | |
|
31 | <a class="tag" href="{% url 'tag' tag_name=tag.name %}" | |
|
32 | >{{ tag.name }}</a> | |
|
33 | 33 | {% endfor %} |
|
34 |
<a class="tag" href="{% url 'tags' %}" |
|
|
34 | <a class="tag" href="{% url 'tags' %}" alt="{% trans 'Tag management' %}" | |
|
35 | >[...]</a> | |
|
35 | 36 | <a class="link" href="{% url 'settings' %}">{% trans 'Settings' %}</a> |
|
36 | 37 | </div> |
|
37 | 38 |
@@ -160,7 +160,7 b'' | |||
|
160 | 160 | {% block metapanel %} |
|
161 | 161 | |
|
162 | 162 | <span class="metapanel"> |
|
163 |
<b><a href="{% url "authors" %}">Neboard</a> |
|
|
163 | <b><a href="{% url "authors" %}">Neboard</a> 1.1</b> | |
|
164 | 164 | {% trans "Pages:" %} |
|
165 | 165 | {% for page in pages %} |
|
166 | 166 | [<a href=" |
@@ -4,11 +4,11 b'' | |||
|
4 | 4 | {% load markup %} |
|
5 | 5 | |
|
6 | 6 | {% block head %} |
|
7 | <title>Neboard - {{ posts.0.title }}</title> | |
|
7 | <title>Neboard - {{ posts.0.get_title }}</title> | |
|
8 | <script src="{{ STATIC_URL }}js/thread.js"></script> | |
|
8 | 9 | {% endblock %} |
|
9 | 10 | |
|
10 | 11 | {% block content %} |
|
11 | <script src="{{ STATIC_URL }}js/thread.js"></script> | |
|
12 | 12 | |
|
13 | 13 | {% if posts %} |
|
14 | 14 | <div id="posts"> |
@@ -2,7 +2,6 b' import hashlib' | |||
|
2 | 2 | from django.core.urlresolvers import reverse |
|
3 | 3 | from django.template import RequestContext |
|
4 | 4 | from django.shortcuts import render, redirect, get_object_or_404 |
|
5 | from django.http import HttpResponseRedirect | |
|
6 | 5 | from django.utils import timezone |
|
7 | 6 | |
|
8 | 7 | from boards import forms |
@@ -11,7 +10,7 b' from boards import utils' | |||
|
11 | 10 | from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \ |
|
12 | 11 | ThreadCaptchaForm, PostCaptchaForm, LoginForm |
|
13 | 12 | |
|
14 |
from boards.models import Post, Tag, Ban, User, RANK_USER, |
|
|
13 | from boards.models import Post, Tag, Ban, User, RANK_USER, NO_PARENT | |
|
15 | 14 | from boards import authors |
|
16 | 15 | import neboard |
|
17 | 16 | |
@@ -155,7 +154,8 b' def login(request):' | |||
|
155 | 154 | context = _init_default_context(request) |
|
156 | 155 | |
|
157 | 156 | if request.method == 'POST': |
|
158 |
form = LoginForm(request.POST, request.FILES, |
|
|
157 | form = LoginForm(request.POST, request.FILES, | |
|
158 | error_class=PlainErrorList) | |
|
159 | 159 | if form.is_valid(): |
|
160 | 160 | user = User.objects.get(user_id=form.cleaned_data['user_id']) |
|
161 | 161 | request.session['user_id'] = user.id |
@@ -225,6 +225,7 b' def delete(request, post_id):' | |||
|
225 | 225 | post = get_object_or_404(Post, id=post_id) |
|
226 | 226 | |
|
227 | 227 | if user.is_moderator(): |
|
228 | # TODO Show confirmation page before deletion | |
|
228 | 229 | Post.objects.delete_post(post) |
|
229 | 230 | |
|
230 | 231 | if NO_PARENT == post.parent: |
@@ -263,10 +264,11 b' def tag_unsubscribe(request, tag_name):' | |||
|
263 | 264 | return redirect(all_tags) |
|
264 | 265 | |
|
265 | 266 | |
|
266 | def _get_theme(request): | |
|
267 | def _get_theme(request, user=None): | |
|
267 | 268 | """Get user's CSS theme""" |
|
268 | 269 | |
|
269 | user = _get_user(request) | |
|
270 | if not user: | |
|
271 | user = _get_user(request) | |
|
270 | 272 | theme = user.get_setting('theme') |
|
271 | 273 | if not theme: |
|
272 | 274 | theme = neboard.settings.DEFAULT_THEME |
@@ -287,9 +289,11 b' def _init_default_context(request):' | |||
|
287 | 289 | """Create context with default values that are used in most views""" |
|
288 | 290 | |
|
289 | 291 | context = RequestContext(request) |
|
290 | context['user'] = _get_user(request) | |
|
291 |
|
|
|
292 |
context[' |
|
|
292 | ||
|
293 | user = _get_user(request) | |
|
294 | context['user'] = user | |
|
295 | context['tags'] = sorted(user.fav_tags.all(), key=lambda tag: tag.name) | |
|
296 | context['theme'] = _get_theme(request, user) | |
|
293 | 297 | |
|
294 | 298 | return context |
|
295 | 299 | |
@@ -313,8 +317,7 b' def _get_user(request):' | |||
|
313 | 317 | session['user_id'] = user.id |
|
314 | 318 | else: |
|
315 | 319 | user = User.objects.get(id=session['user_id']) |
|
320 | user.last_access_time = timezone.now() | |
|
316 | 321 | user.save() |
|
317 | 322 | |
|
318 | user.last_access_time = timezone.now() | |
|
319 | ||
|
320 | 323 | return user |
General Comments 0
You need to be logged in to leave comments.
Login now