Add keys of categories that should exist to the notification Category model

parent 90ae8734
......@@ -170,7 +170,7 @@ class EventMessage(FormView):
body_nl=values['body_nl'],
body_en=values['body_en'],
url=values['url'],
category=Category.objects.get(key='event')
category=Category.objects.get(key=Category.EVENT)
)
message.save()
message.users.set([r.member for r in self.event.participants
......
......@@ -349,7 +349,7 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
'start in 1 uur'
.format(self.title_nl))
registration_reminder.category = Category.objects.get(
key='event')
key=Category.EVENT)
registration_reminder.time = registration_reminder_time
registration_reminder.url = (
f'{settings.BASE_URL}'
......@@ -376,7 +376,8 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
'1 hour')
start_reminder.body_nl = (f'\'{self.title_nl}\' begint over '
'1 uur')
start_reminder.category = Category.objects.get(key='event')
start_reminder.category = Category.objects.get(
key=Category.EVENT)
start_reminder.time = start_reminder_time
start_reminder.save()
self.start_reminder = start_reminder
......
......@@ -190,7 +190,8 @@ class Album(models.Model, metaclass=ModelTranslateMeta):
new_album_notification.body_nl = ('Een nieuw fotoalbum \'{}\' is '
'zojuist geüpload'
.format(self.title_nl))
new_album_notification.category = Category.objects.get(key='photo')
new_album_notification.category = Category.objects.get(
key=Category.PHOTO)
new_album_notification.url = (
f'{settings.BASE_URL}'
f'{self.get_absolute_url()}')
......
......@@ -97,7 +97,7 @@ class PizzaEvent(models.Model):
end_reminder.title_nl = 'Pizza bestellen'
end_reminder.body_en = 'You can order pizzas for 10 more minutes'
end_reminder.body_nl = "Je kan nog 10 minuten pizza's bestellen"
end_reminder.category = Category.objects.get(key='pizza')
end_reminder.category = Category.objects.get(key=Category.PIZZA)
end_reminder.time = self.end - timezone.timedelta(minutes=10)
end_reminder.save()
......
......@@ -13,6 +13,16 @@ from utils.translation import MultilingualField, ModelTranslateMeta
class Category(models.Model, metaclass=ModelTranslateMeta):
"""Describes a Message category"""
# These should be the keys of the categories that we automatically created
# in the migrations (0012 to be specific)
GENERAL = 'general'
PIZZA = 'pizza'
EVENT = 'event'
NEWSLETTER = 'newsletter'
PARTNER = 'partner'
PHOTO = 'photo'
BOARD = 'board'
key = models.CharField(max_length=16, primary_key=True)
name = MultilingualField(
......@@ -32,7 +42,7 @@ class Category(models.Model, metaclass=ModelTranslateMeta):
def default_receive_category():
return Category.objects.filter(key="general")
return Category.objects.filter(key=Category.GENERAL)
class Device(models.Model):
......
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 to comment