mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-23 19:56:39 +02:00
Add comments and linting
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -718,6 +718,9 @@ class PoolUpdateTeamsView(VolunteerMixin, UpdateView):
|
||||
|
||||
|
||||
class PoolAddJurysView(VolunteerMixin, FormView, DetailView):
|
||||
"""
|
||||
This view lets organizers set jurys for a pool, without multiplying clicks.
|
||||
"""
|
||||
model = Pool
|
||||
form_class = AddJuryForm
|
||||
template_name = 'participation/pool_add_jurys.html'
|
||||
@ -731,21 +734,26 @@ class PoolAddJurysView(VolunteerMixin, FormView, DetailView):
|
||||
def form_valid(self, form):
|
||||
self.object = self.get_object()
|
||||
|
||||
# Save the user object first
|
||||
form.save()
|
||||
user = form.instance
|
||||
# Create associated registration object to the new user
|
||||
reg = VolunteerRegistration.objects.create(
|
||||
user=user,
|
||||
professional_activity="Juré⋅e du tournoi " + self.object.tournament.name,
|
||||
)
|
||||
# Add the user in the jury
|
||||
self.object.juries.add(reg)
|
||||
self.object.save()
|
||||
|
||||
reg.send_email_validation_link()
|
||||
|
||||
# Generate new password for the user
|
||||
password = get_random_string(16)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
|
||||
# Send welcome mail
|
||||
subject = "[TFJM²] " + str(_("New TFJM² jury account"))
|
||||
site = Site.objects.first()
|
||||
message = render_to_string('registration/mails/add_organizer.txt', dict(user=user,
|
||||
@ -758,12 +766,14 @@ class PoolAddJurysView(VolunteerMixin, FormView, DetailView):
|
||||
domain=site.domain))
|
||||
user.email_user(subject, message, html_message=html)
|
||||
|
||||
messages.success(self.request, _("The jury {name} has been successfully added!")\
|
||||
# Add notification
|
||||
messages.success(self.request, _("The jury {name} has been successfully added!")
|
||||
.format(name=f"{user.first_name} {user.last_name}"))
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
def form_invalid(self, form):
|
||||
# This is useful since we have a FormView + a DetailView
|
||||
self.object = self.get_object()
|
||||
return super().form_invalid(form)
|
||||
|
||||
|
Reference in New Issue
Block a user