Merged add_tags and lib.search into lib.tags.
[zzz-floof.git] / floof / model / art.py
index 8cfcd5a..0452e32 100644 (file)
@@ -1,12 +1,58 @@
-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 *
+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
+from floof.model.users import User
+
+
+class Art(Entity):
+    title = Field(Unicode(120))
+    original_filename = Field(Unicode(120))
+    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)
+
+    @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)
+
+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
+
+    # TODO: admin log ought to remember who confirmed the relation.
+    #       (tag history will remember who proposed it)