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'})
# 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.
--- /dev/null
+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()
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):
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
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.
# 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
# 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
+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()
# 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')
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
uploads = OneToMany('Art')
has_many('identity_urls', of_kind='IdentityURL')
searches = OneToMany('SavedSearch')
+ galleries = OneToMany('GalleryWidget')
def __unicode__(self):
return self.name
.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 */
<div id="user">
% if c.user:
<form action="${url(controller='account', action='logout')}" method="POST">
- <p>Logged in as ${c.user.name}. ${h.submit(None, 'Log out')}</p>
+ <p>Logged in as <a href="${h.url('user_page', name=c.user.name)}">${c.user.name}</a>. ${h.submit(None, 'Log out')}</p>
</form>
% else:
<form action="${url(controller='account', action='login_begin')}" method="POST">
<%inherit file="base.mako" />
+<%namespace name="macros" file="/macros.mako" />
-
-<ul class="artwork-grid">
- % for artwork in c.artwork:
- <li><a href="${h.url("art", id=artwork.id)}">
- <img width="180" src="${artwork.get_path()}">
- </a></li>
- % endfor
-</ul>
+${macros.thumbs(c.artwork)}
--- /dev/null
+<%def name="thumbs(art)">
+ <ul class="artwork-grid">
+ % for item in art:
+ <li>
+ <a href="${h.url("art", id=item.id)}">
+ <img width="180" src="${item.get_path()}">
+ </a>
+ </li>
+ % endfor
+ </ul>
+</%def>
\ No newline at end of file
<%inherit file="/base.mako" />
+<%namespace name="macros" file="/macros.mako" />
<p>This is the userpage for ${c.this_user.name}.</p>
+
+% for gallery in c.this_user.galleries:
+<h2>${gallery.string}</h2>
+${macros.thumbs(gallery.search.results)}
+% endfor
\ No newline at end of file
--- /dev/null
+from floof.tests import *
+
+class TestGalleryController(TestController):
+
+ def test_index(self):
+ response = self.app.get(url(controller='gallery', action='index'))
+ # Test response...