X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/68a31d533aba7490c3f1f812075e8ab6eb9265d0..ac3d66885419d71d6e6d16080fcf09ecffa66fe9:/floof/model/art.py diff --git a/floof/model/art.py b/floof/model/art.py index 8cfcd5a..bb68c9f 100644 --- a/floof/model/art.py +++ b/floof/model/art.py @@ -1,12 +1,44 @@ -from sqlalchemy import Column, ForeignKey -from sqlalchemy.orm import relation -from sqlalchemy.types import Integer, Unicode +# +# floof/floof/model/art.py +# +# Copyright (c) 2009 Scribblr +# -from floof.model import meta +# from elixir import Entity, Field, Integer, Unicode +from elixir import * +import elixir -__all__ = ['Art'] +from pylons import config -class Art(meta.TableBase): - __tablename__ = 'art' - id = Column(Integer, primary_key=True) - title = Column(Unicode(length=120), nullable=False) +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, unique=True, required=True) + + uploader = ManyToOne('User', required=True) + tags = OneToMany('Tag') + discussion = ManyToOne('Discussion') + + user_relations = OneToMany('UserRelation') + + + 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()