← Back to team overview

widelands-dev team mailing list archive

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

 

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

Commit message:
Fix showing username in search results if user has deleted himself

Requested reviews:
  Widelands Developers (widelands-dev)

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

Just stumbled over this during cleaning of users who had registered but never activated their account. So there are some more small changes:

- in admin/auth/user show if a user has deleted himself. So one can distinguish between inactive users and users who deleted them self (which are also inactive)
- show the deleted status also in admin/wlprofile
- added a new template filter 'user_status', which is used to either show DELETED_USERNAME or the real username. This makes some templates easier to use.
- this filter makes the context_processor in wlprofile superfluous
- use the filter in search results and other places
- fixed displaying smiley in delete_me page
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/deleted_user2 into lp:widelands-website.
=== modified file 'mainpage/admin.py'
--- mainpage/admin.py	2018-12-11 10:22:21 +0000
+++ mainpage/admin.py	2019-01-18 12:08:44 +0000
@@ -36,6 +36,11 @@
 persons.allow_tags = True
 
 
+def deleted(self):
+    return '' if self.wlprofile.deleted==False else 'Yes'
+deleted.short_description = u'Deleted himself'
+
+
 class GroupAdmin(GroupAdmin):
     list_display = ['name', persons]
     list_display_links = ['name']
@@ -47,7 +52,7 @@
 
 class UserAdmin(UserAdmin):
     list_display = ('username', 'email', 'date_joined', 'last_login',
-                    'is_active', 'is_staff', roles)
+                    'is_active', deleted, 'is_staff', roles)
     ordering = ('-date_joined',)
 
 

=== modified file 'settings.py'
--- settings.py	2018-12-18 11:38:34 +0000
+++ settings.py	2019-01-18 12:08:44 +0000
@@ -151,7 +151,6 @@
                 'django.template.context_processors.static',
                 'django.template.context_processors.tz',
                 'django_messages.context_processors.inbox',
-                'wlprofile.context_processors.deleted_user_data',
             ],
         },
     },

=== modified file 'templates/pybb/feeds/posts_description.html'
--- templates/pybb/feeds/posts_description.html	2018-09-13 20:19:07 +0000
+++ templates/pybb/feeds/posts_description.html	2019-01-18 12:08:44 +0000
@@ -1,6 +1,3 @@
-{% if obj.user.wlprofile.deleted %}
-    {{ DELETED_USERNAME }}
-{% else %}
-    {{ obj.user }}
-{% endif %}wrote:<br>
+{% load wlprofile_extras %}
+{{ obj.user|user_status }} wrote:<br>
 {{ obj.body_html|safe }}

=== modified file 'templates/pybb/feeds/topics_description.html'
--- templates/pybb/feeds/topics_description.html	2018-09-13 20:19:07 +0000
+++ templates/pybb/feeds/topics_description.html	2019-01-18 12:08:44 +0000
@@ -1,6 +1,3 @@
-{% if obj.head.user.wlprofile.deleted %}
-    {{ DELETED_USERNAME }}
-{% else %}
-    {{ obj.head.user }}
-{% endif %}wrote:<br>
+{% load wlprofile_extras %}
+{{ obj.head.user|user_status }} wrote:<br>
 {{ obj.head.body_html|safe }}

=== modified file 'templates/search/includes/posts.html'
--- templates/search/includes/posts.html	2017-09-17 15:52:45 +0000
+++ templates/search/includes/posts.html	2019-01-18 12:08:44 +0000
@@ -1,7 +1,8 @@
 {% load highlight %}
 {% load custom_date %}
+{% load wlprofile_extras %}
 
-<a href=" {{ post.post_link }}">Post by {{ post.user }}</a><span class="small"> @ </span>
+<a href=" {{ post.post_link }}">Post by {{ post.user|user_status }}</a><span class="small"> @ </span>
  Topic <a href="{{ post.object.topic.get_absolute_url }}">{{ post.object.topic }}</a><span class="small"> @ </span>
  Forum <a href="{{ post.object.topic.forum.get_absolute_url }}">{{ post.object.topic.forum }}</a>,
  {{ post.date|custom_date:user }}<br>

=== modified file 'templates/search/includes/topics.html'
--- templates/search/includes/topics.html	2017-09-17 15:52:45 +0000
+++ templates/search/includes/topics.html	2019-01-18 12:08:44 +0000
@@ -1,6 +1,7 @@
 {% load custom_date %}
+{% load wlprofile_extras %}
 
     <a href=" {{ topic.topic_link }}">{{ topic.name }}</a><span class="small"> @ </span> 
     Forum <a href="{{ topic.object.forum.get_absolute_url }}">{{ topic.object.forum }}</a>
-    by {{topic.user}},
+    by {{topic.user|user_status}},
     {{topic.date|custom_date:user}}

=== modified file 'templates/search/search.html'
--- templates/search/search.html	2018-11-22 11:08:51 +0000
+++ templates/search/search.html	2019-01-18 12:08:44 +0000
@@ -24,6 +24,7 @@
             will find all forum posts containing 'tribe' but exclude all forum posts containing 'barbarian'.</li>
             <li>The start date won't be considered when searching the encyclopedia, maps or the wiki.
             The default is set to return results for the span of one year.</li>
