diff --git a/core/migrations/0013_auto_20161209_2338.py b/core/migrations/0013_auto_20161209_2338.py new file mode 100644 index 00000000..15343814 --- /dev/null +++ b/core/migrations/0013_auto_20161209_2338.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0012_notification'), + ] + + operations = [ + migrations.RemoveField( + model_name='notification', + name='text', + ), + migrations.AddField( + model_name='notification', + name='param', + field=models.CharField(verbose_name='param', default='', max_length=128), + ), + migrations.AddField( + model_name='notification', + name='viewed', + field=models.BooleanField(verbose_name='viewed', default=False), + ), + migrations.AlterField( + model_name='notification', + name='type', + field=models.CharField(verbose_name='type', default='GENERIC', choices=[('FILE_MODERATION', 'New files to be moderated'), ('SAS_MODERATION', 'New pictures/album to be moderated in the SAS'), ('NEW_PICTURES', "You've been identified on some pictures"), ('REFILLING', 'You just refilled of %(amount)s €'), ('SELLING', 'You just bought %(selling)s'), ('GENERIC', 'You have a notification')], max_length=32), + ), + ] diff --git a/core/models.py b/core/models.py index 332dda63..59ea512f 100644 --- a/core/models.py +++ b/core/models.py @@ -853,8 +853,13 @@ class PageRev(models.Model): class Notification(models.Model): user = models.ForeignKey(User, related_name='notifications') url = models.CharField(_("url"), max_length=255) - text = models.CharField(_("text"), max_length=512) - type = models.CharField(_("text"), max_length=16, choices=settings.SITH_NOTIFICATIONS, blank=True, null=True) + param = models.CharField(_("param"), max_length=128, default="") + type = models.CharField(_("type"), max_length=32, choices=settings.SITH_NOTIFICATIONS, default="GENERIC") date = models.DateTimeField(_('date'), default=timezone.now) + viewed = models.BooleanField(_('viewed'), default=False) + def __str__(self): + if self.param: + return self.get_type_display() % self.param + return self.get_type_display() diff --git a/core/static/core/style.css b/core/static/core/style.css index 1dd0c8bc..776a0290 100644 --- a/core/static/core/style.css +++ b/core/static/core/style.css @@ -67,6 +67,7 @@ header form { display: none; position: fixed; background: lightgrey; + text-align: center; } #notif li:hover { background: #bcc; @@ -289,6 +290,11 @@ tbody>tr:hover { margin: 2px auto; display: block; } +#notifications li { + padding: 5px; + margin: 2px; + list-style: none; +} #moderation div { margin: 2px; padding: 2px; diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index da1d8d87..fcc2907f 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -39,17 +39,16 @@ {% endfor %} {{ user.get_display_name() }} - {% if user.notifications.exists() %} - 🔔 ({{ user.notifications.count() }}) + 🔔 ({{ user.notifications.filter(viewed=False).count() }})