User list sorted by last activity.
authorRadek Czajka <rczajka@rczajka.pl>
Sat, 11 Dec 2021 12:29:13 +0000 (13:29 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Sat, 11 Dec 2021 12:29:13 +0000 (13:29 +0100)
src/documents/templates/documents/book_list/book_list.html
src/documents/templatetags/book_list.py
src/redakcja/static/js/documents/book_list.js

index eb4c8f5..812ea79 100644 (file)
           {% endif %}value="{{ user.username }}">{{ user|username }} ({{ user.count }})</option>
   {% endfor %}
 </select>
+
+<select name="active-users" style="display:none;">
+  {% for user in active_users %}
+  <option value="{{ user.username }}">{{ user|username }}</option>
+  {% endfor %}
+</select>
index acd2208..bf5fbd0 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from re import split
-from django.db.models import Q, Count
+from django.db.models import Q, Count, F, Max
 from django import template
 from django.utils.translation import ugettext_lazy as _
 from django.contrib.auth.models import User
@@ -127,9 +127,9 @@ def book_list(context, user=None):
                 count=Count('chunk')).filter(count__gt=0).order_by(
                 '-count', 'last_name', 'first_name'),
             "other_users": User.objects.annotate(
-                count=Count('chunk')).filter(count=0).order_by(
-                'last_name', 'first_name'),
-                }
+                count=Count('chunk')).filter(count=0).annotate(m=Max('chunkchange__created_at')).order_by(F('m').desc(nulls_last=True), 'last_name', 'first_name'),
+            "active_users": User.objects.annotate(m=Max('chunkchange__created_at')).order_by(F('m').desc(nulls_last=True), 'last_name', 'first_name'),
+        }
 
     new_context.update({
         "filters": True,
index 9d2511d..0f03f4a 100644 (file)
@@ -50,9 +50,7 @@
 
     var user_callback = get_callback('user');
     var users = [
-        get_items("user", user_callback),
-        {sep: '----'},
-        get_items("other-user", user_callback)
+        get_items("active-users", user_callback)
     ];
     var current_user_items = user_items = {};
     var i = 0;