mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 19:58:25 +02:00
Add some forms
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from member.models import TFJMUser
|
||||
@ -37,3 +38,9 @@ class SignUpForm(UserCreationForm):
|
||||
'responsible_email',
|
||||
'description',
|
||||
)
|
||||
|
||||
|
||||
class TFJMUserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = TFJMUser
|
||||
fields = '__all__'
|
||||
|
@ -1,13 +1,15 @@
|
||||
from django.urls import path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from .views import CreateUserView, ProfileListView, OrphanedProfileListView, OrganizersListView
|
||||
from .views import CreateUserView, MyAccountView, UserDetailView,\
|
||||
ProfileListView, OrphanedProfileListView, OrganizersListView
|
||||
|
||||
app_name = "member"
|
||||
|
||||
urlpatterns = [
|
||||
path('signup/', CreateUserView.as_view(), name="signup"),
|
||||
path("my-account/", RedirectView.as_view(pattern_name="index"), name="my_account"),
|
||||
path("my-account/", MyAccountView.as_view(), name="my_account"),
|
||||
path("information/<int:pk>/", UserDetailView.as_view(), name="information"),
|
||||
path("add-team/", RedirectView.as_view(pattern_name="index"), name="add_team"),
|
||||
path("join-team/", RedirectView.as_view(pattern_name="index"), name="join_team"),
|
||||
path("my-team/", RedirectView.as_view(pattern_name="index"), name="my_team"),
|
||||
|
@ -4,11 +4,11 @@ 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.views.generic import CreateView, UpdateView, DetailView
|
||||
from django_tables2 import SingleTableView
|
||||
|
||||
from tournament.views import AdminMixin
|
||||
from .forms import SignUpForm
|
||||
from .forms import SignUpForm, TFJMUserForm
|
||||
from .models import TFJMUser, Document
|
||||
from .tables import UserTable
|
||||
|
||||
@ -19,6 +19,35 @@ class CreateUserView(CreateView):
|
||||
template_name = "registration/signup.html"
|
||||
|
||||
|
||||
class MyAccountView(LoginRequiredMixin, UpdateView):
|
||||
model = TFJMUser
|
||||
form_class = TFJMUserForm
|
||||
template_name = "member/my_account.html"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.user
|
||||
|
||||
|
||||
class UserDetailView(LoginRequiredMixin, DetailView):
|
||||
model = TFJMUser
|
||||
form_class = TFJMUserForm
|
||||
context_object_name = "user"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.admin \
|
||||
and (self.object.team is not None and request.user not in self.object.team.tournament.organizers)\
|
||||
and self.request.user != self.object:
|
||||
raise PermissionDenied
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context["title"] = str(self.object)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class DocumentView(LoginRequiredMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
doc = Document.objects.get(file=self.kwargs["file"])
|
||||
@ -29,7 +58,7 @@ class DocumentView(LoginRequiredMixin, View):
|
||||
return FileResponse(doc.file, content_type="application/pdf")
|
||||
|
||||
|
||||
class ProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
class ProfileListView(AdminMixin, SingleTableView):
|
||||
model = TFJMUser
|
||||
queryset = TFJMUser.objects.order_by("role", "last_name", "first_name")
|
||||
table_class = UserTable
|
||||
@ -37,7 +66,7 @@ class ProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
extra_context = dict(title=_("All profiles"))
|
||||
|
||||
|
||||
class OrphanedProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
class OrphanedProfileListView(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")
|
||||
@ -46,7 +75,7 @@ class OrphanedProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
extra_context = dict(title=_("Orphaned profiles"))
|
||||
|
||||
|
||||
class OrganizersListView(LoginRequiredMixin, AdminMixin, SingleTableView):
|
||||
class OrganizersListView(AdminMixin, SingleTableView):
|
||||
model = TFJMUser
|
||||
queryset = TFJMUser.objects.filter(Q(role="0admin") | Q(role="1volunteer"))\
|
||||
.order_by("role", "last_name", "first_name")
|
||||
|
Reference in New Issue
Block a user