From: Nick Retallack Date: Mon, 5 Oct 2009 17:37:50 +0000 (-0700) Subject: fixed search query (awesome now thanks vee =]), tag links, default routing is back... X-Git-Url: http://git.veekun.com/zzz-floof.git/commitdiff_plain/55270a42bf0699bd78b95a945fddd73a165507ee?ds=inline fixed search query (awesome now thanks vee =]), tag links, default routing is back for now, merged in ratings. Tested stuff out, works nicely. This should be the definitive copy. --- 55270a42bf0699bd78b95a945fddd73a165507ee diff --cc floof/config/routing.py index 37be4c2,f78246a..32093bb --- a/floof/config/routing.py +++ b/floof/config/routing.py @@@ -25,13 -25,8 +25,18 @@@ def make_map() map.connect('/account/login', controller='account', action='login') map.connect('/account/login_begin', controller='account', action='login_begin', **require_POST) map.connect('/account/login_finish', controller='account', action='login_finish') + map.connect('/account/logout', controller='account', action='logout', **require_POST) + map.connect('/account/register', controller='account', action='register') + map.connect('/account/register_finish', controller='account', action='register_finish', **require_POST) + map.connect('/users', controller='users', action='list') + map.connect('/users/{name}', controller='users', action='view') + + map.connect('/search', controller='search', action='index') + ++ # default routing is back so we can test stuff. ++ # please don't take it away until we have some more core features in. + map.connect('/{controller}/{action}') + map.connect('/{controller}/{action}/{id}') + return map diff --cc floof/controllers/search.py index 88dfbe3,5240a0b..abedd16 --- a/floof/controllers/search.py +++ b/floof/controllers/search.py @@@ -13,16 -13,43 +13,16 @@@ import elixi class SearchController(BaseController): def index(self): - # Return a rendered template - #return render('/search.mako') - # or, return a response - return 'Hello World' - - def results(self): - """ Search, implemented the stupid way! """ - query = request.params.get('query','') - words = query.split() + """Search, implemented the stupid way!""" + query = request.params.get('query', '') + tags = query.split() - + - tags = [] - for word in words: - components = word.split(':') - if len(components) == 1: - # tags are plain. - tags.append(word) - elif components[0] == "rating": - if components[1].isnumeric(): - score = int(components[1]) - else: - score = Rating.reverse_options.get(components[1]) - - if -1 <= score <= 3: - pass - # TODO: Find stuff that has this rating - # Rating.query.filter(Rating.s) - - - - tagtexts = TagText.query.filter(TagText.text.in_(tags)) - tagtext_ids = map(lambda x:x.id, tagtexts) + tagtext_ids = [_.id for _ in tagtexts] + + # Fetch art that has all the tags + c.artwork = Art.query.join(Tag) \ - .filter(Tag.id.in_(tagtext_ids)) \ ++ .filter(Tag.tagtext_id.in_(tagtext_ids)) \ + .all() - return render('/index.mako') - # TODO: this is wrong. Please fix it so it returns art that has all the tags. - art_tag_pairs = elixir.session.query(Art,Tag).filter(Art.id == Tag.art_id).\ - filter(Tag.tagtext_id.in_(tagtext_ids)).all() - - # just the art please. - c.artwork = map(lambda x: x[0], art_tag_pairs) + return render('/index.mako') diff --cc floof/model/art.py index 58601a7,7d93e6b..6fd2036 --- a/floof/model/art.py +++ b/floof/model/art.py @@@ -11,9 -11,9 +11,8 @@@ import elixi from pylons import config from floof.lib.file_storage import get_path, save_file - from floof.lib.dbhelpers import find_or_create - + from floof.lib.dbhelpers import find_or_create, update_or_create - class Art(Entity): title = Field(Unicode(120)) original_filename = Field(Unicode(120)) @@@ -57,8 -57,8 +56,6 @@@ raise "Long Tag!" # can we handle this more gracefully? # sqlite seems happy to store strings much longer than the supplied limit... -- -- # elixir should really have its own find_or_create. tagtext = find_or_create(TagText, text=text) tag = find_or_create(Tag, art=self, tagger=user, tagtext=tagtext) @@@ -92,6 -103,19 +100,19 @@@ class Tag(Entity) class TagText(Entity): text = Field(Unicode(50)) # gotta enforce this somehow tags = OneToMany('Tag') - + def __unicode__(self): - return self.text + return self.text + + + class Rating(Entity): + art = ManyToOne('Art', ondelete='cascade') + rater = ManyToOne('User', ondelete='cascade') + score = Field(Integer) + + options = {-1:"sucks", 0:"undecided", 1:"good", 2:"great"} + default = 0 + # options = ["sucks","neutral","good","great"] + + + Rating.reverse_options = dict (zip(Rating.options.values(), Rating.options.keys())) diff --cc floof/public/layout.css index f6e671f,e32995e..74a3c05 --- a/floof/public/layout.css +++ b/floof/public/layout.css @@@ -9,15 -6,4 +9,14 @@@ body { font-family: sans-serif; font-si #footer { padding: 1em; background: #c0c0c0; } .full {display:block;} -.selected {color:red;} + - - +/*** Common bits and pieces ***/ +/* General form layout */ +dl.form { margin: 1em 0; padding-left: 1em; border-left: 0.5em solid gray; } +dl.form dt { padding-bottom: 0.25em; font-style: italic; } +dl.form dd { margin-bottom: 0.5em; } + + + +/*** Individual page layout ***/ ++.selected {color:red;} diff --cc floof/templates/art/show.mako index d77f364,f2320fd..fc0a3f8 --- a/floof/templates/art/show.mako +++ b/floof/templates/art/show.mako @@@ -9,9 -11,17 +11,17 @@@ ${h.end_form() % for tag in c.art.tags: x --${tag} ++${tag} % endfor + What do you think? + % for score,text in sorted(Rating.options.items()): + ${text} + % endfor