forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
80 lines (69 loc) · 3.29 KB
/
Copy pathmodels.py
File metadata and controls
80 lines (69 loc) · 3.29 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
# Copyright The IETF Trust 2007, All Rights Reserved
from django.db import models
from redesign.name.models import *
from redesign.person.models import Email
import datetime
class Group(models.Model):
name = models.CharField(max_length=80)
acronym = models.CharField(max_length=16, db_index=True)
state = models.ForeignKey(GroupStateName, null=True)
type = models.ForeignKey(GroupTypeName, null=True)
charter = models.OneToOneField('doc.Document', related_name='chartered_group', blank=True, null=True)
parent = models.ForeignKey('Group', blank=True, null=True)
list_email = models.CharField(max_length=64, blank=True)
list_pages = models.CharField(max_length=64, blank=True)
comments = models.TextField(blank=True)
def __unicode__(self):
return self.name
def latest_event(self, *args, **filter_args):
"""Get latest group event with filter arguments, e.g.
d.latest_event(type="xyz")."""
e = GroupEvent.objects.filter(group=self).filter(**filter_args).order_by('-time', '-id')[:1]
return e[0] if e else None
GROUP_EVENT_CHOICES = [("proposed", "Proposed group"),
("started", "Started group"),
("concluded", "Concluded group"),
]
class GroupEvent(models.Model):
"""An occurrence for a group, used for tracking who, when and what."""
group = models.ForeignKey(Group)
time = models.DateTimeField(default=datetime.datetime.now, help_text="When the event happened")
type = models.CharField(max_length=50, choices=GROUP_EVENT_CHOICES)
by = models.ForeignKey(Email)
desc = models.TextField()
def __unicode__(self):
return u"%s %s at %s" % (self.by.get_name(), self.get_type_display().lower(), self.time)
class Meta:
ordering = ['-time', 'id']
# This will actually be extended from Groups, but that requires Django 1.0
# This will record the new state and the date it occurred for any changes
# to a group. The group acronym must be unique and is the invariant used
# to select group history from this table.
class GroupHistory(models.Model):
group = models.ForeignKey('Group', related_name='group_history')
# Event related
time = models.DateTimeField()
comment = models.TextField()
who = models.ForeignKey(Email, related_name='group_changes')
# inherited from Group:
name = models.CharField(max_length=64)
acronym = models.CharField(max_length=16)
state = models.ForeignKey(GroupStateName)
type = models.ForeignKey(GroupTypeName)
charter = models.ForeignKey('doc.Document', related_name='chartered_group_history')
parent = models.ForeignKey('Group')
chairs = models.ManyToManyField(Email, related_name='chaired_groups_history')
list_email = models.CharField(max_length=64)
list_pages = models.CharField(max_length=64)
comments = models.TextField(blank=True)
def __unicode__(self):
return self.group.name
class Meta:
verbose_name_plural="Doc histories"
class Role(models.Model):
name = models.ForeignKey(RoleName)
group = models.ForeignKey(Group)
email = models.ForeignKey(Email)
auth = models.CharField(max_length=255, blank=True)
def __unicode__(self):
return u"%s is %s in %s" % (self.email.get_name(), self.name.name, self.group.acronym)