X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/f7617496a08f10a77eb909982dae4e995c132900..40a5c182712d31d44aeacddd16a457f5ab707de7:/floof/model/art.py diff --git a/floof/model/art.py b/floof/model/art.py index e78de41..bb68c9f 100644 --- a/floof/model/art.py +++ b/floof/model/art.py @@ -4,31 +4,41 @@ # Copyright (c) 2009 Scribblr # -from elixir import Entity, Field, Integer, Unicode +# 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 +import floof.model.comments + + +# Note: Art is the most important class. To keep its size down, and to better organize the source code, +# other modules will mix into it automatically by adding to its __bases__. class Art(Entity): title = Field(Unicode(120)) original_filename = Field(Unicode(120)) - hash = Field(String) + hash = Field(String, unique=True, required=True) - 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')) + uploader = ManyToOne('User', required=True) + tags = OneToMany('Tag') + discussion = ManyToOne('Discussion') + user_relations = OneToMany('UserRelation') - super(Art, self).__init__(**kwargs) - # this is what super is doing, pretty much. - # for key, value in kwargs.items(): - # setattr(self, key, value) - + def set_file(self, file): + self.hash = save_file("art", file) + self.original_filename = file.filename + + file = property(get_path, set_file) def get_path(self): if self.hash: return get_path("art", self.hash) + + def __unicode__(self): + return self.get_path()