Browse Source

Basic thread view

Rafał Pitoń 10 years ago
parent
commit
4806f46d8a

+ 1 - 0
misago/static/misago/css/misago/misago.less

@@ -35,3 +35,4 @@
 @import "signin.less";
 @import "signin.less";
 @import "warnings.less";
 @import "warnings.less";
 @import "usercp.less";
 @import "usercp.less";
+@import "posts.less";

+ 122 - 0
misago/static/misago/css/misago/posts.less

@@ -0,0 +1,122 @@
+//
+// Posts Styles
+// --------------------------------------------------
+
+
+// Posts list
+//
+//==
+.posts-list {
+  .post {
+    .user-avatar {
+      img {
+        border-radius: @border-radius-base;
+      }
+    }
+
+    .media-body {
+      padding-left: @font-size-small;
+
+      .panel-default {
+        position: relative;
+        &:after, &:before {
+          right: 100%;
+          border: solid transparent;
+          content: "";
+          height: 0; width: 0;
+          position: absolute;
+          pointer-events: none;
+        }
+
+        &:after {
+          border-color: transparent;
+          border-right-color: @post-panel-bg;
+          border-width: @font-size-small;
+          top: @font-size-small;
+          margin-top: (@font-size-small * -1) + @font-size-small;
+        }
+
+        &:before {
+           border-color: transparent;
+           border-right-color: @post-panel-border;
+           border-width: @font-size-small + 2;
+           top: @font-size-small - 1;
+           margin-top: (@font-size-small * -1) + @font-size-small - 1px;
+        }
+      }
+    }
+  }
+}
+
+
+// Post panel
+//
+//==
+.posts-list {
+  .panel {
+    background: @post-panel-bg;
+    border-color: @post-panel-border;
+  }
+}
+
+
+// Post header
+//
+//==
+.posts-list {
+  .panel {
+    .panel-heading {
+      background: none;
+      border-bottom: none;
+      margin-bottom: @line-height-computed * -0.5;
+
+      .user-name {
+        color: @state-default;
+        font-weight: bold;
+      }
+
+      a.user-name {
+        &:link, &:visited {
+          color: @state-hover;
+        }
+
+        &:hover {
+          color: @state-hover;
+          text-decoration: text-underline;
+        }
+
+        &:active, &:focus {
+          color: @state-clicked;
+          text-decoration: text-underline;
+        }
+      }
+    }
+  }
+}
+
+
+// Post body
+//
+//==
+.posts-list {
+  .panel {
+    .panel-body {
+      .corrupted-message {
+        margin: 0px;
+      }
+    }
+  }
+}
+
+// Post footer
+//
+//==
+.posts-list {
+  .panel {
+    .panel-footer {
+      background: none;
+      border-top: none;
+      margin-top: @line-height-computed * -0.5;
+    }
+  }
+}

+ 4 - 0
misago/static/misago/css/misago/variables.less

@@ -309,6 +309,10 @@
 @user-card-active-border:              @state-clicked;
 @user-card-active-border:              @state-clicked;
 @user-card-active-shadow:              @state-clicked;
 @user-card-active-shadow:              @state-clicked;
 
 
+//** Post panels
+@post-panel-bg:               @panel-bg;
+@post-panel-border:           @panel-default-border;
+
 
 
 //== Form states and alerts
 //== Form states and alerts
 //
 //

+ 3 - 3
misago/templates/misago/profile/state.html

@@ -9,7 +9,7 @@
   {% trans "Banned" %}
   {% trans "Banned" %}
   {% endif %}
   {% endif %}
 {% elif state.is_hidden %}
 {% elif state.is_hidden %}
-  <span class="fa fa-circle-o fa-fw user-offilne"></span>
+  <span class="fa fa-circle-o fa-fw user-offline"></span>
   {% trans "Hides activity" %}
   {% trans "Hides activity" %}
 {% elif state.is_online_hidden %}
 {% elif state.is_online_hidden %}
   <span class="fa fa-circle fa-fw user-online"></span>
   <span class="fa fa-circle fa-fw user-online"></span>
@@ -20,7 +20,7 @@
     {{ state.last_click|date }}
     {{ state.last_click|date }}
   </abbr>
   </abbr>
   {% endcapture %%}
   {% endcapture %%}
