X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/f7617496a08f10a77eb909982dae4e995c132900..d2cfab09f98980d5c1d433a9e75eb65e0b13b0aa:/floof/model/art.py?ds=inline diff --git a/floof/model/art.py b/floof/model/art.py index e78de41..0452e32 100644 --- a/floof/model/art.py +++ b/floof/model/art.py @@ -4,31 +4,55 @@ # Copyright (c) 2009 Scribblr # -from elixir import Entity, Field, Integer, Unicode from elixir import * +import elixir from pylons import config from floof.lib.file_storage import get_path, save_file +from floof.lib.dbhelpers import find_or_create, update_or_create +from floof.model.users import User + class Art(Entity): title = Field(Unicode(120)) original_filename = Field(Unicode(120)) - hash = Field(String) + hash = Field(Unicode(40), unique=True, required=True) + mimetype = Field(Unicode(32), required=True) + + uploader = ManyToOne('User', required=True) + tags = OneToMany('Tag') + discussion = ManyToOne('Discussion') + + art_users = OneToMany('ArtUser') + + @property + def file_path(self): + return get_path("art", self.hash) + + # Associated users + # XXX ok these could stand to do the filtering sql-side + @property + def artists(self): + return (au.user for au in self.art_users if au.type == ArtUserType.BY) - def __init__(self, **kwargs): - # I wanted to check for the existence of the file, but... - # for some reason this FieldStorage object always conditions as falsey. - self.hash = save_file("art", kwargs.pop('file')) + @property + def recipients(self): + return (au.user for au in self.art_users if au.type == ArtUserType.FOR) + @property + def participants(self): + return (au.user for au in self.art_users if au.type == ArtUserType.OF) - super(Art, self).__init__(**kwargs) - # this is what super is doing, pretty much. - # for key, value in kwargs.items(): - # setattr(self, key, value) - +class ArtUserType(object): + BY = 1 + FOR = 2 + OF = 3 +class ArtUser(Entity): + art = ManyToOne('Art', required=True) + user = ManyToOne('User', required=True) + type = Field(Integer, required=True) # ArtUserType - def get_path(self): - if self.hash: - return get_path("art", self.hash) + # TODO: admin log ought to remember who confirmed the relation. + # (tag history will remember who proposed it)