Browse Source

Abstract template for threads lists

Rafał Pitoń 11 years ago
parent
commit
0542a8df86

+ 108 - 0
misago/templates/misago/threads/base.html

@@ -0,0 +1,108 @@
+{% extends "misago/base.html" %}
+{% load humanize i18n misago_avatars %}
+
+{% block content %}
+<div class="container">
+  {% block threads-list %}
+  <div class="threads-list">
+    {% block threads-panel %}
+    <div class="table-panel">
+      <ul class="list-group">
+        {% for thread in threads %}
+        <li class="list-group-item{% if thread.is_new %} new{% endif %}">
+          <div class="row">
+
+            <div class="col-md-8">
+              {% if thread.is_announcement %}
+                {% if thread.is_new %}
+                <span class="thread-icon tooltip-top fa fa-star fa-lg fa-fw" title="{% trans "Announcement, unread" %}"></span>
+                {% else %}
+                <span class="thread-icon tooltip-top fa fa-star-o fa-lg fa-fw" title="{% trans "Announcement, read" %}"></span>
+                {% endif %}
+              {% elif thread.is_pinned %}
+                {% if thread.is_new %}
+                <span class="thread-icon tooltip-top fa fa-bookmark fa-lg fa-fw" title="{% trans "Pinned, unread" %}"></span>
+                {% else %}
+                <span class="thread-icon tooltip-top fa fa-bookmark-o fa-lg fa-fw" title="{% trans "Pinned, read" %}"></span>
+                {% endif %}
+              {% else %}
+                {% if thread.is_new %}
+                <span class="thread-icon tooltip-top fa fa-circle fa-lg fa-fw" title="{% trans "Unread posts" %}"></span>
+                {% else %}
+                <span class="thread-icon tooltip-top fa fa-circle-thin fa-lg fa-fw" title="{% trans "Read posts" %}"></span>
+                {% endif %}
+              {% endif %}
+
+              <a href="{{ thread.get_absolute_url }}" class="item-title">
+                {{ thread.title }}
+              </a>
+
+              <ul class="list-unstyled thread-flags">
+                {% if thread.has_reported_posts %}
+                <li class="tooltip-top" title="{% trans "Reported posts" %}">
+                  <span class="fa fa-exclamation-triangle fa-fw fa-lg"></span>
+                </li>
+                {% endif %}
+                {% if thread.has_moderated_posts and not thread.is_moderated %}
+                <li class="tooltip-top" title="{% trans "Moderated posts" %}">
+                  <span class="fa fa-eye-slash fa-fw fa-lg"></span>
+                </li>
+                {% endif %}
+                {% if thread.is_poll %}
+                <li class="tooltip-top" title="{% trans "Poll" %}">
+                  <span class="fa fa-bar-chart-o fa-fw fa-lg"></span>
+                </li>
+                {% endif %}
+                {% if thread.is_moderated %}
+                <li class="tooltip-top" title="{% trans "Moderated" %}">
+                  <span class="fa fa-eye-slash fa-fw fa-lg"></span>
+                </li>
+                {% endif %}
+                {% if thread.is_closed %}
+                <li class="tooltip-top" title="{% trans "Closed" %}">
+                  <span class="fa fa-lock fa-fw fa-lg"></span>
+                </li>
+                {% endif %}
+              </ul>
+            </div>
+            {% block thread-extra %}
+            <div class="col-md-4 thread-stats">
+              {% block thread-stats %}
+              <div class="thread-replies">
+                <div class="tooltip-top" title="{% blocktrans trimmed with replies=thread.replies|intcomma count counter=thread.replies %}{{ replies }} reply{% plural %}{{ replies }} replies{% endblocktrans %}">
+                  <span class="glyphicon glyphicon-comment"></span>
+                  {{ thread.replies|intcomma }}
+                </div>
+              </div>
+
+              {% if thread.last_poster_id %}
+              <a href="{% url USER_PROFILE_URL user_slug=thread.last_poster_slug user_id=thread.last_poster_id %}" class="thread-author tooltip-top" title="{% blocktrans with user=thread.last_poster_name %}Last post by {{ user }}{% endblocktrans %}">
+                <img src="{{ thread.last_poster_id|avatar:25 }}" alt="{% trans "Avatar" %}" class="avatar">
+              </a>
+              {% else %}
+              <span class="thread-author tooltip-top" title="{% blocktrans with user=thread.last_poster_name %}Last post by {{ user }}{% endblocktrans %}">
+                <img src="{% blankavatar 25 %}" alt="{% trans "Avatar" %}" class="avatar">
+              </span>
+              {% endif %}
+
+              <a href="#" class="dynamic time-ago tooltip-top" data-timestamp="{{ thread.last_post_on|date:"c" }}" title="{% blocktrans with last_post=thread.last_post_on|date %}Last post from {{ last_post }}{% endblocktrans %}">
+                {{ thread.last_post_on|date }}
+              </a>
+              {% endblock thread-stats %}
+            </div>
+            {% endblock thread-extra %}
+          </div>
+        </li>
+        {% empty %}
+        <li class="list-group-item message-row">
+          {% trans "No threads were posted in this forum, or you don't have permission to see them." %}
+        </li>
+        {% endfor %}
+      </ul>
+    </div>
+    {% endblock threads-panel %}
+
+  </div>
+  {% endblock threads-list %}
+</div>
+{% endblock content %}

