Added a bunch of NOT NULLs.
[zzz-floof.git] / floof / model / search.py
index be2bb9e..598999d 100644 (file)
@@ -1,41 +1,48 @@
 from elixir import *
 # from users import User
 
-from floof.lib.search import do_search
 
 class SavedSearch(Entity):
-    string = Field(Unicode) # I tried calling this query, but it broke elixir
-    author = ManyToOne('User')
-    
+    string = Field(Unicode, required=True)
+    author = ManyToOne('User', required=True)
+    fork = ManyToOne("SavedSearch", required=True)
+
     def __unicode__(self):
         return self.string
-        
-    @property
-    def results(self):
-        return do_search(self.string)
 
 
 
 class GalleryWidget(Entity):
-    page = ManyToOne('UserPage')
-    search = ManyToOne(SavedSearch)
+    page = ManyToOne('UserPage', required=True)
+    search = ManyToOne(SavedSearch, required=True)
+    
+    def __init__(self, string=None, **kwargs):
+        owner = kwargs.get('owner', None)
+        if string:
+            self.search = SavedSearch(author=owner, string=string)
+        
+        page = kwargs.get('page', None)
+        if owner and not page:
+            page = author.primary_page
+        
+        super(GalleryWidget, self).__init__(**kwargs)
+
 
     # NOTE: no longer needed now that we have pages, I guess.
     # 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 string(self):
-        return self.search
-    
+        return self.search.string
+
     @string.setter
     def string(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=getattr(self,"author",None), string=value)
-        
\ No newline at end of file
+
+        self.search = SavedSearch(author=getattr(self, "author", None), string=value)