|
|
@ -2,6 +2,8 @@ from django.db import models |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.core.mail import send_mail |
|
|
from django.core.mail import send_mail |
|
|
from django.template import Context, loader |
|
|
from django.template import Context, loader |
|
|
|
|
|
from django.db.models.signals import post_save |
|
|
|
|
|
from django.dispatch import receiver |
|
|
|
|
|
|
|
|
import users.models |
|
|
import users.models |
|
|
|
|
|
|
|
|
@ -46,21 +48,30 @@ class Ticket(models.Model): |
|
|
return "Ticket de {} date: {}".format(self.user.surname,self.date) |
|
|
return "Ticket de {} date: {}".format(self.user.surname,self.date) |
|
|
|
|
|
|
|
|
def publish_mail(self): |
|
|
def publish_mail(self): |
|
|
template = loader.get_template('ticket/mail_publish_ticket') |
|
|
to_addr = Preferences.objects.first().publish_address |
|
|
|
|
|
template = loader.get_template('tickets/publication_mail') |
|
|
context = Context({'ticket':self}) |
|
|
context = Context({'ticket':self}) |
|
|
send_mail( |
|
|
send_mail( |
|
|
'Nouvelle ouverture de ticket', |
|
|
'Nouvelle ouverture de ticket', |
|
|
'', |
|
|
template.render(context), |
|
|
'ticket_app_re2o@crans.org', |
|
|
'grisel-davy@crans.org', |
|
|
'', |
|
|
[to_addr], |
|
|
html_message=template.render(context)) |
|
|
fail_silently = False) |
|
|
|
|
|
|
|
|
class Preferences(models.Model): |
|
|
class Preferences(models.Model): |
|
|
""" Class cannonique définissants les préférences des tickets """ |
|
|
""" Class cannonique définissants les préférences des tickets """ |
|
|
|
|
|
|
|
|
publish_address = models.EmailField( |
|
|
publish_address = models.EmailField( |
|
|
help_text = _("Adresse mail pour annoncer les nouveau tickets (laisser vide pour ne rien annoncer)"), |
|
|
help_text = _("Adresse mail pour annoncer les nouveau tickets (laisser vide pour ne rien annoncer)"), |
|
|
max_length = 1000, |
|
|
max_length = 1000, |
|
|
null = True) |
|
|
null = True) |
|
|
class Meta: |
|
|
class Meta: |
|
|
verbose_name = _("Préférences des tickets") |
|
|
verbose_name = _("Préférences des tickets") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=Ticket) |
|
|
|
|
|
def ticket_post_save(**kwargs): |
|
|
|
|
|
"""Envoit du mail de publication du ticket""" |
|
|
|
|
|
if Preferences.objects.first().publish_address: |
|
|
|
|
|
ticket = kwargs['instance'] |
|
|
|
|
|
ticket.publish_mail() |
|
|
|