mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
core: improve notification callback system
Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
parent
9b0b381fa3
commit
d5c6695f80
@ -1094,13 +1094,18 @@ class Notification(models.Model):
|
|||||||
return self.get_type_display() % self.param
|
return self.get_type_display() % self.param
|
||||||
return self.get_type_display()
|
return self.get_type_display()
|
||||||
|
|
||||||
|
def callback(self):
|
||||||
|
# Get the callback defined in settings to update existing
|
||||||
|
# notifications
|
||||||
|
mod_name, func_name = settings.SITH_PERMANENT_NOTIFICATIONS[self.type].rsplit('.',1)
|
||||||
|
mod = importlib.import_module(mod_name)
|
||||||
|
getattr(mod, func_name)(self)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.id and self.type in settings.SITH_PERMANENT_NOTIFICATIONS:
|
if not self.id and self.type in settings.SITH_PERMANENT_NOTIFICATIONS:
|
||||||
old_notif = self.user.notifications.filter(type=self.type).last()
|
old_notif = self.user.notifications.filter(type=self.type).last()
|
||||||
if old_notif:
|
if old_notif:
|
||||||
mod_name, func_name = settings.SITH_PERMANENT_NOTIFICATIONS[self.type].rsplit('.',1)
|
old_notif.callback()
|
||||||
mod = importlib.import_module(mod_name)
|
|
||||||
getattr(mod, func_name)(old_notif)
|
|
||||||
old_notif.save()
|
old_notif.save()
|
||||||
return
|
return
|
||||||
super(Notification, self).save(*args, **kwargs)
|
super(Notification, self).save(*args, **kwargs)
|
||||||
|
@ -62,7 +62,9 @@ def notification(request, notif_id):
|
|||||||
if notif:
|
if notif:
|
||||||
if notif.type not in settings.SITH_PERMANENT_NOTIFICATIONS:
|
if notif.type not in settings.SITH_PERMANENT_NOTIFICATIONS:
|
||||||
notif.viewed = True
|
notif.viewed = True
|
||||||
notif.save()
|
else:
|
||||||
|
notif.callback()
|
||||||
|
notif.save()
|
||||||
return redirect(notif.url)
|
return redirect(notif.url)
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user