saved searches is going awesome. Partial work on adding them as galleries
[zzz-floof.git] / floof / model / search.py
diff --git a/floof/model/search.py b/floof/model/search.py
new file mode 100644 (file)
index 0000000..011468c
--- /dev/null
@@ -0,0 +1,30 @@
+from elixir import *
+from users import User
+
+class SavedSearch(Entity):
+    string = Field(Unicode) # I tried calling this query, but it broke elixir
+    author = ManyToOne(User)
+    
+    def __unicode__(self):
+        return self.string
+
+
+class GalleryWidget(Entity):
+    search = ManyToOne(SavedSearch)
+    displayer = ManyToOne(User) # determines whose page should it should show up on
+                                # Could be no-ones, if it's just a template.
+    
+    # Needs some fields for position on your page
+
+    @property
+    def query(self):
+        return self.search.query
+    
+    @query.setter
+    def query(self, value):
+        # TODO: should we delete the possibly orphaned saved search?
+        if not self.displayer:
+            # TODO: may have to refactor this into an init if the key ordering is inconvenienc
+            raise "Oh no!  This gallery needs a displayer to set on the saved search."
+        
+        self.search = SavedSearch(author=self.displayer, query=value)
\ No newline at end of file