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