mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 03:18:27 +02:00
Profile list
This commit is contained in:
@ -127,10 +127,10 @@ class TFJMUser(AbstractUser):
|
||||
role = models.CharField(
|
||||
max_length=16,
|
||||
choices=[
|
||||
("0admin", _("admin")),
|
||||
("1volunteer", _("organizer")),
|
||||
("2coach", _("coach")),
|
||||
("3participant", _("participant")),
|
||||
("0admin", _("Admin")),
|
||||
("1volunteer", _("Organizer")),
|
||||
("2coach", _("Coach")),
|
||||
("3participant", _("Participant")),
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -6,4 +6,7 @@ from member.models import TFJMUser
|
||||
class UserTable(tables.Table):
|
||||
class Meta:
|
||||
model = TFJMUser
|
||||
fields = ("last_name", "first_name", "role",)
|
||||
fields = ("last_name", "first_name", "role", "date_joined", )
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped table-hover'
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
from django.urls import path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from .views import CreateUserView, DocumentView
|
||||
from .views import CreateUserView, ProfileListView, OrphanedProfileListView, OrganizersListView
|
||||
|
||||
app_name = "member"
|
||||
|
||||
@ -12,7 +12,7 @@ urlpatterns = [
|
||||
path("join-team/", RedirectView.as_view(pattern_name="index"), name="join_team"),
|
||||
path("my-team/", RedirectView.as_view(pattern_name="index"), name="my_team"),
|
||||
path("my-team/update/", RedirectView.as_view(pattern_name="index"), name="update_my_team"),
|
||||
path("profiles/", RedirectView.as_view(pattern_name="index"), name="all_profiles"),
|
||||
path("orphaned-profiles/", RedirectView.as_view(pattern_name="index"), name="orphaned_profiles"),
|
||||
path("organizers/", RedirectView.as_view(pattern_name="index"), name="organizers"),
|
||||
path("profiles/", ProfileListView.as_view(), name="all_profiles"),
|
||||
path("orphaned-profiles/", OrphanedProfileListView.as_view(), name="orphaned_profiles"),
|
||||
path("organizers/", OrganizersListView.as_view(), name="organizers"),
|
||||
]
|
||||
|
@ -1,11 +1,16 @@
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db.models import Q
|
||||
from django.http import FileResponse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
from django.views.generic import CreateView
|
||||
from django_tables2 import SingleTableView
|
||||
|
||||
from tournament.views import AdminMixin
|
||||
from .forms import SignUpForm
|
||||
from .models import TFJMUser, Document
|
||||
from .tables import UserTable
|
||||
|
||||
|
||||
class CreateUserView(CreateView):
|
||||
@ -22,3 +27,29 @@ class DocumentView(LoginRequiredMixin, View):
|
||||
raise PermissionDenied
|
||||
|
||||
return FileResponse(doc.file, content_type="application/pdf")
|
||||
|
||||
|
||||
class ProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
model = TFJMUser
|
||||
queryset = TFJMUser.objects.order_by("role", "last_name", "first_name")
|
||||
table_class = UserTable
|
||||
template_name = "member/profile_list.html"
|
||||
extra_context = dict(title=_("All profiles"))
|
||||
|
||||
|
||||
class OrphanedProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
model = TFJMUser
|
||||
queryset = TFJMUser.objects.filter((Q(role="2coach") | Q(role="3participant")) & Q(team__isnull=True))\
|
||||
.order_by("role", "last_name", "first_name")
|
||||
table_class = UserTable
|
||||
template_name = "member/profile_list.html"
|
||||
extra_context = dict(title=_("Orphaned profiles"))
|
||||
|
||||
|
||||
class OrganizersListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
model = TFJMUser
|
||||
queryset = TFJMUser.objects.filter(Q(role="0admin") | Q(role="1volunteer"))\
|
||||
.order_by("role", "last_name", "first_name")
|
||||
table_class = UserTable
|
||||
template_name = "member/profile_list.html"
|
||||
extra_context = dict(title=_("Organizers"))
|
||||
|
@ -74,6 +74,32 @@ class TournamentDetailView(DetailView):
|
||||
class TeamDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Team
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.admin and self.request.user not in self.get_object().tournament.organizers:
|
||||
raise PermissionDenied
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
team = self.get_object()
|
||||
if "zip" in request.POST:
|
||||
solutions = team.solutions.all()
|
||||
|
||||
out = BytesIO()
|
||||
zf = zipfile.ZipFile(out, "w")
|
||||
|
||||
for solution in solutions:
|
||||
zf.write(solution.file.path, str(solution) + ".pdf")
|
||||
|
||||
zf.close()
|
||||
|
||||
resp = HttpResponse(out.getvalue(), content_type="application/x-zip-compressed")
|
||||
resp['Content-Disposition'] = 'attachment; filename={}'\
|
||||
.format(_("Solutions for team {team}.zip")
|
||||
.format(team=str(team)).replace(" ", "%20"))
|
||||
return resp
|
||||
|
||||
return self.get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
|
Reference in New Issue
Block a user