diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -57,14 +57,13 @@ class PostManager(models.Manager): def delete_post(self, post): children = self.filter(parent=post.id) - for child in children: - self.delete_post(child) + + map(self.delete_post, children) post.delete() def delete_posts_by_ip(self, ip): posts = self.filter(poster_ip=ip) - for post in posts: - self.delete_post(post) + map(self.delete_post, posts) def get_threads(self, tag=None, page=ALL_PAGES, order_by='-last_edit_time'): @@ -133,8 +132,7 @@ class PostManager(models.Manager): num_threads_to_delete = thread_count - settings.MAX_THREAD_COUNT old_threads = threads[thread_count - num_threads_to_delete:] - for thread in old_threads: - self.delete_post(thread) + map(self.delete_post, old_threads) def _bump_thread(self, thread_id): thread = self.get(id=thread_id) @@ -172,8 +170,6 @@ class Tag(models.Model): objects = TagManager() name = models.CharField(max_length=100) - # TODO Connect the tag to its posts to check the number of threads for - # the tag. def __unicode__(self): return self.name @@ -235,6 +231,13 @@ class Post(models.Model): return '#' + str(self.id) + ' ' + self.title + ' (' + \ self.text.raw[:50] + ')' + def get_title(self): + title = self.title + if len(title) == 0: + title = self.text.raw[:20] + + return title + def _get_replies(self): return Post.objects.filter(parent=self.id) @@ -249,14 +252,6 @@ class Post(models.Model): return images_count - def get_gets_count(self): - gets_count = 1 if self.is_get() else 0 - for reply in self._get_replies(): - if reply.is_get(): - gets_count += 1 - - return gets_count - def can_bump(self): """Check if the thread can be bumped by replying""" @@ -314,7 +309,7 @@ class User(models.Model): return RANK_MODERATOR >= self.rank def __unicode__(self): - return self.user_id + return self.user_id + '(' + self.rank + ')' class Setting(models.Model): diff --git a/boards/templates/boards/base.html b/boards/templates/boards/base.html --- a/boards/templates/boards/base.html +++ b/boards/templates/boards/base.html @@ -28,10 +28,11 @@ diff --git a/boards/templates/boards/posting_general.html b/boards/templates/boards/posting_general.html --- a/boards/templates/boards/posting_general.html +++ b/boards/templates/boards/posting_general.html @@ -160,7 +160,7 @@ {% block metapanel %} - Neboard pre1.0 + Neboard 1.1 {% trans "Pages:" %} {% for page in pages %} [ {% endblock %} {% block content %} - {% if posts %}
diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -2,7 +2,6 @@ import hashlib from django.core.urlresolvers import reverse from django.template import RequestContext from django.shortcuts import render, redirect, get_object_or_404 -from django.http import HttpResponseRedirect from django.utils import timezone from boards import forms @@ -11,7 +10,7 @@ from boards import utils from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \ ThreadCaptchaForm, PostCaptchaForm, LoginForm -from boards.models import Post, Tag, Ban, User, RANK_USER, RANK_MODERATOR, NO_PARENT +from boards.models import Post, Tag, Ban, User, RANK_USER, NO_PARENT from boards import authors import neboard @@ -155,7 +154,8 @@ def login(request): context = _init_default_context(request) if request.method == 'POST': - form = LoginForm(request.POST, request.FILES, error_class=PlainErrorList) + form = LoginForm(request.POST, request.FILES, + error_class=PlainErrorList) if form.is_valid(): user = User.objects.get(user_id=form.cleaned_data['user_id']) request.session['user_id'] = user.id @@ -225,6 +225,7 @@ def delete(request, post_id): post = get_object_or_404(Post, id=post_id) if user.is_moderator(): + # TODO Show confirmation page before deletion Post.objects.delete_post(post) if NO_PARENT == post.parent: @@ -263,10 +264,11 @@ def tag_unsubscribe(request, tag_name): return redirect(all_tags) -def _get_theme(request): +def _get_theme(request, user=None): """Get user's CSS theme""" - user = _get_user(request) + if not user: + user = _get_user(request) theme = user.get_setting('theme') if not theme: theme = neboard.settings.DEFAULT_THEME @@ -287,9 +289,11 @@ def _init_default_context(request): """Create context with default values that are used in most views""" context = RequestContext(request) - context['user'] = _get_user(request) - context['tags'] = _get_user(request).fav_tags.all() - context['theme'] = _get_theme(request) + + user = _get_user(request) + context['user'] = user + context['tags'] = sorted(user.fav_tags.all(), key=lambda tag: tag.name) + context['theme'] = _get_theme(request, user) return context @@ -313,8 +317,7 @@ def _get_user(request): session['user_id'] = user.id else: user = User.objects.get(id=session['user_id']) + user.last_access_time = timezone.now() user.save() - user.last_access_time = timezone.now() - return user