Commit cc595a39 by Őry Máté

dashboard: add Notification.valid_until

parent ec4f2a05
...@@ -5,7 +5,8 @@ from django.conf import settings ...@@ -5,7 +5,8 @@ from django.conf import settings
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.contrib.auth.signals import user_logged_in from django.contrib.auth.signals import user_logged_in
from django.db.models import ( from django.db.models import (
Model, ForeignKey, OneToOneField, CharField, IntegerField, TextField Model, ForeignKey, OneToOneField, CharField, IntegerField, TextField,
DateTimeField,
) )
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _, override from django.utils.translation import ugettext_lazy as _, override
...@@ -34,12 +35,13 @@ class Notification(TimeStampedModel): ...@@ -34,12 +35,13 @@ class Notification(TimeStampedModel):
to = ForeignKey(User) to = ForeignKey(User)
subject = CharField(max_length=128) subject = CharField(max_length=128)
message = TextField() message = TextField()
valid_until = DateTimeField(null=True, default=None)
class Meta: class Meta:
ordering = ['-created'] ordering = ['-created']
@classmethod @classmethod
def send(cls, user, subject, template, context={}): def send(cls, user, subject, template, context={}, valid_until=None):
try: try:
language = user.profile.preferred_language language = user.profile.preferred_language
except: except:
...@@ -48,7 +50,8 @@ class Notification(TimeStampedModel): ...@@ -48,7 +50,8 @@ class Notification(TimeStampedModel):
context['user'] = user context['user'] = user
rendered = render_to_string(template, context) rendered = render_to_string(template, context)
subject = unicode(subject) subject = unicode(subject)
return cls.objects.create(to=user, subject=subject, message=rendered) return cls.objects.create(to=user, subject=subject, message=rendered,
valid_until=valid_until)
class Profile(Model): class Profile(Model):
...@@ -62,8 +65,9 @@ class Profile(Model): ...@@ -62,8 +65,9 @@ class Profile(Model):
help_text=_('Unique identifier of the person, e.g. a student number.')) help_text=_('Unique identifier of the person, e.g. a student number.'))
instance_limit = IntegerField(default=5) instance_limit = IntegerField(default=5)
def notify(self, subject, template, context={}): def notify(self, subject, template, context={}, valid_until=None):
return Notification.send(self.user, subject, template, context) return Notification.send(self.user, subject, template, context,
valid_until)
class GroupProfile(AclBase): class GroupProfile(AclBase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment