From ffa741d5665ce5f0f1142f4343e8d65b67b394ef Mon Sep 17 00:00:00 2001
From: Lucas Brandstaetter <lucas@brandstaetter.tech>
Date: Mon, 21 Oct 2024 00:55:16 +0000
Subject: [PATCH] Fix conference selection

* Show a proper message when there are no public conferences
* Use Bootstrap classes for the form
* Use LoginRequiredMixin instead of ConferenceLoginRequiredMixin
  The ConferenceLoginRequiredMixin will error out if no conference
  is available, which is not always the case for the conference selection.
---
 .../locale/de/LC_MESSAGES/django.po           |  6 +++
 .../locale/en/LC_MESSAGES/django.po           |  6 +++
 .../backoffice/conferenceselection.html       | 49 ++++++++++++-------
 src/backoffice/views/misc.py                  |  7 ++-
 4 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/src/backoffice/locale/de/LC_MESSAGES/django.po b/src/backoffice/locale/de/LC_MESSAGES/django.po
index 0dd83442c..11c65a72b 100644
--- a/src/backoffice/locale/de/LC_MESSAGES/django.po
+++ b/src/backoffice/locale/de/LC_MESSAGES/django.po
@@ -849,9 +849,15 @@ msgstr "alle"
 msgid "backoffice__not_a_conference_member"
 msgstr "Das Nutzerkonto, mit dem du gerade angemeldet bist, ist zur Zeit nicht mit einem Veranstaltungsticket verknüpft. Wenn Du gerade beim Aufbau hilfst, ist das kein Problem. Denk aber bitte daran, rechtzeitig ein Ticket zu kaufen und dies kurz vor Veranstaltungsbeginn mit deinem Nutzerkonto zu verknüpfen. Ansonsten kannst Du mit diesem Nutzerkonto nicht an der Veranstaltung teilnehmen."
 
+msgid "Conferences__selection__header"
+msgstr "Konferenz auswählen"
+
 msgid "Conference"
 msgstr "Konferenz"
 
+msgid "Conferences__selection__no_public_conferences"
+msgstr "Zum aktuellen Zeitpunk sind keine öffentlichen Konferenzen verfügbar."
+
 msgid "Event__Assembly_create"
 msgstr "Assembly Veranstaltung erstellen"
 
diff --git a/src/backoffice/locale/en/LC_MESSAGES/django.po b/src/backoffice/locale/en/LC_MESSAGES/django.po
index ad9e12c60..21c3fd49d 100644
--- a/src/backoffice/locale/en/LC_MESSAGES/django.po
+++ b/src/backoffice/locale/en/LC_MESSAGES/django.po
@@ -848,9 +848,15 @@ msgstr "all"
 msgid "backoffice__not_a_conference_member"
 msgstr "The user account you are currently logged in with is not linked to an valid event ticket. If you are helping with the set-up, this is not a problem. But please remember to buy a ticket in time and link it to your user account. Otherwise you will not be able to participate in the event with this user account. Linking the ticket to the user account will be available directly before the event."
 
+msgid "Conferences__selection__header"
+msgstr "Select Conference"
+
 msgid "Conference"
 msgstr "Conference"
 
+msgid "Conferences__selection__no_public_conferences"
+msgstr "No public conferences are currently available."
+
 msgid "Event__Assembly_create"
 msgstr "Create assembly event"
 
diff --git a/src/backoffice/templates/backoffice/conferenceselection.html b/src/backoffice/templates/backoffice/conferenceselection.html
index eeeea3381..9cad9c308 100644
--- a/src/backoffice/templates/backoffice/conferenceselection.html
+++ b/src/backoffice/templates/backoffice/conferenceselection.html
@@ -1,20 +1,35 @@
 {% extends 'backoffice/base.html' %}
 {% load i18n %}
-
 {% block content %}
-
-<form action="{% url 'backoffice:conference_selection' %}" method="POST">
-	{% csrf_token %}
-	<label for="conference">{% trans 'Conference' %}:</label>
-	<select id="conference" name="conference_slug">
-		{% for e in conferences %}
-		<option value="{{ e.slug }}"{% if e == conference %} selected{% endif %}>{{ e.name }}</option>
-		{% endfor %}
-	</select>
-
-	<input type="submit">
-
-	{{ form.errors }}
-</form>
-
-{% endblock %}
\ No newline at end of file
+  <div class="row">
+    <div class="col-md-12">
+      <div class="card mb-3">
+        <div class="card-header">{% trans "Conferences__selection__header" %}</div>
+        <div class="card-body">
+          {% if conferences %}
+            <form action="{% url 'backoffice:conference_selection' %}" method="POST">
+              {% csrf_token %}
+              <p>
+                {% trans Conferences__selection__help%}
+              </p>
+              <div class="mb-3">
+                <label class="form-label" for="conference">{% trans 'Conference' %}:</label>
+                <select class="form-select" id="conference" name="conference_slug">
+                  {% for e in conferences %}
+                    <option value="{{ e.slug }}"{% if e == conference %} selected{% endif %}>{{ e.name }}</option>
+                  {% endfor %}
+                </select>
+                {{ form.errors }}
+              </div>
+              <button type="submit" class="btn btn-primary">Submit</button>
+            </form>
+          {% else %}
+            <div class="alert alert-danger card-body border border-3">
+              {% trans "Conferences__selection__no_public_conferences" %}
+            </div>
+          {% endif %}
+        </div>
+      </div>
+    </div>
+  </div>
+{% endblock content %}
diff --git a/src/backoffice/views/misc.py b/src/backoffice/views/misc.py
index 3ccbe69d9..0728cf718 100644
--- a/src/backoffice/views/misc.py
+++ b/src/backoffice/views/misc.py
@@ -5,10 +5,10 @@ from django.views.generic.edit import FormView
 from core.models import Assembly, Conference
 
 from backoffice.forms import ConferenceForm
-from backoffice.views.mixins import ConferenceLoginRequiredMixin
+from backoffice.views.mixins import ConferenceLoginRequiredMixin, LoginRequiredMixin
 
 
-class ConferenceSelectionView(ConferenceLoginRequiredMixin, FormView):
+class ConferenceSelectionView(LoginRequiredMixin, FormView):
     form_class = ConferenceForm
     template_name = 'backoffice/conferenceselection.html'
 
@@ -20,11 +20,14 @@ class ConferenceSelectionView(ConferenceLoginRequiredMixin, FormView):
 
     def get_context_data(self, *args, **kwargs):
         ctx = super().get_context_data(*args, **kwargs)
+        ctx['conferences'] = Conference.objects.accessible_by_user(self.request.user)
         ctx['active_page'] = 'conference_selection'
         return ctx
 
 
 class IndexView(ConferenceLoginRequiredMixin, View):
+    require_conference = True
+
     def get(self, *args, **kwargs):
         if self.request.user.is_authenticated:
             myassemblies = list(Assembly.objects.associated_to_user(conference=self.conference, user=self.request.user))
-- 
GitLab