+ 69 - 0
misago/templates/misago/threads/forum.html

@@ -0,0 +1,69 @@
+{% extends "misago/threads/base.html" %}
+{% load i18n misago_stringutils %}
+
+
+{% block title %}{{ forum.name }}{% if page.number > 1 %} ({% blocktrans with page=page.number %}Page {{ page }}{% endblocktrans %}){% endif %} | {{ block.super }}{% endblock title %}
+
+
+{% block meta-description %}{{ forum.description|striplinebreaks }}{% endblock meta-description %}
+
+
+{% block content %}
+<div{% if forum.css %} class="page-{{ forum.css_class }}"{% endif %}>
+  <div class="page-header">
+    <div class="container">
+      {% if path %}
+      <ol class="breadcrumb">
+        {% for crumb in path|slice:":-1" %}
+        <li>
+          <a href="{{ crumb.get_absolute_url }}">{{ crumb.name }}</a>{% if not forloop.last %}<span class="fa fa-chevron-right"></span>{% endif %}
+        </li>
+        {% endfor %}
+      </ol>
+      {% endif %}
+
+      <h1>{{ forum.name }}</h1>
+    </div>
+  </div>
+  {{ block.super }}
+{% endblock content %}
+
+
+{% block threads-list %}
+{% if forum.description %}
+<div class="lead">
+  {{ forum.description|escape|urlize|linebreaks }}
+</div>
+{% endif %}
+
+{% if forum.subforums %}
+{% include "misago/forums/subforums.html" with category=forum %}
+{% endif %}
+
+{{ block.super }}
+{% endblock threads-list %}
+
+
+{% block threads-panel %}
+<div class="table-actions">
+  {% include "misago/threads/paginator.html" %}
+  {% if user.is_authenticated %}
+  {% include "misago/threads/sort.html" %}
+  {% include "misago/threads/show.html" %}
+  {% endif %}
+  {% include "misago/threads/reply_btn.html" %}
+</div>
+
+{{ block.super }}
+
+<div class="table-actions">
+  {% include "misago/threads/paginator.html" %}
+  {% include "misago/threads/reply_btn.html" %}
+</div>
+{% endblock threads-panel %}
+
+
+{% block javascripts %}
+{{ block.super }}
+{% include "misago/forums/js.html" %}
+{% endblock javascripts %}

+ 0 - 156
misago/templates/misago/threads/list.html

