X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/6fb3ad2a578aa2e0eced735187a02a79a8907668..03c8b0becd6264301a64e9201588c60c9b588ad1:/floof/model/search.py diff --git a/floof/model/search.py b/floof/model/search.py index 011468c..7e04ae7 100644 --- a/floof/model/search.py +++ b/floof/model/search.py @@ -1,30 +1,48 @@ from elixir import * -from users import User +# from users import User + class SavedSearch(Entity): string = Field(Unicode) # I tried calling this query, but it broke elixir - author = ManyToOne(User) - + author = ManyToOne('User') + fork = ManyToOne("SavedSearch") + def __unicode__(self): return self.string + class GalleryWidget(Entity): + page = ManyToOne('UserPage') 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. + 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 query(self): - return self.search.query - - @query.setter - def query(self, value): + def string(self): + 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=self.displayer, query=value) \ No newline at end of file + # 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)