be2bb9edeb72ce15e167be938ff50fab6923eff5
[zzz-floof.git] / floof / model / search.py
1 from elixir import *
2 # from users import User
3
4 from floof.lib.search import do_search
5
6 class SavedSearch(Entity):
7 string = Field(Unicode) # I tried calling this query, but it broke elixir
8 author = ManyToOne('User')
9
10 def __unicode__(self):
11 return self.string
12
13 @property
14 def results(self):
15 return do_search(self.string)
16
17
18
19 class GalleryWidget(Entity):
20 page = ManyToOne('UserPage')
21 search = ManyToOne(SavedSearch)
22
23 # NOTE: no longer needed now that we have pages, I guess.
24 # displayer = ManyToOne('User') # determines whose page should it should show up on
25 # # Could be no-ones, if it's just a template.
26
27 # Needs some fields for position on your page
28
29 @property
30 def string(self):
31 return self.search
32
33 @string.setter
34 def string(self, value):
35 # TODO: should we delete the possibly orphaned saved search?
36 # if not self.displayer:
37 # # TODO: may have to refactor this into an init if the key ordering is inconvenienc
38 # raise "Oh no! This gallery needs a displayer to set on the saved search."
39
40 self.search = SavedSearch(author=getattr(self,"author",None), string=value)
41