@@ -1,156 +0,0 @@
-{% extends "misago/base.html" %}
-{% load humanize i18n misago_avatars misago_capture misago_stringutils %}
-
-
-{% block title %}{{ forum.name }}{% if page.number > 1 %} ({% blocktrans with page=page.number %}Page {{ page }}{% endblocktrans %}){% endif %} | {{ block.super }}{% endblock title %}
-
-
-{% block meta-description %}{{ forum.description|striplinebreaks }}{% endblock meta-description %}
-
-
-{% block content %}
-<div{% if forum.css %} class="page-{{ forum.css_class }}"{% endif %}>
-  <div class="page-header">
-    <div class="container">
-      {% if path %}
-      <ol class="breadcrumb">
-        {% for crumb in path|slice:":-1" %}
-        <li>
-          <a href="{{ crumb.get_absolute_url }}">{{ crumb.name }}</a>{% if not forloop.last %}<span class="fa fa-chevron-right"></span>{% endif %}
-        </li>
-        {% endfor %}
-      </ol>
-      {% endif %}
-
-      <h1>{{ forum.name }}</h1>
-    </div>
-  </div>
-  <div class="container">
-    {% if forum.description %}
-    <div class="lead">
-      {{ forum.description|escape|urlize|linebreaks }}
-    </div>
-    {% endif %}
-
-    {% if forum.subforums %}
-    {% include "misago/forums/subforums.html" with category=forum %}
-    {% endif %}
-
-    <div class="threads-list">
-
-      <div class="table-actions">
-        {% include "misago/threads/paginator.html" %}
-        {% if user.is_authenticated %}
-        {% include "misago/threads/sort.html" %}
-        {% include "misago/threads/show.html" %}
-        {% endif %}
-        {% include "misago/threads/reply_btn.html" %}
-      </div>
-
-      <div class="table-panel">
-        <ul class="list-group">
-          {% for thread in threads %}
-          <li class="list-group-item{% if thread.is_new %} new{% endif %}">
-            <div class="row">
-
-              <div class="col-md-8">
-                {% if thread.is_announcement %}
-                  {% if thread.is_new %}
-                  <span class="thread-icon tooltip-top fa fa-star fa-lg fa-fw" title="{% trans "Announcement, unread" %}"></span>
-                  {% else %}
-                  <span class="thread-icon tooltip-top fa fa-star-o fa-lg fa-fw" title="{% trans "Announcement, read" %}"></span>
-                  {% endif %}
-                {% elif thread.is_pinned %}
-                  {% if thread.is_new %}
-                  <span class="thread-icon tooltip-top fa fa-bookmark fa-lg fa-fw" title="{% trans "Pinned, unread" %}"></span>
-                  {% else %}
-                  <span class="thread-icon tooltip-top fa fa-bookmark-o fa-lg fa-fw" title="{% trans "Pinned, read" %}"></span>
-                  {% endif %}
-                {% else %}
-                  {% if thread.is_new %}
-                  <span class="thread-icon tooltip-top fa fa-circle fa-lg fa-fw" title="{% trans "Unread posts" %}"></span>
-                  {% else %}
-                  <span class="thread-icon tooltip-top fa fa-circle-thin fa-lg fa-fw" title="{% trans "Read posts" %}"></span>
-                  {% endif %}
-                {% endif %}
-
-                <a href="{{ thread.get_absolute_url }}" class="item-title">
-                  {{ thread.title }}
-                </a>
-
-                <ul class="list-unstyled thread-flags">
-                  {% if thread.has_reported_posts %}
-                  <li class="tooltip-top" title="{% trans "Reported posts" %}">
-                    <span class="fa fa-exclamation-triangle fa-fw fa-lg"></span>
-                  </li>
-                  {% endif %}
-                  {% if thread.has_moderated_posts and not thread.is_moderated %}
-                  <li class="tooltip-top" title="{% trans "Moderated posts" %}">
-                    <span class="fa fa-eye-slash fa-fw fa-lg"></span>
-                  </li>
-                  {% endif %}
-                  {% if thread.is_poll %}
-                  <li class="tooltip-top" title="{% trans "Poll" %}">
-                    <span class="fa fa-bar-chart-o fa-fw fa-lg"></span>
-                  </li>
-                  {% endif %}
-                  {% if thread.is_moderated %}
-                  <li class="tooltip-top" title="{% trans "Moderated" %}">
-                    <span class="fa fa-eye-slash fa-fw fa-lg"></span>
-                  </li>
-                  {% endif %}
-                  {% if thread.is_closed %}
-                  <li class="tooltip-top" title="{% trans "Closed" %}">
-                    <span class="fa fa-lock fa-fw fa-lg"></span>
-                  </li>
-                  {% endif %}
-                </ul>
-              </div>
-              <div class="col-md-4 thread-stats">
-                <div class="thread-replies">
-                  <div class="tooltip-top" title="{% blocktrans trimmed with replies=thread.replies|intcomma count counter=thread.replies %}{{ replies }} reply{% plural %}{{ replies }} replies{% endblocktrans %}">
-                    <span class="glyphicon glyphicon-comment"></span>
-                    {{ thread.replies|intcomma }}
-                  </div>
-                </div>
-
-                {% if thread.last_poster_id %}
-                <a href="{% url USER_PROFILE_URL user_slug=thread.last_poster_slug user_id=thread.last_poster_id %}" class="thread-author tooltip-top" title="{% blocktrans with user=thread.last_poster_name %}Last post by {{ user }}{% endblocktrans %}">
-                  <img src="{{ thread.last_poster_id|avatar:25 }}" alt="{% trans "Avatar" %}" class="avatar">
-                </a>
-                {% else %}
-                <span class="thread-author tooltip-top" title="{% blocktrans with user=thread.last_poster_name %}Last post by {{ user }}{% endblocktrans %}">
-                  <img src="{% blankavatar 25 %}" alt="{% trans "Avatar" %}" class="avatar">
-                </span>
-                {% endif %}
-
-                <a href="#" class="dynamic time-ago tooltip-top" data-timestamp="{{ thread.last_post_on|date:"c" }}" title="{% blocktrans with last_post=thread.last_post_on|date %}Last post from {{ last_post }}{% endblocktrans %}">
-                  {{ thread.last_post_on|date }}
-                </a>
-              </div>
-            </div>
-          </li>
-          {% empty %}
-          <li class="list-group-item message-row">
-            {% trans "No threads were posted in this forum, or you don't have permission to see them." %}
-          </li>
-          {% endfor %}
-        </ul>
-      </div>
-
-      <div class="table-actions">
-        {% include "misago/threads/paginator.html" %}
-        {% include "misago/threads/reply_btn.html" %}
-      </div>
-
-    </div>
-
-  </div>
-</div>
-{% endblock content %}
-
-
-{% block javascripts %}
-{{ block.super }}
-{% include "misago/forums/js.html" %}
-{% endblock javascripts %}