-  <span class="fa fa-circle-o fa-fw user-offilne"></span>
+  <span class="fa fa-circle-o fa-fw user-offline"></span>
   {% blocktrans trimmed with last_seen=last_seen|safe %}
   {% blocktrans trimmed with last_seen=last_seen|safe %}
     Seen {{ last_seen }}, hidden
     Seen {{ last_seen }}, hidden
   {% endblocktrans %}
   {% endblocktrans %}
@@ -33,7 +33,7 @@
     {{ state.last_click|date }}
     {{ state.last_click|date }}
   </abbr>
   </abbr>
   {% endcapture %%}
   {% endcapture %%}
-  <span class="fa fa-circle-o fa-fw user-offilne"></span>
+  <span class="fa fa-circle-o fa-fw user-offline"></span>
   {% blocktrans trimmed with last_seen=last_seen|safe %}
   {% blocktrans trimmed with last_seen=last_seen|safe %}
     Seen {{ last_seen }}
     Seen {{ last_seen }}
   {% endblocktrans %}
   {% endblocktrans %}

+ 0 - 0
misago/templates/misago/thread/pagination.html


+ 45 - 0
misago/templates/misago/thread/post.html

@@ -0,0 +1,45 @@
+{% load i18n misago_avatars %}
+<div class="media post">
+  {% if post.poster %}
+  <a class="user-avatar pull-left" href="{% url USER_PROFILE_URL user_slug=post.poster.slug user_id=post.poster.id %}">
+    <img class="media-object" src="{{ post.poster|avatar:100 }}" alt="{% trans "Poster avatar" %}">
+  </a>
+  {% else %}
+  <span class="user-avatar pull-left">
+    <img class="media-object" src="{% blankavatar 100 %}" alt="{% trans "Poster avatar" %}">
+  </span>
+  {% endif %}
+
+  <div class="media-body">
+    <div class="panel panel-default">
+      <div class="panel-heading">
+        {% if post.poster %}
+        {% include "misago/user_state.html" with user=post.poster state=post.poster.online_state %}
+        <a class="user-name" href="{% url USER_PROFILE_URL user_slug=post.poster.slug user_id=post.poster.id %}">
+          {{ post.poster.username }}
+        </a>
+        {% else %}
+        <span class="fa fa-power-off fa-fw user-offline tooltip-top" title="{% blocktrans with user=post.poster_name %}{{ user }}'s forum account has been deleted.{% endblocktrans %}"></span>
+        <span class="user-name">
+          {{ post.poster_name }}
+        </span>
+        {% endif %}
+      </div>
+      <div class="panel-body">
+        {% if post.is_valid %}
+        <article class="misago-markup">
+          {{ post.parsed|safe }}
+        <article>
+        {% else %}
+        <p class="lead corrupted-message">
+          <span class="fa fa-exclamation-triangle"></span>
+          {% trans "Post can't be displayed due to invalid message checksum." %}
+        </p>
+        {% endif %}
+      </div>
+      <div class="panel-footer">
+        le footer
+      </div>
+    </div>
+  </div>
+</div>

+ 5 - 1
misago/templates/misago/thread/replies.html

@@ -58,7 +58,11 @@
   </div>
   </div>
   <div class="container">
   <div class="container">
 
 
-    Blah blah blah!
+    <div class="posts-list">
+      {% for post in posts %}
+      {% include "misago/thread/post.html" %}
+      {% endfor %}
+    </div>
 
 
   </div>
   </div>
 </div>
 </div>

+ 23 - 0
misago/templates/misago/user_state.html

