merged. Oh no, we have two different user relationship models. Mine's in relations...
[zzz-floof.git] / floof / model / relations.py
1 from elixir import *
2 from art import Art
3
4
5 class UserRelation(Entity):
6 user = ManyToOne("User")
7 art = ManyToOne("Art")
8 kind = Field(String) # by for of
9 creator = ManyToOne("User")
10 confirmed_by_related_user = Field(Boolean)
11
12 # it is useful to record which authority figure on a given artwork
13 # confirmed the validity of this relation.
14 confirmed_by_authority = ManyToOne("User")
15
16 def __init__(self, **kwargs):
17 super(UserRelation, self).__init__(**kwargs)
18 assert self.user and self.art and self.kind and self.creator
19
20 if self.creator == self.user:
21 self.confirmed_by_related_user = True
22 # TODO: implement authorities
23 # if self.creator in self.art.authorities
24 # self.confirmed_by_authority = self.creator
25
26 def __unicode__(self):
27 return "%s: %s" % (self.kind, self.related_user)
28
29
30 class RelationMixin(object):
31 def add_relation(creator, kind, user):
32 return UserRelation(art=self, creator=creator, kind=kind, user=user)
33
34 Art.__bases__ += (RelationMixin,)