Allow filtering talk votes page by tag
authorMagnus Hagander <magnus@hagander.net>
Thu, 10 Jul 2025 09:45:20 +0000 (11:45 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 10 Jul 2025 10:30:22 +0000 (12:30 +0200)
postgresqleu/confreg/views.py
template/confreg/sessionvotes.html

index e7f7a51425667fbd26fa188ce4f17504af1f4b7c..eac66272b6c672d84d51b8d1f3d881a77d0426d2 100644 (file)
@@ -2830,6 +2830,10 @@ def talkvote(request, confname):
     alltracks.insert(0, {'id': 0, 'trackname': 'No track'})
     alltrackids = [t['id'] for t in alltracks]
     selectedtracks = [int(id) for id in request.GET.getlist('tracks') if int(id) in alltrackids]
+    alltags = [{'id': t.id, 'tag': t.tag} for t in ConferenceSessionTag.objects.filter(conference=conference)]
+    alltags.insert(0, {'id': 0, 'tag': 'No tag'})
+    alltagids = [t['id'] for t in alltags]
+    selectedtags = [int(id) for id in request.GET.getlist('tags') if int(id) in alltagids]
     allstatusids = [id for id, status in STATUS_CHOICES]
     selectedstatuses = [int(id) for id in request.GET.getlist('statuses') if int(id) in allstatusids]
     if selectedtracks:
@@ -2838,6 +2842,12 @@ def talkvote(request, confname):
         selectedtracks = alltrackids
         urltrackfilter = ''
 
+    if selectedtags:
+        urltagfilter = "{0}&".format("&".join(["tags={0}".format(t) for t in selectedtags]))
+    else:
+        selectedtags = alltagids
+        urltagfilter = ''
+
     if selectedstatuses:
         urlstatusfilter = "{0}&".format("&".join(["statuses={0}".format(t) for t in selectedstatuses]))
     else:
@@ -2850,6 +2860,13 @@ def talkvote(request, confname):
     else:
         nonvotedquery = ""
 
+    if conference.callforpaperstags:
+        tagsquery = "AND (EXISTS (SELECT 1 FROM confreg_conferencesession_tags cst WHERE cst.conferencesession_id=s.id AND (cst.conferencesessiontag_id=ANY(%(tags)s))) {})".format(
+            'OR NOT EXISTS (SELECT 1 FROM confreg_conferencesession_tags cstt WHERE cstt.conferencesession_id=s.id)' if 0 in selectedtags else '',
+        )
+    else:
+        tagsquery = ""
+
     curs = connection.cursor()
     curs.execute("SELECT username FROM confreg_conference_talkvoters INNER JOIN auth_user ON user_id=auth_user.id WHERE conference_id=%(confid)s ORDER BY 1", {
         'confid': conference.id,
@@ -2927,13 +2944,14 @@ LEFT JOIN LATERAL (
 WHERE s.conference_id=%(confid)s AND
       (COALESCE(s.track_id,0)=ANY(%(tracks)s)) AND
       status=ANY(%(statuses)s)
-      {}
-ORDER BY {}s.title,s.id""".format(nonvotedquery, order), {
+      {} {}
+ORDER BY {}s.title,s.id""".format(nonvotedquery, tagsquery, order), {
         'confid': conference.id,
         'userid': request.user.id,
         'username': request.user.username,
         'tracks': selectedtracks,
         'statuses': selectedstatuses,
+        'tags': selectedtags,
     })
 
     # If the user is only talkvoter at the conference, and not an administrator,
@@ -2958,11 +2976,13 @@ ORDER BY {}s.title,s.id""".format(nonvotedquery, order), {
         'hasvoters': hasvoters,
         'status_choices': STATUS_CHOICES,
         'tracks': alltracks,
+        'tags': alltags,
         'selectedtracks': selectedtracks,
+        'selectedtags': selectedtags,
         'selectedstatuses': selectedstatuses,
         'nonvoted': nonvoted,
         'valid_status_transitions': valid_status_transitions,
-        'urlfilter': urltrackfilter + urlstatusfilter,
+        'urlfilter': urltrackfilter + urlstatusfilter + urltagfilter,
         'helplink': 'callforpapers',
         'options': options,
         'scoring_method': SCORING_METHOD_CHOICES[conference.scoring_method][1],
index f28c2bcf08f466d5bfc035ec78b6454a3d7bffd1..3d3881cff8bbcb234947569a2707cf3adc3f3f00 100644 (file)
@@ -41,6 +41,11 @@ $(function() {
   $('#selectTracks').selectize({
       plugins: ['remove_button'],
   });
+{%if conference.callforpaperstags%}
+  $('#selectTags').selectize({
+      plugins: ['remove_button'],
+  });
+{%endif%}
   $('#selectStatuses').selectize({
       plugins: ['remove_button'],
   });
@@ -221,6 +226,15 @@ ul.comments span.username {
 {%endfor%}
     </select>
   </div>
+{%if conference.callforpaperstags %}
+  <div>
+    <select id="selectTags" name="tags" multiple="multiple" style="inline-block; width=80%;">
+{%for t in tags %}
+      <option value="{{t.id}}"{%if t.id in selectedtags%} SELECTED{%endif%}>{{t.tag}}</option>
+{%endfor%}
+    </select>
+  </div>
+{%endif%}
   <div>
     <select id="selectStatuses" name="statuses" multiple="multiple" style="inline-block; width=80%;">
 {%for sid,s in status_choices %}