models.py
4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from django.db import models
from django.utils.translation import ugettext_lazy as _
from users.models import User
from autoslug.fields import AutoSlugField
from django.contrib.postgres.fields import JSONField
# Create your models here.
class MimeType(models.Model):
typ = models.CharField(_('Type'), max_length=100, unique=True)
icon = models.CharField(_('Icon'), max_length=50, unique=True)
class Meta:
verbose_name= _('Amadeus Mime Type')
verbose_name_plural = _('Amadeus Mime Types')
def get_icon(self, type):
pass
def __str__(self):
return self.typ
class Action(models.Model):
"""
It represents an Action on the program by a User such as "create post",
"visualize post", etc. It is supposed to be created everytime we want an aciton
"""
name = models.CharField(_('Name'), max_length = 100)
slug = AutoSlugField(_("Slug"), populate_from=('name'), unique=True)
created_date = models.DateTimeField(_('Created Date'), auto_now_add=True)
class Meta:
verbose_name = "Action"
verbose_name_plural = "Actions"
def __str__(self):
return self.name
class Resource(models.Model):
"""
It represents the resource where the action was applied on.
Example: Pool was answered (Resource: Pool), PDF was visualized(Resource: PDF).
Attributes:
@name: name of the resource affected, it will be unique because a resource can be affecte
by a huge amount of actions
@created_date: The date the resource was created
@link: Which URL made that resource able to find
"""
name = models.CharField(_('Name'), max_length =100)
slug = AutoSlugField(_("Slug"), populate_from='name', unique=True)
created_date = models.DateTimeField(_('Created Date'), auto_now_add=True)
url = models.CharField(_('URL'), max_length =100, default="")
class Meta:
verbose_name = "Resource"
verbose_name_plural = "Resources"
def __str__(self):
return self.name
class Action_Resource(models.Model):
action = models.ForeignKey(Action , verbose_name= _('Action_Applied'))
resource = models.ForeignKey(Resource, verbose_name = _('Resource'))
class Meta:
verbose_name = "Action_Resource"
verbose_name_plural = "Action_Resources"
def __str__(self):
return ''.join([self.action.name, " / ", self.resource.name])
class Notification(models.Model):
"""
Attributes:
@message: The message that will be shown on the notification prompt
@user: The User that the notification will be sent to.
@read: Whether or not the user has read the notification.
@datetime: The time the notification was created
@action_resource: The Object that holds the information about which action was perfomed on the Resource
@actor: The user who applied the action
"""
message = models.TextField(_('Message'))
user = models.ForeignKey(User, related_name = _('%(class)s_Actor'), verbose_name= _('User'))
read = models.BooleanField(_('Read'), default = False)
datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True)
action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource'))
actor = models.ForeignKey(User, related_name = _('%(class)s_Performer'), verbose_name= _('Performer'), null = True)
class Meta:
verbose_name = _("Notification")
verbose_name_plural = _("Notifications")
def __str__(self):
return self.message
class Log(models.Model):
component = models.TextField(_('Component (Module / App)'))
context = JSONField(_('Context'), blank = True)
action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource'))
user = models.ForeignKey(User, verbose_name = _('Actor'))
datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True)
class Meta:
verbose_name = _('Log')
verbose_name_plural = _('Logs')
def __str__(self):
return self.component