add a view to list members
authorFrédéric Péters <fpeters@0d.be>
Sat, 16 May 2020 14:57:45 +0000 (16:57 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sat, 16 May 2020 14:57:45 +0000 (16:57 +0200)
panikdb/aa/models.py
panikdb/aa/views.py
panikdb/templates/aa/user_list.html [new file with mode: 0644]
panikdb/urls.py

index dd65e5a..9b996d0 100644 (file)
@@ -32,8 +32,17 @@ class User(AbstractUser):
             return self.has_perm('emissions.change_newsitem') or object.emission in self.emissions.all()
         return False
 
-    def __unicode__(self):
-        s = super(User, self).__unicode__()
+    def active_emissions(self):
+        return self.emissions.exclude(archived=True)
+
+    def is_ca(self):
+        return self.groups.filter(name='CA').exists()
+
+    def is_cp(self):
+        return self.groups.filter(name='CP').exists()
+
+    def __str__(self):
+        s = super().__str__()
         parts = []
         if self.first_name:
             parts.append(self.first_name)
index 90d8513..6368353 100644 (file)
@@ -1,6 +1,8 @@
 from django.contrib.auth.decorators import login_required
+from django.db.models import Q
 from django.views.generic.base import TemplateView
 from django.views.generic.edit import UpdateView
+from django.views.generic.list import ListView
 from django.core.urlresolvers import reverse_lazy
 
 from .models import User
@@ -23,3 +25,20 @@ class ProfileContactEditView(UpdateView):
 
 
 profile_contact_edit = login_required(ProfileContactEditView.as_view())
+
+
+class MembersListView(ListView):
+    paginate_by = 10
+
+    def get_queryset(self):
+        qs = User.objects.filter(is_active=True)
+        if self.request.GET.get('q'):
+            for part in self.request.GET.get('q').split():
+                part = part.strip()
+                if not part:
+                    continue
+                qs = qs.filter(Q(first_name__icontains=part) | Q(last_name__icontains=part))
+        return qs
+
+
+members_list_view = login_required(MembersListView.as_view())
diff --git a/panikdb/templates/aa/user_list.html b/panikdb/templates/aa/user_list.html
new file mode 100644 (file)
index 0000000..bad3ba3
--- /dev/null
@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block appbar %}
+<h2>{% trans "Members" %}</h2>
+{% endblock %}
+
+{% block content %}
+<div class="section padded">
+<form>
+  <input name="q" type="search" value="{{ request.GET.q }}"> <button>{% trans 'Search' %}</button>
+</form>
+</div>
+
+<table class="main">
+{% for user in object_list %}
+  <tr>
+    <td>{{ user }}</td>
+    <td>{% if user.is_ca %}CA{% endif %}
+        {% if user.is_cp %}CP{% endif %}</td>
+    <td>{{ user.active_emissions|join:", " }}</td>
+    <td>{% if user.share_contact_details and user.email %}<a href="mailto:{{ user.email }}">{{ user.email }}</a>{% endif %}</td>
+    <td>{% if user.share_contact_details %}{{ user.phone|default:"" }} {{ user.mobile|default:"" }}{% endif %}</td>
+  </tr>
+{% endfor %}
+</table>
+
+{% include "gadjo/pagination.html" %}
+
+{% endblock %}
index b87a04b..6c38a98 100644 (file)
@@ -79,6 +79,7 @@ urlpatterns = [
     url(r'^combok/soundfiles/', panikombo.views.soundfiles),
     url(r'^combok/episodes/', panikombo.views.episodes),
 
+    url(r'^members/$', aa_views.members_list_view, name='members-list-view'),
     url(r'^profile/$', aa_views.profile_view, name='profile-view'),
     url(r'^profile/edit/$', aa_views.profile_contact_edit, name='profile-contact-edit'),