import random
import re
import types
+from urllib import urlencode
import uuid
from xml.sax import saxutils
recipe = random.choice(self.cookbook)
else:
recipe = self.cookbook.index[name]
+ tag_links = [
+ '<a href="./?%s">%s</a>' % (urlencode({'tag':t}), t)
+ for t in (recipe.tags or [])]
template = self.env.get_template('recipe.html')
- return template.render(cookbook=self.cookbook, recipe=recipe)
+ return template.render(cookbook=self.cookbook, recipe=recipe,
+ tag_links=tag_links)
@cherrypy.expose
def add_tag(self, name, tag):
def edit(self, name=None, **kwargs):
"""Remove a tag from a single recipe."""
name,recipe,action = self._normalize_edit_params(name, **kwargs)
- if action.startswith('edit'):
+ if action == 'remove':
+ recipe = self.cookbook.index[name]
+ os.remove(recipe.path)
+ self.cookbook.remove(recipe)
+ self.cookbook.make_index()
+ raise cherrypy.HTTPRedirect(u'.', status=302)
+ elif action.startswith('edit'):
self._update_recipe(name, recipe)
if action == 'edit and redirect': # done editing this recipe
raise cherrypy.HTTPRedirect(
print 'new'
self.cookbook.append(recipe)
self.cookbook.make_index()
+ self.cookbook.sort(key=lambda r: r.path)
elif name != recipe.name: # renamed recipe
print 'rename'
os.remove(recipe.path)
m = regexp.match(key)
if m != None:
handler = getattr(self, '_action_%s' % k)
- action = handler(recipe, action, value, *m.groups(),
- ingredient_block_map=ingredient_block_map,
- ingredient_map=ingredient_map)
+ kws = {'ingredient_block_map': ingredient_block_map,
+ 'ingredient_map': ingredient_map}
+ action = handler(recipe, action, value, *m.groups(), **kws)
break
# button updates
action = kwargs.get('action', action)
m = regexp.match(action)
if m != None:
handler = getattr(self, '_action_%s' % a)
- action = handler(recipe, action, *m.groups(),
- ingredient_block_map=ingredient_block_map,
- ingredient_map=ingredient_map)
+ kws = {'ingredient_block_map': ingredient_block_map,
+ 'ingredient_map': ingredient_map}
+ action = handler(recipe, action, *m.groups(), **kws)
break
return (name, recipe, action)