def ready(self):
from .models import Notification
from herald import registry
self.module.autodiscover()
try:
# add any new notifications to database.
for index, klass in enumerate(registry._registry):
notification, created = Notification.objects.get_or_create(
notification_class=klass.get_class_path(),
defaults={
'verbose_name': klass.get_verbose_name(),
'can_disable': klass.can_disable,
}
)
if not created:
notification.verbose_name = klass.get_verbose_name()
notification.can_disable = klass.can_disable
notification.save()
except OperationalError:
# if the table is not created yet, just keep going.
pass
except ProgrammingError:
# if the database is not created yet, keep going (ie: during testing)
pass
评论列表
文章目录