Commit 3ea9a7719f06dc6107cd52456745980bd5c8b6f9

Authored by fbormann
1 parent 862dbc12

Modifiying Models and Adding a NotificationMixin Isuee#41

core/migrations/0003_auto_20160908_1108.py 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +# -*- coding: utf-8 -*-
  2 +# Generated by Django 1.10 on 2016-09-08 14:08
  3 +from __future__ import unicode_literals
  4 +
  5 +from django.conf import settings
  6 +from django.db import migrations, models
  7 +import django.db.models.deletion
  8 +
  9 +
  10 +class Migration(migrations.Migration):
  11 +
  12 + dependencies = [
  13 + migrations.swappable_dependency(settings.AUTH_USER_MODEL),
  14 + ('core', '0002_auto_20160907_0038'),
  15 + ]
  16 +
  17 + operations = [
  18 + migrations.AddField(
  19 + model_name='notification',
  20 + name='actor',
  21 + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notification_Performer', to=settings.AUTH_USER_MODEL, verbose_name='Perfomer'),
  22 + ),
  23 + migrations.AlterField(
  24 + model_name='notification',
  25 + name='user',
  26 + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notification_Actor', to=settings.AUTH_USER_MODEL, verbose_name='User'),
  27 + ),
  28 + ]
... ...
core/mixins.py
1 1 from django.conf import settings
2   -from .models import Action, Resource, Action_Resource, Log
  2 +from .models import Action, Resource, Action_Resource, Log, Notification
3 3  
4 4 class LogMixin(object):
5 5 log_action = ""
... ... @@ -17,4 +17,26 @@ class LogMixin(object):
17 17  
18 18 log.save()
19 19  
20   - return super(LogMixin, self).dispatch(request, *args, **kwargs)
21 20 \ No newline at end of file
  21 + return super(LogMixin, self).dispatch(request, *args, **kwargs)
  22 +
  23 +
  24 +
  25 +class NotificationMixin(object):
  26 + message = ""
  27 + read = False
  28 +
  29 + def dispatch(self, request, *args, **kwargs):
  30 + action = Action.objects.filter(name = self.log_action)
  31 + resource = Resource.objects.filter(name = self.log_resource)
  32 +
  33 + action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0]
  34 +
  35 + notification = Notification()
  36 + notification.action_resource = action_resource
  37 + notification.user = request.user #We still have to handle the notification to be sent to an amount of Users
  38 +
  39 + notification.read = read
  40 + notification.message = ""
  41 +
  42 +
  43 +
... ...
core/models.py
... ... @@ -52,11 +52,12 @@ class Action_Resource(models.Model):
52 52  
53 53 class Notification(models.Model):
54 54 message = models.TextField(_('Message'))
55   - user = models.ForeignKey(User, verbose_name = _('Actor'))
  55 + user = models.ForeignKey(User, related_name = _('%(class)s_Actor'), verbose_name= _('User'))
56 56 read = models.BooleanField(_('Read'), default = False)
57 57 datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True)
58 58 action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource'))
59   -
  59 + actor = models.ForeignKey(User, related_name = _('%(class)s_Performer'), verbose_name= _('Perfomer'), null = True)
  60 +
60 61 class Meta:
61 62 verbose_name = _("Notification")
62 63 verbose_name_plural = _("Notifications")
... ...
users/migrations/0011_auto_20160908_1108.py 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +# -*- coding: utf-8 -*-
  2 +# Generated by Django 1.10 on 2016-09-08 14:08
  3 +from __future__ import unicode_literals
  4 +
  5 +import django.core.validators
  6 +from django.db import migrations, models
  7 +import re
  8 +
  9 +
  10 +class Migration(migrations.Migration):
  11 +
  12 + dependencies = [
  13 + ('users', '0010_auto_20160906_2332'),
  14 + ]
  15 +
  16 + operations = [
  17 + migrations.AlterField(
  18 + model_name='user',
  19 + name='username',
  20 + field=models.CharField(help_text='A short name that will be used to identify you in the platform and to access it', max_length=35, unique=True, validators=[django.core.validators.RegexValidator(re.compile(b'^[\\w.@+-]+$'), 'Type a valid username. This fields should only contain letters, numbers and the characteres: @/./+/-/_ .', b'invalid')], verbose_name='Login'),
  21 + ),
  22 + ]
... ...