diff --git a/accounts/templates/admin/participants.html b/accounts/templates/accounts/participation_list.html similarity index 100% rename from accounts/templates/admin/participants.html rename to accounts/templates/accounts/participation_list.html diff --git a/accounts/urls.py b/accounts/urls.py index 2b78ecd..1e54ed7 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -10,7 +10,7 @@ urlpatterns = [ url(r'^profile/(?P[\w.@+-]+)$', views.edit, name='edit-profile'), url(r'^login/$', auth_views.login, {'extra_context': {'buttons': [views.RESET_PASSWORD_BUTTON]}}, name='login'), url(r'^logout/$', auth_views.logout, {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'), - url(r'^admin/participants/$', views.participants, name='participants'), + url(r'^admin/participants/$', views.ParticipantList.as_view(), name='participants'), url(r'^admin/participant/(?P[\w.@+-]+)$', views.participant, name='show-participation'), url(r'', include('django.contrib.auth.urls')), ] diff --git a/accounts/views.py b/accounts/views.py index a7ac51b..4561fd7 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -2,10 +2,12 @@ from django.contrib import messages from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied from django.shortcuts import get_object_or_404, render +from django.views.generic import ListView from registration.backends.default.views import RegistrationView from .forms import ParticipationForm, ProfileForm, ProfileOrgaForm, UserForm +from .mixins import StaffRequiredMixin from .models import Participation, Profile from .utils import can_edit_profile @@ -36,15 +38,8 @@ def profile(request): return render(request, 'accounts/profile.html', {'forms': forms, 'buttons': [CHANGE_PASSWORD_BUTTON]}) -@login_required -def participants(request): - - if not request.user.is_superuser: - raise PermissionDenied() - - participation_list = Participation.on_site.all() - - return render(request, 'admin/participants.html', {'participation_list': participation_list}) +class ParticipantList(StaffRequiredMixin, ListView): + queryset = Participation.on_site.all() def participant(request, username):