+ 2 - 1
misago/threads/views/generic/__init__.py

@@ -3,4 +3,5 @@ from misago.threads.views.generic.base import *
 from misago.threads.views.generic.post import *
 from misago.threads.views.generic.post import *
 from misago.threads.views.generic.posting import *
 from misago.threads.views.generic.posting import *
 from misago.threads.views.generic.thread import *
 from misago.threads.views.generic.thread import *
-from misago.threads.views.generic.threadslists import *
+from misago.threads.views.generic.threads import *
+from misago.threads.views.generic.forum import *

+ 3 - 78
misago/threads/views/generic/threadslists.py → misago/threads/views/generic/forum.py

@@ -9,53 +9,10 @@ from misago.forums.lists import get_forums_list, get_forum_path
 from misago.threads.posting import (PostingInterrupt, EditorFormset,
 from misago.threads.posting import (PostingInterrupt, EditorFormset,
                                     START, REPLY, EDIT)
                                     START, REPLY, EDIT)
 from misago.threads.models import ANNOUNCEMENT, Thread
 from misago.threads.models import ANNOUNCEMENT, Thread
-from misago.threads.views.generic.base import ViewBase
+from misago.threads.views.generic.threads import OrderThreadsMixin, ThreadsView
 
 
 
 
-__all__ = ['OrderThreadsMixin', 'ThreadsView', 'ForumView']
-
-
-class OrderThreadsMixin(object):
-    order_by = (
-        ('recently-replied', ugettext_lazy("Recently replied")),
-        ('last-replied', ugettext_lazy("Last replied")),
-        ('most-replied', ugettext_lazy("Most replied")),
-        ('least-replied', ugettext_lazy("Least replied")),
-        ('newest', ugettext_lazy("Newest")),
-        ('oldest', ugettext_lazy("Oldest")),
-    )
-
-    def get_ordering(self, kwargs):
-        if kwargs.get('sort') in [o[0] for o in self.order_by]:
-            return kwargs.get('sort')
-        else:
-            return self.order_by[0][0]
-
-    def is_ordering_default(self, order_by):
-        return self.order_by[0][0] == order_by
-
-    def get_ordering_name(self, order_by):
-        for ordering in self.order_by:
-            if ordering[0] == order_by:
-                return ordering[1]
-
-    def get_orderings_dicts(self, exclude_ordering, links_params):
-        url_kwargs = links_params.copy()
-        dicts = []
-
-        for ordering in self.order_by:
-            if not dicts:
-                url_kwargs.pop('sort', None)
-            else:
-                url_kwargs['sort'] = ordering[0]
-
-            if ordering[0] != exclude_ordering:
-                dicts.append({
-                    'url': reverse(self.link_name, kwargs=url_kwargs),
-                    'name': ordering[1],
-                })
-
-        return dicts
+__all__ = ['FilterThreadsMixin', 'ForumView']
 
 
 
 
 class FilterThreadsMixin(object):
 class FilterThreadsMixin(object):
