mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-07-02 00:28:32 +02:00
Add survey notification in the menu
This commit is contained in:
@ -8,6 +8,7 @@ from django.contrib.sites.models import Site
|
||||
from django.core.mail import send_mail
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.template import loader
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone, translation
|
||||
@ -260,6 +261,8 @@ class ParticipantRegistration(Registration):
|
||||
raise NotImplementedError
|
||||
|
||||
def registration_informations(self):
|
||||
from survey.models import Survey
|
||||
|
||||
informations = []
|
||||
if not self.team:
|
||||
text = _("You are not in a team. You can <a href=\"{create_url}\">create one</a> "
|
||||
@ -300,6 +303,20 @@ class ParticipantRegistration(Registration):
|
||||
'content': content,
|
||||
})
|
||||
|
||||
if self.team.participation.valid:
|
||||
for survey in Survey.objects.filter(Q(tournament__isnull=True) | Q(tournament=self.team.participation.tournament),
|
||||
Q(invite_team=False), Q(invite_coaches=True) | Q(invite_coaches=self.is_coach),
|
||||
~Q(completed_registrations=self)):
|
||||
text = _("Please answer to the survey \"{name}\". You can go to the survey on <a href=\"{survey_link}\">that link</a>, "
|
||||
"using the token code you received by mail.")
|
||||
content = format_lazy(text, name=survey.name, survey_link=f"{settings.LIMESURVEY_URL}/index.php/{survey.survey_id}")
|
||||
informations.append({
|
||||
'title': _("Required answer to survey"),
|
||||
'type': "warning",
|
||||
'priority': 12,
|
||||
'content': content
|
||||
})
|
||||
|
||||
informations.extend(self.team.important_informations())
|
||||
|
||||
return informations
|
||||
@ -315,19 +332,19 @@ class ParticipantRegistration(Registration):
|
||||
tournament = Tournament.final_tournament()
|
||||
payment = self.payments.filter(final=True).first() if self.is_student else None
|
||||
message = loader.render_to_string('registration/mails/final_selection.txt',
|
||||
{
|
||||
'user': self.user,
|
||||
'domain': site.domain,
|
||||
'tournament': tournament,
|
||||
'payment': payment,
|
||||
})
|
||||
{
|
||||
'user': self.user,
|
||||
'domain': site.domain,
|
||||
'tournament': tournament,
|
||||
'payment': payment,
|
||||
})
|
||||
html = loader.render_to_string('registration/mails/final_selection.html',
|
||||
{
|
||||
'user': self.user,
|
||||
'domain': site.domain,
|
||||
'tournament': tournament,
|
||||
'payment': payment,
|
||||
})
|
||||
{
|
||||
'user': self.user,
|
||||
'domain': site.domain,
|
||||
'tournament': tournament,
|
||||
'payment': payment,
|
||||
})
|
||||
self.user.email_user(subject, message, html_message=html)
|
||||
|
||||
class Meta:
|
||||
@ -807,9 +824,9 @@ class Payment(models.Model):
|
||||
site = Site.objects.first()
|
||||
for registration in self.registrations.all():
|
||||
message = loader.render_to_string('registration/mails/payment_reminder.txt',
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
html = loader.render_to_string('registration/mails/payment_reminder.html',
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
registration.user.email_user(subject, message, html_message=html)
|
||||
|
||||
def send_helloasso_payment_confirmation_mail(self):
|
||||
@ -818,18 +835,18 @@ class Payment(models.Model):
|
||||
site = Site.objects.first()
|
||||
for registration in self.registrations.all():
|
||||
message = loader.render_to_string('registration/mails/payment_confirmation.txt',
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
html = loader.render_to_string('registration/mails/payment_confirmation.html',
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
dict(registration=registration, payment=self, domain=site.domain))
|
||||
registration.user.email_user(subject, message, html_message=html)
|
||||
|
||||
payer = self.get_checkout_intent()['order']['payer']
|
||||
payer_name = f"{payer['firstName']} {payer['lastName']}"
|
||||
if not self.registrations.filter(user__email=payer['email']).exists():
|
||||
message = loader.render_to_string('registration/mails/payment_confirmation.txt',
|
||||
dict(registration=payer_name, payment=self, domain=site.domain))
|
||||
dict(registration=payer_name, payment=self, domain=site.domain))
|
||||
html = loader.render_to_string('registration/mails/payment_confirmation.html',
|
||||
dict(registration=payer_name, payment=self, domain=site.domain))
|
||||
dict(registration=payer_name, payment=self, domain=site.domain))
|
||||
send_mail(subject, message, None, [payer['email']], html_message=html)
|
||||
|
||||
def get_absolute_url(self):
|
||||
|
Reference in New Issue
Block a user