Add fetch function for DSI

This commit is contained in:
2017-08-17 21:46:13 +02:00
parent 9cb88a878d
commit 8c9f02a142
7 changed files with 44 additions and 1 deletions

View File

@ -231,6 +231,11 @@ class Mailing(models.Model):
club = models.ForeignKey(Club, verbose_name=_('Club'), related_name="mailings", null=False, blank=False)
email = models.EmailField(_('Email address'), unique=True)
def clean(self):
if '@' + settings.SITH_MAILING_ALLOWED_DOMAIN not in self.email:
raise ValidationError(_('Unothorized mailing domain'))
super(Mailing, self).clean()
def is_owned_by(self, user):
return user.is_in_group(self) or user.is_root or user.is_board_member
@ -242,6 +247,15 @@ class Mailing(models.Model):
sub.delete()
super(Mailing, self).delete()
def base_mail(self):
return self.email.split('@')[0]
def fetch_format(self):
resp = self.base_mail() + ': '
for sub in self.subscriptions.all():
resp += sub.fetch_format()
return resp
def __str__(self):
return "%s - %s" % (self.club, self.email)
@ -270,6 +284,9 @@ class MailingSubscription(models.Model):
def can_be_edited_by(self, user):
return self.is_owned_by(user) or (user is not None and user.id == self.user.id)
def fetch_format(self):
return self.email + ' '
def __str__(self):
if self.user:
user = str(self.user)