From: Nick Retallack Date: Wed, 7 Oct 2009 03:27:45 +0000 (-0700) Subject: displaying galleries on your page works X-Git-Url: http://git.veekun.com/zzz-floof.git/commitdiff_plain/332de9696e2cca102332d5543adad9b289c35214?hp=-c displaying galleries on your page works --- 332de9696e2cca102332d5543adad9b289c35214 diff --git a/floof/config/routing.py b/floof/config/routing.py index 9c3da14..7f46a2c 100644 --- a/floof/config/routing.py +++ b/floof/config/routing.py @@ -42,7 +42,7 @@ def make_map(): 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('user_page', '/users/{name}', controller='users', action='view') # Art stuff art = map.resource('art','art', controller="art", member={'rate':'PUT'}) @@ -77,7 +77,8 @@ def make_map(): # map.connect('/tag/{id}/delete', controller='tag', action='delete') map.connect('search', '/search', controller='search', action='index') - map.connect('/search/list', controller='search', action='list') + # map.connect( '/search/{query}', controller='search', action='index') + map.connect('saved_searches', '/search/list', controller='search', action='list') # default routing is back so we can test stuff. diff --git a/floof/controllers/gallery.py b/floof/controllers/gallery.py new file mode 100644 index 0000000..e923e30 --- /dev/null +++ b/floof/controllers/gallery.py @@ -0,0 +1,17 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, h +from pylons.controllers.util import abort, redirect +from pylons import url + +from floof.lib.base import BaseController, render + +log = logging.getLogger(__name__) +import elixir +from floof.model.search import GalleryWidget +class GalleryController(BaseController): + + def delete(self, id): + c.gallery = h.get_object_or_404(GalleryWidget, id=id) + elixir.session.delete(tag) + elixir.session.commit() diff --git a/floof/controllers/search.py b/floof/controllers/search.py index 3b6faef..e27e5c8 100644 --- a/floof/controllers/search.py +++ b/floof/controllers/search.py @@ -1,14 +1,16 @@ import logging from pylons import request, response, session, tmpl_context as c, h -from pylons.controllers.util import abort, redirect_to +from pylons.controllers.util import abort, redirect +from pylons import url from floof.lib.base import BaseController, render +from floof.lib.search import do_search log = logging.getLogger(__name__) from floof.model.art import Art, Tag, TagText -from floof.model.search import SavedSearch +from floof.model.search import SavedSearch, GalleryWidget import elixir class SearchController(BaseController): @@ -18,16 +20,7 @@ class SearchController(BaseController): return self.save() c.query = request.params.get('query', '') - tags = c.query.split() - - tagtexts = TagText.query.filter(TagText.text.in_(tags)) - tagtext_ids = [_.id for _ in tagtexts] - - # Fetch art that has all the tags - c.artwork = Art.query.join(Tag) \ - .filter(Tag.tagtext_id.in_(tagtext_ids)) \ - .all() - + c.artwork = do_search(c.query) return render('/index.mako') # TODO: login required @@ -35,7 +28,7 @@ class SearchController(BaseController): c.query = request.params.get('query', '') saved_search = SavedSearch(author=c.user, string=c.query) elixir.session.commit() - redirect_to(action="list") + redirect(url('saved_searches')) # TODO: do something better than this. @@ -47,9 +40,9 @@ class SearchController(BaseController): # TODO: login required def display(self, id): c.search = h.get_object_or_404(SavedSearch, id=id) - # TODO: create a gallery widget - - redirect_to(controller="users", action="view", name=c.user.name) + c.gallery = GalleryWidget(search=c.search, displayer=c.user) + elixir.session.commit() + redirect(url(controller="users", action="view", name=c.user.name)) \ No newline at end of file diff --git a/floof/controllers/tag.py b/floof/controllers/tag.py index d8e46f3..ef3c7ce 100644 --- a/floof/controllers/tag.py +++ b/floof/controllers/tag.py @@ -15,10 +15,9 @@ class TagController(BaseController): # TODO: login required def delete(self, art_id, id): - tag = Tag.get(id) - if tag: - elixir.session.delete(tag) - elixir.session.commit() + tag = h.get_object_or_404(Tag, id=id) + elixir.session.delete(tag) + elixir.session.commit() redirect(url('art', id=art_id)) # TODO: login required diff --git a/floof/lib/search.py b/floof/lib/search.py index 3acb248..f7ce65b 100644 --- a/floof/lib/search.py +++ b/floof/lib/search.py @@ -1,3 +1,23 @@ +from floof.model.art import Art, Tag, TagText + +def do_search(query): + tags = query.split() + + tagtexts = TagText.query.filter(TagText.text.in_(tags)) + tagtext_ids = [_.id for _ in tagtexts] + + # Fetch art that has all the tags + artwork = Art.query.join(Tag) \ + .filter(Tag.tagtext_id.in_(tagtext_ids)) \ + .all() + return artwork + + + + + + +# unfinished stuff def parse(query): words = query.split() @@ -18,16 +38,6 @@ def parse(query): # 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) - # 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 --git a/floof/model/search.py b/floof/model/search.py index 011468c..e812afc 100644 --- a/floof/model/search.py +++ b/floof/model/search.py @@ -1,30 +1,42 @@ from elixir import * -from users import User +# 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) + author = ManyToOne('User') def __unicode__(self): return self.string + + @property + def results(self): + return do_search(self.string) + class GalleryWidget(Entity): search = ManyToOne(SavedSearch) - displayer = ManyToOne(User) # determines whose page should it should show up on + 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 + def string(self): + return self.search - @query.setter - def query(self, value): + @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 + self.search = SavedSearch(author=self.displayer, string=value) + + +# class UserPage(Entity): +# owner = ManyToOne('User') +# visible = Field(Boolean) \ No newline at end of file diff --git a/floof/model/users.py b/floof/model/users.py index 5c9783e..d4a679a 100644 --- a/floof/model/users.py +++ b/floof/model/users.py @@ -12,6 +12,7 @@ class User(Entity): uploads = OneToMany('Art') has_many('identity_urls', of_kind='IdentityURL') searches = OneToMany('SavedSearch') + galleries = OneToMany('GalleryWidget') def __unicode__(self): return self.name diff --git a/floof/public/layout.css b/floof/public/layout.css index 25737d0..a098b5e 100644 --- a/floof/public/layout.css +++ b/floof/public/layout.css @@ -10,6 +10,9 @@ body { font-family: sans-serif; font-size: 12px; } .full {display:block;} + +.artwork-grid li {display:inline;} + /*** Common bits and pieces ***/ /* General form layout */ a {color:blue; text-decoration:none; pointer:cursor;} /* Who needs visited links */ diff --git a/floof/templates/base.mako b/floof/templates/base.mako index 13126f7..7290a11 100644 --- a/floof/templates/base.mako +++ b/floof/templates/base.mako @@ -32,7 +32,7 @@ ${h.end_form()}
% if c.user:
-

