Skip to content
Snippets Groups Projects
Commit d35301d6 authored by Roang's avatar Roang
Browse files

Refactor ConferenceSelectionView

Move it to a separate file and add Docstring
parent f809e1e5
Branches
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ from core.utils import str2timedelta ...@@ -36,7 +36,7 @@ from core.utils import str2timedelta
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class ConferenceForm(forms.Form): class ConferenceSelectionForm(forms.Form):
conference_slug = forms.SlugField() conference_slug = forms.SlugField()
......
...@@ -828,9 +828,12 @@ msgstr "Schedules" ...@@ -828,9 +828,12 @@ msgstr "Schedules"
msgid "nav_workadventure" msgid "nav_workadventure"
msgstr "WorkAdventure" msgstr "WorkAdventure"
msgid "conference_selection" msgid "Conference__Selection"
msgstr "Konferenz auswählen" msgstr "Konferenz auswählen"
msgid "Conferences"
msgstr "Konferenzen"
msgid "nav_profile" msgid "nav_profile"
msgstr "Profil" msgstr "Profil"
......
...@@ -827,9 +827,12 @@ msgstr "Schedules" ...@@ -827,9 +827,12 @@ msgstr "Schedules"
msgid "nav_workadventure" msgid "nav_workadventure"
msgstr "WorkAdventure" msgstr "WorkAdventure"
msgid "conference_selection" msgid "Conference__Selection"
msgstr "Select Conference" msgstr "Select Conference"
msgid "Conferences"
msgstr "Conferences"
msgid "nav_profile" msgid "nav_profile"
msgstr "Profile" msgstr "Profile"
...@@ -1965,3 +1968,8 @@ msgstr "sessions" ...@@ -1965,3 +1968,8 @@ msgstr "sessions"
msgid "wa_textures" msgid "wa_textures"
msgstr "textures" msgstr "textures"
#, fuzzy
#~| msgid "Conference"
#~ msgid "nav_conference"
#~ msgstr "Conference"
...@@ -71,10 +71,10 @@ ...@@ -71,10 +71,10 @@
{% endif %} {% endif %}
</ul> </ul>
<ul class="navbar-nav"> <ul class="navbar-nav">
{% if conferences|length > 1 or active_page == 'conference_selection' %} {% if conferences|length > 1 or active_page == 'conferences' %}
<li class="nav-item{% if active_page == 'conference_selection' %} active{% endif %}"> <li class="nav-item{% if active_page == 'conferences' %} active{% endif %}">
<a class="nav-link" href="{% url 'backoffice:conference_selection' %}" title="{% trans 'conference_selection' %}"> <a class="nav-link" href="{% url 'backoffice:conferences' %}" title="{% trans 'Conference__Selection' %}">
{{ conference.slug }} {% trans 'Conferences' %}
</a> </a>
</li> </li>
{% endif %} {% endif %}
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div class="card-header">{% trans "Conferences__selection__header" %}</div> <div class="card-header">{% trans "Conferences__selection__header" %}</div>
<div class="card-body"> <div class="card-body">
{% if conferences %} {% if conferences %}
<form action="{% url 'backoffice:conference_selection' %}" method="POST"> <form action="{% url 'backoffice:conferences' %}" method="POST">
{% csrf_token %} {% csrf_token %}
<p> <p>
{% trans Conferences__selection__help %} {% trans Conferences__selection__help %}
......
from django.urls import path, re_path from django.urls import path, re_path
from django.views.generic import RedirectView from django.views.generic import RedirectView
from backoffice.views.conferences import ConferenceSelectionView
from backoffice.views.map import ( from backoffice.views.map import (
FloorCreateView, FloorCreateView,
FloorListView, FloorListView,
...@@ -47,7 +48,7 @@ urlpatterns = [ ...@@ -47,7 +48,7 @@ urlpatterns = [
path('login', auth.LoginView.as_view(), name='login'), path('login', auth.LoginView.as_view(), name='login'),
path('logout', auth.LogoutView.as_view(), name='logout'), path('logout', auth.LogoutView.as_view(), name='logout'),
path('auth_debug', auth.AuthDebugView.as_view()), 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', wiki.WikiOverviewView.as_view(), name='wiki'),
path('wiki/namespaces', wiki.NamespaceListView.as_view(), name='wiki-namespaces'), path('wiki/namespaces', wiki.NamespaceListView.as_view(), name='wiki-namespaces'),
path('wiki/locks', wiki.LockListView.as_view(), name='wiki-locks'), path('wiki/locks', wiki.LockListView.as_view(), name='wiki-locks'),
......
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,
}
from django.shortcuts import redirect, render from django.shortcuts import render
from django.views.generic import View 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
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
class IndexView(ConferenceLoginRequiredMixin, View): class IndexView(ConferenceLoginRequiredMixin, View):
...@@ -30,7 +11,7 @@ class IndexView(ConferenceLoginRequiredMixin, View): ...@@ -30,7 +11,7 @@ class IndexView(ConferenceLoginRequiredMixin, View):
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
if self.request.user.is_authenticated: 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 # 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) self.request.session.pop('assembly_back', None)
......
...@@ -80,7 +80,7 @@ class ConferenceRequiredMixin(PermissionRequiredMixin): ...@@ -80,7 +80,7 @@ class ConferenceRequiredMixin(PermissionRequiredMixin):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if self.require_conference and self.conference is None: if self.require_conference and self.conference is None:
return redirect('backoffice:conference_selection') return redirect('backoffice:conferences')
if not self.has_permission(): if not self.has_permission():
raise PermissionDenied('Insufficient privileges.') raise PermissionDenied('Insufficient privileges.')
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment