Rearranged user/art relations.
[zzz-floof.git] / floof / model / art.py
1 #
2 # floof/floof/model/art.py
3 #
4 # Copyright (c) 2009 Scribblr
5 #
6
7 from elixir import *
8 import elixir
9
10 from pylons import config
11
12 from floof.lib.file_storage import get_path, save_file
13 from floof.lib.dbhelpers import find_or_create, update_or_create
14 from floof.model.users import User
15
16
17 class Art(Entity):
18 title = Field(Unicode(120))
19 original_filename = Field(Unicode(120))
20 hash = Field(Unicode(40), unique=True, required=True)
21 mimetype = Field(Unicode(32), required=True)
22
23 uploader = ManyToOne('User', required=True)
24 tags = OneToMany('Tag')
25 discussion = ManyToOne('Discussion')
26
27 art_users = OneToMany('ArtUser')
28
29 @property
30 def file_path(self):
31 return get_path("art", self.hash)
32
33 # Associated users
34 # XXX ok these could stand to do the filtering sql-side
35 @property
36 def artists(self):
37 return (au.user for au in self.art_users if au.type == ArtUserType.BY)
38
39 @property
40 def recipients(self):
41 return (au.user for au in self.art_users if au.type == ArtUserType.FOR)
42
43 @property
44 def participants(self):
45 return (au.user for au in self.art_users if au.type == ArtUserType.OF)
46
47
48 class ArtUserType(object):
49 BY = 1
50 FOR = 2
51 OF = 3
52
53 class ArtUser(Entity):
54 art = ManyToOne('Art', required=True)
55 user = ManyToOne('User', required=True)
56 type = Field(Integer, required=True) # ArtUserType
57
58 # TODO: admin log ought to remember who confirmed the relation.
59 # (tag history will remember who proposed it)