def make_map():
"""Create, configure and return the routes Mapper"""
map = Mapper(directory=config['pylons.paths']['controllers'],
- always_scan=config['debug'])
+ always_scan=config['debug'], explicit=True)
map.minimization = False
+ # explicit = True disables a broken feature called "route memory",
+ # where it adds everything matched in the current request as default variables
+ # for the next one. This is wrong because it doesn't invalidate things lower down in
+ # the hierarchy when higher up things change. Rails port failure.
+ # NOTE: this also disables actions defaulting to index, sorry.
require_POST = dict(conditions={'method': ['POST']})
# Art stuff
map.connect('/art/new', controller='art', action='new')
map.connect('/art/upload', controller='art', action='upload')
- map.connect('/art/{id}', controller='art', action='show')
+ map.connect('show_art', '/art/{id}', controller='art', action='show')
map.connect('/art/{id}/tag', controller='art', action='tag')
map.connect('/tag/{id}/delete', controller='tag', action='delete')
- map.connect('/search', controller='search', action='index')
+ map.connect('search', '/search', controller='search', action='index')
map.connect('/search/list', controller='search', action='list')
from floof.model.art import Art
class ArtController(BaseController):
+ def __before__(self, id=None):
+ super(ArtController, self).__before__()
+ # Awesome refactoring!
+ if id:
+ c.art = h.get_object_or_404(Art, id=id)
# def index():
# c.artwork = Art.query.order_by(Art.id.desc()).all()
""" New Art! """
return render("/art/new.mako")
-
+ # TODO: login required
def upload(self):
- print "PARAMS", request.params
Art(uploaded_by=c.user, **request.params)
elixir.session.commit()
redirect_to(controller="main", action="index")
def show(self, id):
- c.art = h.get_object_or_404(Art, id=id)
+ # c.art = h.get_object_or_404(Art, id=id)
if c.user:
c.your_score = c.art.user_score(c.user)
return render("/art/show.mako")
# TODO: login required
def tag(self, id):
- c.art = h.get_object_or_404(Art, id=id)
+ # c.art = h.get_object_or_404(Art, id=id)
c.art.add_tags(request.params["tags"], c.user)
elixir.session.commit()
- redirect_to(action="show", id=c.art.id)
+ redirect_to('show_art', id=c.art.id)
# TODO: login required
def rate(self, id):
- c.art = h.get_object_or_404(Art, id=id)
+ # c.art = h.get_object_or_404(Art, id=id)
c.art.rate(request.params["score"], c.user)
elixir.session.commit()
- redirect_to(action="show", id=c.art.id)
+ redirect_to('show_art', id=c.art.id)
class BaseController(WSGIController):
# NOTE: This could have been implemented as a middleware =]
- def __before__(self, action, **params):
+ def __before__(self):
# Fetch current user object
try:
c.user = User.query.get(session['user_id'])
## | <a href="${h.url_for("/users/"+c.user}">Your Page</a>
% endif
-${h.form(h.url_for(controller='search'), method='GET')}
+${h.form(h.url_for('search'), method='GET')}
${h.text('query', c.query)}
${h.submit('button', 'Search')}