-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
424 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/backend/joanie/core/migrations/0003_alter_courserun_is_listed_notification.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 4.0.10 on 2023-02-24 16:37 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('core', '0002_coursewish'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='courserun', | ||
name='is_listed', | ||
field=models.BooleanField(default=False, help_text='If checked the course run will be included in the list of course runs available for enrollment on the related course page.', verbose_name='is listed'), | ||
), | ||
migrations.CreateModel( | ||
name='Notification', | ||
fields=[ | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')), | ||
('created_on', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')), | ||
('updated_on', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')), | ||
('notif_subject_id', models.UUIDField()), | ||
('notif_object_id', models.UUIDField()), | ||
('action_type', models.CharField(choices=[('EMAIL', 'Send an email')], default='EMAIL', max_length=10, verbose_name='Type of action')), | ||
('notified_at', models.DateTimeField(blank=True, editable=False, help_text='date and time at which an email has been sent to the user', null=True, verbose_name='Notified at')), | ||
('notif_object_ctype', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='object_ctype_of_notifications', to='contenttypes.contenttype')), | ||
('notif_subject_ctype', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subject_ctype_of_notifications', to='contenttypes.contenttype')), | ||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'verbose_name': 'Notification', | ||
'verbose_name_plural': 'Notifications', | ||
'db_table': 'joanie_notification', | ||
'ordering': ('owner', 'notified_at'), | ||
}, | ||
), | ||
] |
30 changes: 30 additions & 0 deletions
30
...ackend/joanie/core/migrations/0004_rename_action_type_notification_notif_type_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 4.0.10 on 2023-02-27 15:55 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('core', '0003_alter_courserun_is_listed_notification'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='notification', | ||
old_name='action_type', | ||
new_name='notif_type', | ||
), | ||
migrations.AlterField( | ||
model_name='notification', | ||
name='notif_object_ctype', | ||
field=models.ForeignKey(limit_choices_to=models.Q(models.Q(('app_label', 'core'), ('model', 'producttargetcourserelation')), models.Q(('app_label', 'core'), ('model', 'courserun')), models.Q(('app_label', 'core'), ('model', 'product')), _connector='OR'), on_delete=django.db.models.deletion.CASCADE, related_name='object_ctype_of_notifications', to='contenttypes.contenttype'), | ||
), | ||
migrations.AlterField( | ||
model_name='notification', | ||
name='notif_subject_ctype', | ||
field=models.ForeignKey(limit_choices_to=models.Q(models.Q(('app_label', 'core'), ('model', 'coursewish')), models.Q(('app_label', 'core'), ('model', 'enrollment')), _connector='OR'), on_delete=django.db.models.deletion.CASCADE, related_name='subject_ctype_of_notifications', to='contenttypes.contenttype'), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
src/backend/joanie/core/migrations/0005_notification_action_alter_notification_notif_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.0.10 on 2023-02-28 09:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0004_rename_action_type_notification_notif_type_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='notification', | ||
name='action', | ||
field=models.CharField(choices=[('ADD', 'added'), ('CREATE', 'created')], default='CREATE', max_length=10, verbose_name='Action on the object of notification'), | ||
), | ||
migrations.AlterField( | ||
model_name='notification', | ||
name='notif_type', | ||
field=models.CharField(choices=[('EMAIL', 'Send an email')], default='EMAIL', max_length=10, verbose_name='Type of notification'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
from .courses import * | ||
from .products import * | ||
from .wishlist import * | ||
from .notifications import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
""" | ||
Declare and configure the models for the notification part | ||
""" | ||
from django.contrib.contenttypes.fields import GenericForeignKey | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from . import User | ||
from .base import BaseModel | ||
|
||
|
||
class Notification(BaseModel): | ||
""" | ||
Notification model define a notification about an action on a object instance according a | ||
subject instance. | ||
notif_subject: [GenericForeignKey] | ||
Defined using notif_subject_ctype [ContentType] and notif_subject_id [uuid] | ||
It represents the user's subject that he want to be notified about. | ||
It can be a user course wish or a user course enrollment. | ||
notif_object: [GenericForeignKey] | ||
Defined using notif_object_ctype [ContentType] and notif_object_id [uuid] | ||
It represents the object that generate the notification according the user's subject | ||
It can be a course run, a product or the relation between a product and an course. | ||
action: [CharField with NOTIF_ACTIONS choices] | ||
It represents the action done on the object that generate the notification | ||
The action's values are | ||
"ADD": the object has been add in a m2m relationship | ||
"CREATE": the object has been create | ||
notif_type: [CharField with NOTIF_TYPES choices] | ||
It's the type of the notification | ||
It can be an email or a dashboard notification (not implemented yet) | ||
notified_at: [DateTimeField] | ||
It's the DatiTime when the notification has been sent to the owner. | ||
If the value is None, the notification has not been sent yet. | ||
owner: [User] | ||
It's the User that received or will receive the notification. | ||
""" | ||
|
||
NOTIF_ACTION_ADD = "ADD" | ||
NOTIF_ACTION_CREATE = "CREATE" | ||
|
||
NOTIF_ACTIONS = ( | ||
(NOTIF_ACTION_ADD, _("added")), | ||
(NOTIF_ACTION_CREATE, _("created")), | ||
) | ||
|
||
NOTIF_TYPE_EMAIL = "EMAIL" | ||
|
||
NOTIF_TYPES = ( | ||
(NOTIF_TYPE_EMAIL, _("Send an email")), | ||
) | ||
|
||
notif_subject_ctype_limit = models.Q(app_label='core', model='coursewish') \ | ||
| models.Q(app_label='core', model='enrollment') | ||
notif_subject_ctype = models.ForeignKey( | ||
ContentType, | ||
on_delete=models.CASCADE, | ||
related_name="subject_ctype_of_notifications", | ||
limit_choices_to=notif_subject_ctype_limit | ||
) | ||
notif_subject_id = models.UUIDField() | ||
notif_subject = GenericForeignKey('notif_subject_ctype', 'notif_subject_id') | ||
|
||
notif_object_ctype_limit = models.Q(app_label='core', model='producttargetcourserelation') \ | ||
| models.Q(app_label='core', model='courserun') \ | ||
| models.Q(app_label='core', model='product') | ||
notif_object_ctype = models.ForeignKey( | ||
ContentType, | ||
on_delete=models.CASCADE, | ||
related_name="object_ctype_of_notifications", | ||
limit_choices_to=notif_object_ctype_limit | ||
) | ||
notif_object_id = models.UUIDField() | ||
notif_object = GenericForeignKey('notif_object_ctype', 'notif_object_id') | ||
|
||
action = models.CharField( | ||
_("Action on the object of notification"), | ||
choices=NOTIF_ACTIONS, | ||
max_length=10, | ||
default=NOTIF_ACTION_CREATE | ||
) | ||
|
||
notif_type = models.CharField( | ||
_("Type of notification"), | ||
choices=NOTIF_TYPES, | ||
max_length=10, | ||
default=NOTIF_TYPE_EMAIL | ||
) | ||
|
||
notified_at = models.DateTimeField( | ||
verbose_name=_("Notified at"), | ||
help_text=_("date and time when the notification has been sent to the owner"), | ||
blank=True, | ||
null=True, | ||
editable=False, | ||
) | ||
|
||
owner = models.ForeignKey(User, on_delete=models.PROTECT) | ||
|
||
class Meta: | ||
db_table = "joanie_notification" | ||
ordering = ("owner", "notified_at") | ||
verbose_name = _( | ||
"Notification" | ||
) | ||
verbose_name_plural = _( | ||
"Notifications" | ||
) | ||
|
||
def __str__(self): | ||
if self.notified_at: | ||
return ( | ||
f"'{self.owner}' has been notified about " | ||
f"'{self.notif_object}' according to '{self.notif_subject}' at '{self.notified_at}'" | ||
) | ||
return ( | ||
f"'{self.owner}' hasn't been notified about " | ||
f"'{self.notif_object}' according to '{self.notif_subject}' yet" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.