mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Merge branch 'sli' into 'master'
Add automatic mail when an eticket has been bought See merge request !19
This commit is contained in:
commit
7fe0964ae1
@ -1,4 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.core.mail import send_mail
|
||||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager, Group as AuthGroup, GroupManager as AuthGroupManager, AnonymousUser as AuthAnonymousUser
|
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager, Group as AuthGroup, GroupManager as AuthGroupManager, AnonymousUser as AuthAnonymousUser
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@ -332,6 +333,8 @@ class User(AbstractBaseUser):
|
|||||||
"""
|
"""
|
||||||
Sends an email to this User.
|
Sends an email to this User.
|
||||||
"""
|
"""
|
||||||
|
if from_email is None:
|
||||||
|
from_email = settings.DEFAULT_FROM_EMAIL
|
||||||
send_mail(subject, message, from_email, [self.email], **kwargs)
|
send_mail(subject, message, from_email, [self.email], **kwargs)
|
||||||
|
|
||||||
def generate_username(self):
|
def generate_username(self):
|
||||||
|
@ -4,6 +4,7 @@ from django.utils import timezone
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.forms import ValidationError
|
from django.forms import ValidationError
|
||||||
|
from django.contrib.sites.shortcuts import get_current_site
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import random
|
import random
|
||||||
@ -54,6 +55,13 @@ class Customer(models.Model):
|
|||||||
self.amount -= s.quantity * s.unit_price
|
self.amount -= s.quantity * s.unit_price
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('core:user_account', kwargs={'user_id': self.user.pk})
|
||||||
|
|
||||||
|
def get_full_url(self):
|
||||||
|
return ''.join(['https://', settings.SITH_URL, self.get_absolute_url()])
|
||||||
|
|
||||||
|
|
||||||
class ProductType(models.Model):
|
class ProductType(models.Model):
|
||||||
"""
|
"""
|
||||||
This describes a product type
|
This describes a product type
|
||||||
@ -292,6 +300,33 @@ class Selling(models.Model):
|
|||||||
self.customer.save()
|
self.customer.save()
|
||||||
super(Selling, self).delete(*args, **kwargs)
|
super(Selling, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
def send_mail_customer(self):
|
||||||
|
event = self.product.eticket.event_title or _("Unknown event")
|
||||||
|
subject = _('Eticket bought for the event %(event)s') % {'event': event}
|
||||||
|
message_html = _(
|
||||||
|
"You bought an eticket for the event %(event)s.\nYou can download it on this page %(url)s."
|
||||||
|
) % {
|
||||||
|
'event': event,
|
||||||
|
'url':''.join((
|
||||||
|
'<a href="',
|
||||||
|
self.customer.get_full_url(),
|
||||||
|
'">',
|
||||||
|
self.customer.get_full_url(),
|
||||||
|
'</a>'
|
||||||
|
))
|
||||||
|
}
|
||||||
|
message_txt = _(
|
||||||
|
"You bought an eticket for the event %(event)s.\nYou can download it on this page %(url)s."
|
||||||
|
) % {
|
||||||
|
'event': event,
|
||||||
|
'url': self.customer.get_full_url(),
|
||||||
|
}
|
||||||
|
self.customer.user.email_user(
|
||||||
|
subject,
|
||||||
|
message_txt,
|
||||||
|
html_message=message_html
|
||||||
|
)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.date:
|
if not self.date:
|
||||||
self.date = timezone.now()
|
self.date = timezone.now()
|
||||||
@ -330,6 +365,10 @@ class Selling(models.Model):
|
|||||||
duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration'],
|
duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration'],
|
||||||
start=sub.subscription_start)
|
start=sub.subscription_start)
|
||||||
sub.save()
|
sub.save()
|
||||||
|
try:
|
||||||
|
if self.product.eticket:
|
||||||
|
self.send_mail_customer()
|
||||||
|
except: pass
|
||||||
super(Selling, self).save(*args, **kwargs)
|
super(Selling, self).save(*args, **kwargs)
|
||||||
|
|
||||||
class Permanency(models.Model):
|
class Permanency(models.Model):
|
||||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user