2 # floof/floof/model/art.py
4 # Copyright (c) 2009 Scribblr
10 from pylons
import config
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
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)
23 uploader
= ManyToOne('User', required
=True)
24 tags
= OneToMany('Tag')
25 discussion
= ManyToOne('Discussion')
27 art_users
= OneToMany('ArtUser')
31 return get_path("art", self
.hash)
34 # XXX ok these could stand to do the filtering sql-side
37 return (au
.user
for au
in self
.art_users
if au
.type == ArtUserType
.BY
)
41 return (au
.user
for au
in self
.art_users
if au
.type == ArtUserType
.FOR
)
44 def participants(self
):
45 return (au
.user
for au
in self
.art_users
if au
.type == ArtUserType
.OF
)
47 class ArtUserType(object):
52 class ArtUser(Entity
):
53 art
= ManyToOne('Art', required
=True)
54 user
= ManyToOne('User', required
=True)
55 type = Field(Integer
, required
=True) # ArtUserType
57 # TODO: admin log ought to remember who confirmed the relation.
58 # (tag history will remember who proposed it)