@@ -92,43 +49,11 @@ class FilterThreadsMixin(object):
         return dicts
         return dicts
 
 
 
 
-class ThreadsView(ViewBase):
-    def get_threads(self, request, kwargs):
-        queryset = self.get_threads_queryset(request, forum)
-
-        threads_qs = queryset.filter(weight__lt=ANNOUNCEMENT)
-        threads_qs = threads_qs.order_by('-weight', '-last_post_id')
-
-        page = paginate(threads_qs, kwargs.get('page', 0), 30, 10)
-        threads = []
-
-        for announcement in queryset.filter(weight=ANNOUNCEMENT):
-            threads.append(announcement)
-        for thread in page.object_list:
-            threads.append(thread)
-
-        for thread in threads:
-            thread.forum = forum
-
-        return page, threads
-
-    def get_threads_queryset(self, request):
-        return forum.thread_set.all().order_by('-last_post_id')
-
-    def add_threads_reads(self, request, threads):
-        for thread in threads:
-            thread.is_new = False
-
-        import random
-        for thread in threads:
-            thread.is_new = random.choice((True, False))
-
-
 class ForumView(FilterThreadsMixin, OrderThreadsMixin, ThreadsView):
 class ForumView(FilterThreadsMixin, OrderThreadsMixin, ThreadsView):
     """
     """
     Basic view for threads lists
     Basic view for threads lists
     """
     """
-    template = 'misago/threads/list.html'
+    template = 'misago/threads/forum.html'
 
 
     def get_threads(self, request, forum, kwargs,
     def get_threads(self, request, forum, kwargs,
                     order_by=None, filter_by=None):
                     order_by=None, filter_by=None):

+ 76 - 0
misago/threads/views/generic/threads.py

@@ -0,0 +1,76 @@
+from django.core.urlresolvers import reverse
+from django.db.models import Q
+from django.shortcuts import redirect
+from django.utils.translation import ugettext_lazy, ugettext as _
+
+from misago.core.shortcuts import paginate
+
+from misago.threads.views.generic.base import ViewBase
+
+
+__all__ = ['OrderThreadsMixin', 'ThreadsView']
+
+
+class OrderThreadsMixin(object):
+    order_by = (
+        ('recently-replied', ugettext_lazy("Recently replied")),
+        ('last-replied', ugettext_lazy("Last replied")),
+        ('most-replied', ugettext_lazy("Most replied")),
+        ('least-replied', ugettext_lazy("Least replied")),
+        ('newest', ugettext_lazy("Newest")),
+        ('oldest', ugettext_lazy("Oldest")),
+    )
+
+    def get_ordering(self, kwargs):
+        if kwargs.get('sort') in [o[0] for o in self.order_by]:
+            return kwargs.get('sort')
+        else:
+            return self.order_by[0][0]
+
+    def is_ordering_default(self, order_by):
+        return self.order_by[0][0] == order_by
+
+    def get_ordering_name(self, order_by):
+        for ordering in self.order_by:
+            if ordering[0] == order_by:
+                return ordering[1]
+
+    def get_orderings_dicts(self, exclude_ordering, links_params):
+        url_kwargs = links_params.copy()
+        dicts = []
+
+        for ordering in self.order_by:
+            if not dicts:
+                url_kwargs.pop('sort', None)
+            else:
+                url_kwargs['sort'] = ordering[0]
+
+            if ordering[0] != exclude_ordering:
+                dicts.append({
+                    'url': reverse(self.link_name, kwargs=url_kwargs),
+                    'name': ordering[1],
+                })
+
+        return dicts
+
+
+class ThreadsView(ViewBase):
+    def get_threads(self, request, kwargs):
+        queryset = self.get_threads_queryset(request, forum)
+        queryset = threads_qs.order_by('-last_post_id')
+
+        page = paginate(threads_qs, kwargs.get('page', 0), 30, 10)
+        threads = [thread for thread in page.object_list]
+
+        return page, threads
+
+    def get_threads_queryset(self, request):
+        return forum.thread_set.all().order_by('-last_post_id')
+
+    def add_threads_reads(self, request, threads):
+        for thread in threads:
+            thread.is_new = False
+
+        import random
+        for thread in threads:
+            thread.is_new = random.choice((True, False))