← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands-website/show_user_posts into lp:widelands-website

 

kaputtnik has proposed merging lp:~widelands-dev/widelands-website/show_user_posts into lp:widelands-website.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1825707 in Widelands Website: "Move topic to different forum"
  https://bugs.launchpad.net/widelands-website/+bug/1825707

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/show_user_posts/+merge/367237

Add link and view to show all posts of a particular user.

The link is made from the posts count in the user profile. The view contains all posts of the user, sorted by date.

Example image: https://bugs.launchpad.net/widelands-website/+bug/1825707/+attachment/5262041/+files/all_users_post.jpg
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/show_user_posts into lp:widelands-website.
=== added file 'pybb/templates/pybb/all_user_posts.html'
--- pybb/templates/pybb/all_user_posts.html	1970-01-01 00:00:00 +0000
+++ pybb/templates/pybb/all_user_posts.html	2019-05-10 06:18:26 +0000
@@ -0,0 +1,38 @@
+{% extends 'pybb/base.html' %}
+{% load custom_date %}
+{% load pagination_tags %}
+{% block title %}
+    Posts by {{ this_user }}- {{ block.super }}
+{% endblock title %}
+
+{% block content_header %}
+    <h1>Posts by {{ this_user }}</h1>
+{% endblock %}
+
+{% block content_main %}
+<div class="blogEntry">
+<p>{{ this_user }} had {{posts|length}} post{{posts|length|pluralize}} written.</p>
+{% autopaginate posts 30 %}
+{% paginate %}
+<table class='forum'>
+  <thead>
+    <tr>
+      <th style="text-align: left; width: 12em;">Date</th>
+      <th style="text-align: left; width: 10%;">Forum</th>
+      <th style="text-align: left; width: 20%;">Topic</th>
+      <th style="text-align: left;">Post{{posts|length|pluralize}}</th>
+    </tr>
+  </thead>
+  <tbody>
+    {% for post in posts %}
+    <tr class="{% cycle 'odd' 'even' %}">
+      <td class='post'>{{ post.created|custom_date:user }}</td>
+      <td class='post'><a href="{% url 'pybb_topic' post.topic.id %}">{{ post.topic.forum }}</a></td>
+      <td class='post'><a href="{% url 'pybb_forum' post.topic.forum.id %}">{{ post.topic }}</a></td>
+      <td class='post'><a href="{{post.get_absolute_url}}">"{{ post.body_text|truncatechars:80}}"</a></td>
+    </tr>
+    {% endfor %}
+  </tbody>
+</table>
+</div>
+{% endblock %}

=== modified file 'pybb/urls.py'
--- pybb/urls.py	2019-03-16 20:10:31 +0000
+++ pybb/urls.py	2019-05-10 06:18:26 +0000
@@ -41,6 +41,7 @@
     url('^post/(?P<post_id>\d+)/delete/$',
         views.delete_post, name='pybb_delete_post'),
     url(r'^latest_posts/$', views.all_latest, name='all_latest_posts'),
+    url(r'^user_posts/(?P<this_user>\w+)/$', views.user_posts, name='all_user_posts'),
 
     # Attachment
     url('^attachment/(?P<hash>\w+)/$',

=== modified file 'pybb/views.py'
--- pybb/views.py	2019-03-23 09:00:44 +0000
+++ pybb/views.py	2019-05-10 06:18:26 +0000
@@ -474,5 +474,20 @@
         'sort_by': sort_by
     }
 
-
 all_latest = render_to('pybb/all_last_posts.html')(all_latest_posts)
+
+@login_required
+def all_user_posts(request, this_user=None):
+    """Get all posts of a user"""
+
+    if this_user:
+        posts = Post.objects.public().filter(user__username=this_user)
+    else:
+        posts = Post.objects.public().filter(user__username=request.user)
+
+    return {
+        'this_user': this_user,
+        'posts': posts,
+        }
+
+user_posts = render_to('pybb/all_user_posts.html')(all_user_posts)

=== modified file 'wlprofile/models.py'
--- wlprofile/models.py	2019-03-31 11:08:21 +0000
+++ wlprofile/models.py	2019-05-10 06:18:26 +0000
@@ -62,7 +62,7 @@
         to not be always calculated.
 
         """
-        return Post.objects.filter(user=self.user).count()
+        return Post.objects.public().filter(user=self.user).count()
 
     def user_status(self):
         nump = self.post_count()

=== modified file 'wlprofile/templates/wlprofile/view_profile.html'
--- wlprofile/templates/wlprofile/view_profile.html	2018-10-09 19:52:50 +0000
+++ wlprofile/templates/wlprofile/view_profile.html	2019-05-10 06:18:26 +0000
@@ -45,7 +45,7 @@
 			</tr>
 			<tr>
 				<td class="grey">Forum Posts:</td>
-				<td>{{ profile.post_count }}</td>
+				<td><a href="{% url 'all_user_posts' profile.user %}" title="Show all posts">{{ profile.post_count }}</a></td>
 			</tr>
 			<tr>
 				<td class="grey">Website:</td>


Follow ups