recipe = self.cookbook.index[name]
template = self.env.get_template('recipe.html')
return template.render(cookbook=self.cookbook, recipe=recipe)
-#
-# @cherrypy.expose
-# def create(self, summary):
-# """The view that handles the creation of a new bug."""
-# if summary.strip() != '':
-# bugdir = self.storage_callbacks.get_bugdir()
-# bugdir.new_bug(summary=summary)
-# self.commit(u"Created bug: %s" % summary)
-# raise cherrypy.HTTPRedirect('/', status=302)
-#
-# @cherrypy.expose
-# def comment(self, id, body):
-# """The view that handles adding a comment."""
-# if body.strip() != '':
-# bugdir = self.storage_callbacks.get_bugdir()
-# bug = bugdir.bug_from_uuid(id)
-# bug.comment_root.new_reply(body=body)
-# self.commit(u"Added reply Re: %s" % bug.summary)
-# raise cherrypy.HTTPRedirect('/bug?id=%s' % (bug.uuid,), status=302)
-# raise cherrypy.HTTPRedirect('/', status=302)
-#
-# @cherrypy.expose
-# def edit(self, id, status=None, target=None, assignee=None, severity=None, summary=None):
-# """The view that handles editing bug details."""
-# bugdir = self.storage_callbacks.get_bugdir()
-# bug = bugdir.bug_from_uuid(id)
-#
-# if summary != None:
-# old_summary = bug.summary
-# bug.summary = summary
-# self.bd.vcs.commit("Changed bug summary: %s -> %s" % (old_summary, bug.summary))
-# else:
-# bug.status = status if status != 'None' else None
-# if target != 'None':
-# libbe.target.add_target(bugdir, bug, target)
-# bug.assigned = assignee if assignee != 'None' else None
-# bug.severity = severity if severity != 'None' else None
-# self.bd.vcs.commit("Changed bug values: %s" % bug.summary)
-#
-# raise cherrypy.HTTPRedirect('/bug?id=%s' % (bug.uuid,), status=302)
+
+ @cherrypy.expose
+ def add_tag(self, name, tag):
+ """Add a tag to a single recipe."""
+ if type(name) == types.StringType:
+ name = unicode(name, encoding='utf-8')
+ recipe = self.cookbook.index[name]
+ if recipe.tags == None:
+ recipe.tags = []
+ if tag not in recipe.tags:
+ recipe.tags.append(tag)
+ with open(recipe.path, 'w') as f:
+ recipe.save(f)
+ raise cherrypy.HTTPRedirect(
+ 'recipe?name=%s' % recipe.clean_name(), status=302)
+
+ @cherrypy.expose
+ def remove_tag(self, name, tag):
+ """Remove a tag from a single recipe."""
+ if type(name) == types.StringType:
+ name = unicode(name, encoding='utf-8')
+ recipe = self.cookbook.index[name]
+ if recipe.tags == None:
+ return
+ if tag in recipe.tags:
+ recipe.tags.remove(tag)
+ with open(recipe.path, 'w') as f:
+ recipe.save(f)
+ raise cherrypy.HTTPRedirect(
+ 'recipe?name=%s' % recipe.clean_name(), status=302)
+
def test():
import doctest
<span class="detail-field-header">Source:</span>
<span class="detail-field-contents">{{ recipe.source }}</span><br />
{% endif %}
+ {% if recipe.tags %}
+ <span class="detail-field-header">Tags:</span>
+ <span class="detail-field-contents">{{ ', '.join(recipe.tags) }}
+ </span><br />
+ {% endif %}
+ </p>
+ <form action="add_tag" method="get">
+ <input type="hidden" name="name" value="{{ recipe.name }}"/>
+ <input type="text" name="tag" value=""/>
+ <input type="submit" value="Add tag" />
+ </form>
+ <form action="remove_tag" method="get">
+ <input type="hidden" name="name" value="{{ recipe.name }}"/>
+ <input type="text" name="tag" value=""/>
+ <input type="submit" value="Remove tag" />
+ </form>
<div id="recipe-ingredient-blocks">
{% for ingredient_block in recipe.ingredient_blocks %}