Commit 3c80a5d80ceecddbaed656afd41035685bb73c21

Authored by Jailson Dias
2 parents fce7c945 17de13f6

resolve conflicts

core/decorators.py
... ... @@ -14,7 +14,25 @@ def log_decorator(log_action = '', log_resource = ''):
14 14 action = Action.objects.filter(name = log_action)
15 15 resource = Resource.objects.filter(name = log_resource)
16 16  
17   - action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0]
  17 + if not action:
  18 + action = Action(name = log_action)
  19 + action.save()
  20 + else:
  21 + action = action[0]
  22 +
  23 + if not resource:
  24 + resource = Resource(name = log_resource)
  25 + resource.save()
  26 + else:
  27 + resource = resource[0]
  28 +
  29 + action_resource = Action_Resource.objects.filter(action = action, resource = resource)
  30 +
  31 + if not action_resource:
  32 + action_resource = Action_Resource(action = action, resource = resource)
  33 + action_resource.save()
  34 + else:
  35 + action_resource = action_resource[0]
18 36  
19 37 log = Log()
20 38 log.user = request.user
... ...
core/forms.py
... ... @@ -12,7 +12,7 @@ class RegisterUserForm(forms.ModelForm):
12 12 def clean_email(self):
13 13 email = self.cleaned_data['email']
14 14 if User.objects.filter(email = email).exists():
15   - raise forms.ValidationError('Já existe um usuário cadastrado com este E-mail')
  15 + raise forms.ValidationError('Ja existe um usuario cadastrado com este E-mail')
16 16 return email
17 17  
18 18 def clean_password(self):
... ... @@ -35,7 +35,7 @@ class RegisterUserForm(forms.ModelForm):
35 35 password2 = self.cleaned_data.get("password2")
36 36  
37 37 if password and password2 and password != password2:
38   - raise forms.ValidationError('A confirmacão da senha está incorreta')
  38 + raise forms.ValidationError('A confirmacao da senha esta incorreta')
39 39 return password2
40 40  
41 41 def save(self, commit=True):
... ...
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/migrations/0004_auto_20160908_1151.py 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +# -*- coding: utf-8 -*-
  2 +# Generated by Django 1.10 on 2016-09-08 14:51
  3 +from __future__ import unicode_literals
  4 +
  5 +from django.db import migrations, models
  6 +
  7 +
  8 +class Migration(migrations.Migration):
  9 +
  10 + dependencies = [
  11 + ('core', '0003_auto_20160908_1108'),
  12 + ]
  13 +
  14 + operations = [
  15 + migrations.AlterField(
  16 + model_name='resource',
  17 + name='name',
  18 + field=models.CharField(max_length=100, unique=True, verbose_name='Name'),
  19 + ),
  20 + ]
... ...
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 = ""
... ... @@ -9,7 +9,25 @@ class LogMixin(object):
9 9 action = Action.objects.filter(name = self.log_action)
10 10 resource = Resource.objects.filter(name = self.log_resource)
11 11  
12   - action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0]
  12 + if not action:
  13 + action = Action(name = self.log_action)
  14 + action.save()
  15 + else:
  16 + action = action[0]
  17 +
  18 + if not resource:
  19 + resource = Resource(name = self.log_resource)
  20 + resource.save()
  21 + else:
  22 + resource = resource[0]
  23 +
  24 + action_resource = Action_Resource.objects.filter(action = action, resource = resource)
  25 +
  26 + if not action_resource:
  27 + action_resource = Action_Resource(action = action, resource = resource)
  28 + action_resource.save()
  29 + else:
  30 + action_resource = action_resource[0]
13 31  
14 32 log = Log()
15 33 log.user = request.user
... ... @@ -18,3 +36,20 @@ class LogMixin(object):
18 36 log.save()
19 37  
20 38 return super(LogMixin, self).dispatch(request, *args, **kwargs)
  39 +
  40 +class NotificationMixin(object):
  41 + message = ""
  42 + read = False
  43 +
  44 + def dispatch(self, request, *args, **kwargs):
  45 + action = Action.objects.filter(name = self.log_action)
  46 + resource = Resource.objects.filter(name = self.log_resource)
  47 +
  48 + action_resource = Action_Resource.objects.filter(action = action, resource = resource)[0]
  49 +
  50 + notification = Notification()
  51 + notification.action_resource = action_resource
  52 + notification.user = request.user #We still have to handle the notification to be sent to an amount of Users
  53 +
  54 + notification.read = read
  55 + notification.message = ""
... ...
core/models.py
... ... @@ -24,9 +24,14 @@ class Resource(models.Model):
24 24 """
25 25 It represents the resource where the action was applied on.
26 26 Example: Pool was answered (Resource: Pool), PDF was visualized(Resource: PDF).
  27 +
  28 + Attributes:
  29 + @name: name of the resource affected, it will be unique because a resource can be affecte
  30 + by a huge amount of actions
  31 + @created_date: The date the resource was created
27 32 """
28 33  
29   - name = models.CharField(_('Name'), max_length =100)
  34 + name = models.CharField(_('Name'), max_length =100, unique=True)
30 35 created_date = models.DateField(_('Created Date'), auto_now_add=True)
31 36  
32 37 class Meta:
... ... @@ -51,12 +56,23 @@ class Action_Resource(models.Model):
51 56  
52 57  
53 58 class Notification(models.Model):
  59 + """
  60 + Attributes:
  61 + @message: The message that will be shown on the notification prompt
  62 + @user: The User that the notification will be sent to.
  63 + @read: Whether or not the user has read the notification.
  64 + @datetime: The time the notification was created
  65 + @action_resource: The Object that holds the information about which action was perfomed on the Resource
  66 + @actor: The user who applied the action
  67 + """
  68 +
54 69 message = models.TextField(_('Message'))
55   - user = models.ForeignKey(User, verbose_name = _('Actor'))
  70 + user = models.ForeignKey(User, related_name = _('%(class)s_Actor'), verbose_name= _('User'))
56 71 read = models.BooleanField(_('Read'), default = False)
57 72 datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True)
58 73 action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource'))
59   -
  74 + actor = models.ForeignKey(User, related_name = _('%(class)s_Performer'), verbose_name= _('Perfomer'), null = True)
  75 +
60 76 class Meta:
61 77 verbose_name = _("Notification")
62 78 verbose_name_plural = _("Notifications")
... ...
logs/log_file_06-09-2016.txt
... ... @@ -93,3 +93,8 @@
93 93 06/09/2016 21:34:11 - test - Acessou home
94 94 06/09/2016 21:38:44 - test - Entrou no sistema
95 95 06/09/2016 21:38:44 - test - Acessou home
  96 +06/09/2016 21:58:49 - jailson - Entrou no sistema
  97 +06/09/2016 21:58:49 - jailson - Acessou home
  98 +06/09/2016 21:59:05 - jailson - Acessou home
  99 +06/09/2016 21:59:35 - jailson - Acessou home
  100 +06/09/2016 21:59:42 - jailson - Acessou home
... ...
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 + ]
... ...