diff --git a/src/backoffice/forms.py b/src/backoffice/forms.py index 70c60d5d6d321bd4c94f01d6a01820faee16d9c5..e4482cf688867b6917aceded0a62c0e0b0ee4599 100644 --- a/src/backoffice/forms.py +++ b/src/backoffice/forms.py @@ -36,7 +36,7 @@ from core.utils import str2timedelta logger = logging.getLogger(__name__) -class ConferenceForm(forms.Form): +class ConferenceSelectionForm(forms.Form): conference_slug = forms.SlugField() diff --git a/src/backoffice/locale/de/LC_MESSAGES/django.po b/src/backoffice/locale/de/LC_MESSAGES/django.po index 11c65a72bf3f769a6f4e0b96579b011061be6843..3624aaca34315cc12db64c588cff90bdd0b981ac 100644 --- a/src/backoffice/locale/de/LC_MESSAGES/django.po +++ b/src/backoffice/locale/de/LC_MESSAGES/django.po @@ -828,9 +828,12 @@ msgstr "Schedules" msgid "nav_workadventure" msgstr "WorkAdventure" -msgid "conference_selection" +msgid "Conference__Selection" msgstr "Konferenz auswählen" +msgid "Conferences" +msgstr "Konferenzen" + msgid "nav_profile" msgstr "Profil" diff --git a/src/backoffice/locale/en/LC_MESSAGES/django.po b/src/backoffice/locale/en/LC_MESSAGES/django.po index 21c3fd49ddfc124b0d70be94acd4faace58bae4c..1ce5dc96d2dbe033cadd85f826756d61044dcbc1 100644 --- a/src/backoffice/locale/en/LC_MESSAGES/django.po +++ b/src/backoffice/locale/en/LC_MESSAGES/django.po @@ -827,9 +827,12 @@ msgstr "Schedules" msgid "nav_workadventure" msgstr "WorkAdventure" -msgid "conference_selection" +msgid "Conference__Selection" msgstr "Select Conference" +msgid "Conferences" +msgstr "Conferences" + msgid "nav_profile" msgstr "Profile" @@ -1965,3 +1968,8 @@ msgstr "sessions" msgid "wa_textures" msgstr "textures" + +#, fuzzy +#~| msgid "Conference" +#~ msgid "nav_conference" +#~ msgstr "Conference" diff --git a/src/backoffice/templates/backoffice/base.html b/src/backoffice/templates/backoffice/base.html index 20517eae6134b4aba2e45363d99adb33c7f69c65..71b80a48ece412d4546d89cc5342863012f1bad6 100644 --- a/src/backoffice/templates/backoffice/base.html +++ b/src/backoffice/templates/backoffice/base.html @@ -71,10 +71,10 @@ {% endif %} </ul> <ul class="navbar-nav"> - {% if conferences|length > 1 or active_page == 'conference_selection' %} - <li class="nav-item{% if active_page == 'conference_selection' %} active{% endif %}"> - <a class="nav-link" href="{% url 'backoffice:conference_selection' %}" title="{% trans 'conference_selection' %}"> - {{ conference.slug }} + {% if conferences|length > 1 or active_page == 'conferences' %} + <li class="nav-item{% if active_page == 'conferences' %} active{% endif %}"> + <a class="nav-link" href="{% url 'backoffice:conferences' %}" title="{% trans 'Conference__Selection' %}"> + {% trans 'Conferences' %} </a> </li> {% endif %} diff --git a/src/backoffice/templates/backoffice/conferenceselection.html b/src/backoffice/templates/backoffice/conferences/selection.html similarity index 89% rename from src/backoffice/templates/backoffice/conferenceselection.html rename to src/backoffice/templates/backoffice/conferences/selection.html index 9cad9c308c6742562bc43eea0263039b65fdb25b..7ded69a53c29e49c6f777e9303393c1a7e4039fe 100644 --- a/src/backoffice/templates/backoffice/conferenceselection.html +++ b/src/backoffice/templates/backoffice/conferences/selection.html @@ -7,10 +7,10 @@ <div class="card-header">{% trans "Conferences__selection__header" %}</div> <div class="card-body"> {% if conferences %} - <form action="{% url 'backoffice:conference_selection' %}" method="POST"> + <form action="{% url 'backoffice:conferences' %}" method="POST"> {% csrf_token %} <p> - {% trans Conferences__selection__help%} + {% trans Conferences__selection__help %} </p> <div class="mb-3"> <label class="form-label" for="conference">{% trans 'Conference' %}:</label> diff --git a/src/backoffice/urls.py b/src/backoffice/urls.py index 6931b8b45b50914fa3098b95e62e79e1bb2a060a..748dfa12c6191b0d7527377d21f97450c31732da 100644 --- a/src/backoffice/urls.py +++ b/src/backoffice/urls.py @@ -1,6 +1,7 @@ from django.urls import path, re_path from django.views.generic import RedirectView +from backoffice.views.conferences import ConferenceSelectionView from backoffice.views.map import ( FloorCreateView, FloorListView, @@ -47,7 +48,7 @@ urlpatterns = [ path('login', auth.LoginView.as_view(), name='login'), path('logout', auth.LogoutView.as_view(), name='logout'), path('auth_debug', auth.AuthDebugView.as_view()), - path('conferences', misc.ConferenceSelectionView.as_view(), name='conference_selection'), + path('conferences', ConferenceSelectionView.as_view(), name='conferences'), path('wiki', wiki.WikiOverviewView.as_view(), name='wiki'), path('wiki/namespaces', wiki.NamespaceListView.as_view(), name='wiki-namespaces'), path('wiki/locks', wiki.LockListView.as_view(), name='wiki-locks'), diff --git a/src/backoffice/views/conferences.py b/src/backoffice/views/conferences.py new file mode 100644 index 0000000000000000000000000000000000000000..facd80268f81f0893e674b77e2c10595365dcb5d --- /dev/null +++ b/src/backoffice/views/conferences.py @@ -0,0 +1,50 @@ +from django.shortcuts import redirect +from django.views.generic.edit import FormView + +from core.models import Conference + +from backoffice.forms import ConferenceSelectionForm +from backoffice.views.mixins import LoginRequiredMixin + + +class ConferenceSelectionView(LoginRequiredMixin, FormView): + """ + A class-based view that will let you select the current :model:`core.Conference` for you session. + + It will also be used if no conference is available and show an error message to the user. + + **Context:** + + ``conferences`` + A list of all available :model:`core.Conference` for the current user. + + **Template:** + + :template:`backoffice/conferences/selection.html` + + """ + + form_class = ConferenceSelectionForm + template_name = 'backoffice/conferences/selection.html' + active_page = 'conferences' + + def form_valid(self, form: ConferenceSelectionForm): + """Sets the selected conference for the session if the form is valid. + + Args: + form (ConferenceForm): A form containing the selected conference + + Returns: + Response: A redirection to the backoffice index + """ + conf_slug = form.cleaned_data['conference_slug'] + conference = Conference.objects.accessible_by_user(self.request.user).get(slug=conf_slug) + self.request.session['conference'] = conference.slug + return redirect('backoffice:index') + + def get_context_data(self, *args, **kwargs): + return { + **super().get_context_data(*args, **kwargs), + 'conferences': Conference.objects.accessible_by_user(self.request.user), + 'active_page': self.active_page, + } diff --git a/src/backoffice/views/misc.py b/src/backoffice/views/misc.py index 0728cf71834a9a4398eb0b6cf63f549954c50a85..5ca163188ee66c104287513eea2a3ef95f8b0a8d 100644 --- a/src/backoffice/views/misc.py +++ b/src/backoffice/views/misc.py @@ -1,28 +1,9 @@ -from django.shortcuts import redirect, render +from django.shortcuts import render from django.views.generic import View -from django.views.generic.edit import FormView -from core.models import Assembly, Conference +from core.models.assemblies import Assembly -from backoffice.forms import ConferenceForm -from backoffice.views.mixins import ConferenceLoginRequiredMixin, LoginRequiredMixin - - -class ConferenceSelectionView(LoginRequiredMixin, FormView): - form_class = ConferenceForm - template_name = 'backoffice/conferenceselection.html' - - def form_valid(self, form): - conf_slug = form.cleaned_data['conference_slug'] - conference = Conference.objects.accessible_by_user(self.request.user).get(slug=conf_slug) - self.request.session['conference'] = conference.slug - return redirect('backoffice:index') - - 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 +from backoffice.views.mixins import ConferenceLoginRequiredMixin class IndexView(ConferenceLoginRequiredMixin, View): @@ -30,7 +11,7 @@ class IndexView(ConferenceLoginRequiredMixin, View): 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)) + myassemblies = list(Assembly.objects.associated_with_user(conference=self.conference, user=self.request.user)) # remove stored backlink for assembly pages from the session if it is set, so the backlink will go to the overview, which is the default self.request.session.pop('assembly_back', None) diff --git a/src/backoffice/views/mixins.py b/src/backoffice/views/mixins.py index b47660a1d6a07c65f62a5f21ad5e198d2d696abc..a56853bd8bd0795fed5968c135e269be511cce57 100644 --- a/src/backoffice/views/mixins.py +++ b/src/backoffice/views/mixins.py @@ -80,7 +80,7 @@ class ConferenceRequiredMixin(PermissionRequiredMixin): def dispatch(self, request, *args, **kwargs): if self.require_conference and self.conference is None: - return redirect('backoffice:conference_selection') + return redirect('backoffice:conferences') if not self.has_permission(): raise PermissionDenied('Insufficient privileges.') return super().dispatch(request, *args, **kwargs)