diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -38,7 +38,7 @@ class PostForm(forms.Form): class ThreadForm(PostForm): - INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?', '-'] + INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?', '-', '.', ','] tags = forms.CharField(max_length=100) diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -137,6 +137,14 @@ class TagManager(models.Manager): return tags + def get_popular_tags(self): + all_tags = self.get_not_empty_tags() + + sorted_tags = sorted(all_tags, key=lambda tag: tag.get_popularity(), + reverse=True) + + return sorted_tags[:settings.POPULAR_TAGS] + class Tag(models.Model): """ @@ -160,6 +168,14 @@ class Tag(models.Model): posts_with_tag = Post.objects.get_threads(tag=self) return len(posts_with_tag) + def get_popularity(self): + posts_with_tag = Post.objects.get_threads(tag=self) + reply_count = 0 + for post in posts_with_tag: + reply_count += post.get_reply_count() + + return reply_count + class Post(models.Model): """A post is a message.""" diff --git a/boards/static/css/md/base_page.css b/boards/static/css/md/base_page.css --- a/boards/static/css/md/base_page.css +++ b/boards/static/css/md/base_page.css @@ -17,14 +17,6 @@ html { color: #afdcec; } -.link:hover, a:hover { - color: #fff380; -} - -.post_id:hover { - color: #ccc555; -} - .block { display: inline-block; vertical-align: top; @@ -34,10 +26,6 @@ html { color: #b4cfec; } -.tag:hover { - color: #d0edb4; -} - .post_id { color: #fff380; } @@ -192,4 +180,8 @@ blockquote { .comment { color: darkseagreen; -} \ No newline at end of file +} + +a:hover { + text-decoration: underline; +} diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -21,4 +21,5 @@ urlpatterns = patterns('', url(r'^thread/(?P\w+)/$', views.thread, name='thread'), # /boards/theme/theme_name/ url(r'^settings$', views.settings, name='settings'), + url(r'^tags$', views.all_tags, name='tags'), ) diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -20,7 +20,7 @@ def index(request, page=0): # TODO Get rid of the duplicate code in index and tag views context['threads'] = None if len(threads) == 0 else threads context['form'] = forms.ThreadForm() - context['tags'] = Tag.objects.get_not_empty_tags() + context['tags'] = Tag.objects.get_popular_tags() context['theme'] = _get_theme(request) context['pages'] = range(Post.objects.get_thread_page_count()) @@ -94,7 +94,7 @@ def tag(request, tag_name, page=0): context = RequestContext(request) context['threads'] = None if len(threads) == 0 else threads context['tag'] = tag_name - context['tags'] = Tag.objects.get_not_empty_tags() + context['tags'] = Tag.objects.get_popular_tags() context['theme'] = _get_theme(request) context['pages'] = range(Post.objects.get_thread_page_count(tag=tag)) @@ -117,7 +117,7 @@ def thread(request, post_id): context['posts'] = posts context['form'] = forms.PostForm() - context['tags'] = Tag.objects.get_not_empty_tags() + context['tags'] = Tag.objects.get_popular_tags() context['theme'] = _get_theme(request) return render(request, 'thread.html', context) @@ -165,11 +165,20 @@ def settings(request): selected_theme = _get_theme(request) form = SettingsForm(initial={'theme': selected_theme}) context['form'] = form - context['tags'] = Tag.objects.get_not_empty_tags() + context['tags'] = Tag.objects.get_popular_tags() context['theme'] = _get_theme(request) return render(request, 'settings.html', context) +def all_tags(request): + context = RequestContext(request) + context['tags'] = Tag.objects.get_popular_tags() + context['theme'] = _get_theme(request) + context['all_tags'] = Tag.objects.get_not_empty_tags() + + return render(request, 'tags.html', context) + + def _get_theme(request): return request.session.get('theme', neboard.settings.DEFAULT_THEME) \ No newline at end of file diff --git a/neboard/settings.py b/neboard/settings.py --- a/neboard/settings.py +++ b/neboard/settings.py @@ -169,6 +169,9 @@ LOGGING = { } } +MARKUP_FIELD_TYPES = ( + ('markdown', markdown_extended), +) # Custom imageboard settings MAX_POSTS_PER_THREAD = 10 # Thread bumplimit MAX_THREAD_COUNT = 500 # Old threads will be deleted to preserve this count @@ -180,6 +183,4 @@ THEMES = [ ('sw', 'Snow White') ] DEFAULT_THEME = 'md' -MARKUP_FIELD_TYPES = ( - ('markdown', markdown_extended), -) \ No newline at end of file +POPULAR_TAGS=10 \ No newline at end of file diff --git a/templates/base.html b/templates/base.html --- a/templates/base.html +++ b/templates/base.html @@ -26,6 +26,7 @@ {{ tag.name }}({{ tag.get_post_count }}) {% endfor %} + [...] {% trans 'Settings' %} diff --git a/templates/posting_general.html b/templates/posting_general.html --- a/templates/posting_general.html +++ b/templates/posting_general.html @@ -35,9 +35,6 @@ {% endautoescape %}
- {{ thread.get_reply_count }} {% trans 'replies' %}, - {{ thread.get_images_count }} {% trans 'images' %}, - {{ thread.get_gets_count }} {% trans 'gets' %}. {% if thread.tags.all %} {% trans 'Tags' %}: {% for tag in thread.tags.all %} @@ -46,7 +43,10 @@ {{ tag.name }} {% endfor %} - {% endif %} + {% endif %}, + {{ thread.get_reply_count }} {% trans 'replies' %}, + {{ thread.get_images_count }} {% trans 'images' %}. + {% trans 'Last update: ' %}{{ thread.last_edit_time }}
{% endfor %} diff --git a/templates/thread.html b/templates/tags.html copy from templates/thread.html copy to templates/tags.html --- a/templates/thread.html +++ b/templates/tags.html @@ -4,89 +4,21 @@ {% load markup %} {% block head %} - Neboard - {{ posts.0.title }} + Neboard - {% trans "tags" %} {% endblock %} {% block content %} - {% if posts %} - {% for post in posts %} - -
- {% if post.image %} -
- - -
- {% endif %} -
- {{ post.title }} - - (#{{ post.id }}) - [{{ post.pub_time }}] - {% if post.is_get %} - - {% trans "Get!" %} - - {% endif %} - {% autoescape off %} - {{ post.text.rendered }} - {% endautoescape %} -
- {% if post.tags.all %} - - {% endif %} -
+
+ {% if tags %} + {% for tag in all_tags %} + + {{ tag.name }}
{% endfor %} {% else %} - No threads found. + No tags found.
{% endif %} - -
{% csrf_token %} -
-
{% trans "Reply to thread" %}
-
-
-
{% trans 'Title' %}
-
{{ form.title }}
-
-
-
{% trans 'Text' %}
-
{{ form.text }}
-
-
-
{% trans 'Image' %}
-
{{ form.image }}
-
-
-
-
Use - markdown syntax for posting.
-
Example: *italic*, **bold**
-
Insert quotes with ">"
-
-
- -{% endblock %} - -{% block metapanel %} - - - {{ posts.0.get_reply_count }} {% trans 'replies' %}, - {{ posts.0.get_images_count }} {% trans 'images' %}, - {{ posts.0.get_gets_count }} {% trans 'gets' %} - +
{% endblock %} \ No newline at end of file diff --git a/templates/thread.html b/templates/thread.html --- a/templates/thread.html +++ b/templates/thread.html @@ -85,8 +85,8 @@ {{ posts.0.get_reply_count }} {% trans 'replies' %}, - {{ posts.0.get_images_count }} {% trans 'images' %}, - {{ posts.0.get_gets_count }} {% trans 'gets' %} + {{ posts.0.get_images_count }} {% trans 'images' %}. + {% trans 'Last update: ' %}{{ posts.0.last_edit_time }} {% endblock %} \ No newline at end of file