+            <li>{{ sql_queries }}</li>
         </ul>
     <form method="get" action=".">
       {{ form.non_field_errors }}

=== modified file 'templates/wiki/feeds/history_description.html'
--- templates/wiki/feeds/history_description.html	2018-09-13 20:19:07 +0000
+++ templates/wiki/feeds/history_description.html	2019-01-18 12:08:44 +0000
@@ -1,9 +1,6 @@
 {% load i18n %}
+{% load wlprofile_extras %}
 
-{% trans "Edited by user" %} {% if obj.editor.wlprofile.deleted %}
-        {{ DELETED_USERNAME }}
-    {% else %}
-        {{ obj.editor.username }}
-    {% endif %}
+{% trans "Edited by user" %} {{ obj.editor.username|user_status }}
     {% trans "at"%} {{ obj.modified }}<br>
 {{ obj.comment }}

=== modified file 'templates/wlprofile/delete_me.html'
--- templates/wlprofile/delete_me.html	2018-10-14 13:24:15 +0000
+++ templates/wlprofile/delete_me.html	2019-01-18 12:08:44 +0000
@@ -2,6 +2,7 @@
 
 {% load i18n %}
 {% load wlprofile_extras %}
+{% load static %}
 
 {% block title %}
 {% trans "Delete me" %} - {{ block.super }}
@@ -13,7 +14,7 @@
 {% block content_main %}
 <div class="blogEntry">
 	<h3>Hi {{ user }},</h3>
-	<p>we are sorry that you want to leave our community <img src="/wlmedia/img/smileys/face-sad.png" alt="Sad smiley"></p>
+	<p>we are sorry that you want to leave our community <img src="{% static 'img/smileys/face-sad.png' %}" alt="Sad smiley"></p>
 	<h3>What deleting yourself means:</h3>
 	<ul>
 		<li>Your account will be deactivated. This means:
@@ -30,7 +31,7 @@
 		<li>Your email address will be removed, so you will not receive any notification mails anymore.</li>
 		<li>
 			<b>Nothing</b> that you have posted (forum posts, comments and uploaded maps) will be deleted.
-			Instead of your user name, the string "{{ DELETED_USERNAME }}" will be shown.</li>
+			Instead of your user name, the string "{{ deleted_name }}" will be shown.</li>
 		<li>Your online gaming password will be reset.</li>
 		<li>All dates given in the <a href="{% url 'scheduling_scheduling' %}">Playtime scheduler</a> will be deleted</li>
 	</ul>

=== modified file 'wlprofile/admin.py'
--- wlprofile/admin.py	2018-12-11 10:22:21 +0000
+++ wlprofile/admin.py	2019-01-18 12:08:44 +0000
@@ -17,7 +17,7 @@
 
 
 class ProfileAdmin(admin.ModelAdmin):
-    list_display = ['user', 'time_zone', 'location']
+    list_display = ['user', 'time_zone', 'location', 'deleted']
     list_per_page = 20
     ordering = ['-user']
     search_fields = ['user__username', 'user__first_name', 'user__last_name']

=== removed file 'wlprofile/context_processors.py'
--- wlprofile/context_processors.py	2018-09-13 20:19:07 +0000
+++ wlprofile/context_processors.py	1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
-from django.conf import settings
-
-
-def deleted_user_data(request):
-    context = {'DELETED_USERNAME': settings.DELETED_USERNAME}
-    return context

=== modified file 'wlprofile/templatetags/wlprofile_extras.py'
--- wlprofile/templatetags/wlprofile_extras.py	2018-09-14 07:01:22 +0000
+++ wlprofile/templatetags/wlprofile_extras.py	2019-01-18 12:08:44 +0000
@@ -14,6 +14,8 @@
 from django.utils.safestring import mark_safe
 from django.contrib.auth.models import User
 from django.conf import settings
+from django.contrib.auth.models import User
+from django.shortcuts import get_object_or_404
 
 register = template.Library()
 
@@ -28,3 +30,22 @@
         data = u'<a href="%s">%s</a>' % (
             reverse('profile_view', args=[user.username]), user.username)
     return mark_safe(data)
+
+
+@register.filter
+def user_status(user):
+    """Check if user has deleted himself.
+
+    When using the search, the user is just a string, so we need to get
+    the userobject.
+    """
+
+    if not isinstance(user, User):
+        user_obj = get_object_or_404(User, username=user)
+    else:
+        user_obj = user
+
+    if user_obj.wlprofile.deleted:
+        return settings.DELETED_USERNAME
+
+    return user

=== modified file 'wlprofile/views.py'
--- wlprofile/views.py	2018-09-14 06:42:53 +0000
+++ wlprofile/views.py	2019-01-18 12:08:44 +0000
@@ -17,7 +17,8 @@
     """Show a page to inform the user what deleting means."""
 
     context = {
-        'user': request.user
+        'user': request.user,
+        'deleted_name': settings.DELETED_USERNAME,
     }
     return render(request, 'wlprofile/delete_me.html',
                   context)


Follow ups