@@ -0,0 +1,23 @@
+{% load i18n misago_capture %}
+{% if state.is_banned %}
+  {% capture trimmed as state_name %}
+  {% if state.banned_until %}
+  {% blocktrans trimmed with ban_date=state.banned_until|date %}
+    Banned until {{ ban_date }}
+  {% endblocktrans %}
+  {% else %}
+  {% trans "Banned" %}
+  {% endif %}
+  {% endcapture %}
+  <span class="fa fa-lock fa-fw tooltip-top user-banned" title="{{ state_name }}"></span>
+{% elif state.is_hidden %}
+  <span class="fa fa-circle-o fa-fw tooltip-top user-offline" title="{% trans "Hides activity" %}"></span>
+{% elif state.is_online_hidden %}
+  <span class="fa fa-circle fa-fw tooltip-top user-online" title="{% trans "Online, hidden" %}"></span>
+{% elif state.is_offline_hidden %}
+  <span class="fa fa-circle-o fa-fw tooltip-top user-offline" title="{% blocktrans with last_seen=state.last_click %}Offline and hidden, last seen {{ last_seen }}{% endblocktrans %}"></span>
+{% elif state.is_online %}
+  <span class="fa fa-circle fa-fw tooltip-top user-online" title="{% trans "Online" %}"></span>
+{% elif state.is_offline %}
+  <span class="fa fa-circle-o fa-fw tooltip-top user-offline" title="{% blocktrans with last_seen=state.last_click %}Offline, last seen {{ last_seen }}{% endblocktrans %}"></span>
+{% endif%}

+ 1 - 0
misago/threads/models/thread.py

@@ -3,6 +3,7 @@ from django.db import models
 from django.dispatch import receiver
 from django.dispatch import receiver
 
 
 from misago.conf import settings
 from misago.conf import settings
+from misago.core.shortcuts import paginate
 from misago.core.utils import slugify
 from misago.core.utils import slugify
 
 
 
 

+ 37 - 1
misago/threads/views/generic/thread.py

@@ -1,6 +1,10 @@
+from django.db.models import Q
 from django.shortcuts import redirect
 from django.shortcuts import redirect
 
 
+from misago.acl import add_acl
+from misago.core.shortcuts import paginate
 from misago.forums.lists import get_forum_path
 from misago.forums.lists import get_forum_path
+from misago.users.online.utils import get_user_state
 
 
 from misago.threads.views.generic.base import ViewBase
 from misago.threads.views.generic.base import ViewBase
 
 
@@ -14,6 +18,33 @@ class ThreadView(ViewBase):
     """
     """
     template = 'misago/thread/replies.html'
     template = 'misago/thread/replies.html'
 
 
+    def get_posts(self, user, forum, thread, kwargs):
+        queryset = self.get_posts_queryset(user, forum, thread)
+        page = paginate(queryset, kwargs.get('page', 0), 10, 5)
+
+        posts = []
+        for post in page.object_list:
+            add_acl(user, post)
+            if post.poster:
+                poster_state = get_user_state(post.poster, user.acl)
+                post.poster.online_state = poster_state
+            posts.append(post)
+
+        return page, posts
+
+    def get_posts_queryset(self, user, forum, thread):
+        queryset = thread.post_set.select_related(
+            'poster', 'poster__rank', 'poster__bancache', 'poster__online')
+
+        if user.is_authenticated():
+            if forum.acl['can_review_moderated_content']:
+                visibility_condition = Q(is_moderated=False) | Q(poster=user)
+                queryset = queryset.filter(visibility_condition)
+        else:
+            queryset = queryset.filter(is_moderated=False)
+
+        return queryset
+
     def dispatch(self, request, *args, **kwargs):
     def dispatch(self, request, *args, **kwargs):
         relations = ['forum', 'starter', 'last_poster', 'first_post']
         relations = ['forum', 'starter', 'last_poster', 'first_post']
         thread = self.fetch_thread(request, select_related=relations, **kwargs)
         thread = self.fetch_thread(request, select_related=relations, **kwargs)
@@ -22,8 +53,13 @@ class ThreadView(ViewBase):
         self.check_forum_permissions(request, forum)
         self.check_forum_permissions(request, forum)
         self.check_thread_permissions(request, thread)
         self.check_thread_permissions(request, thread)
 
 
+        page, posts = self.get_posts(request.user, forum, thread, kwargs)
+
         return self.render(request, {
         return self.render(request, {
             'forum': forum,
             'forum': forum,
             'path': get_forum_path(forum),
             'path': get_forum_path(forum),
-            'thread': thread
+            'thread': thread,
+            'posts': posts,
+            'page': page,
+            'paginator': page.paginator,
         })
         })