Logged in as ${c.user.name}. ${h.submit(None, 'Log out')}

+

Logged in as ${c.user.name}. ${h.submit(None, 'Log out')}

% else:
diff --git a/floof/templates/index.mako b/floof/templates/index.mako index 8ee86e6..a774551 100644 --- a/floof/templates/index.mako +++ b/floof/templates/index.mako @@ -1,10 +1,4 @@ <%inherit file="base.mako" /> +<%namespace name="macros" file="/macros.mako" /> - -
    - % for artwork in c.artwork: -
  • - -
  • - % endfor -
+${macros.thumbs(c.artwork)} diff --git a/floof/templates/macros.mako b/floof/templates/macros.mako new file mode 100644 index 0000000..5633e5b --- /dev/null +++ b/floof/templates/macros.mako @@ -0,0 +1,11 @@ +<%def name="thumbs(art)"> +
    + % for item in art: +
  • + + + +
  • + % endfor +
+ \ No newline at end of file diff --git a/floof/templates/users/view.mako b/floof/templates/users/view.mako index 9f39bae..d128276 100644 --- a/floof/templates/users/view.mako +++ b/floof/templates/users/view.mako @@ -1,3 +1,9 @@ <%inherit file="/base.mako" /> +<%namespace name="macros" file="/macros.mako" />

This is the userpage for ${c.this_user.name}.

+ +% for gallery in c.this_user.galleries: +

${gallery.string}

+${macros.thumbs(gallery.search.results)} +% endfor \ No newline at end of file diff --git a/floof/tests/functional/test_gallery.py b/floof/tests/functional/test_gallery.py new file mode 100644 index 0000000..695513c --- /dev/null +++ b/floof/tests/functional/test_gallery.py @@ -0,0 +1,7 @@ +from floof.tests import * + +class TestGalleryController(TestController): + + def test_index(self): + response = self.app.get(url(controller='gallery', action='index')) + # Test response...