3 """Serve cookbooks over HTTP.
9 from xml.sax import saxutils
12 from jinja2 import Environment, FileSystemLoader
15 class Server (object):
16 """Cookbook web interface."""
18 def __init__(self, cookbook, template_root):
19 self.cookbook = cookbook
20 self.cookbook.make_index()
21 self.env = Environment(loader=FileSystemLoader(template_root))
24 #self.cookbook.save('new-recipe')
28 def index(self, status='open', assignee='all', target='all'):
31 Recipes can be filtered or sorted using a variety of criteria.
33 template = self.env.get_template('recipes.html')
34 return template.render(cookbook=self.cookbook,
35 recipes=list(self.cookbook))
38 def recipe(self, name=None):
39 """Single recipe page.
42 recipe = random.choice(self.cookbook)
44 if type(name) == types.StringType:
45 name = unicode(name, encoding='utf-8')
46 recipe = self.cookbook.index[name]
47 template = self.env.get_template('recipe.html')
48 return template.render(cookbook=self.cookbook, recipe=recipe)
51 # def create(self, summary):
52 # """The view that handles the creation of a new bug."""
53 # if summary.strip() != '':
54 # bugdir = self.storage_callbacks.get_bugdir()
55 # bugdir.new_bug(summary=summary)
56 # self.commit(u"Created bug: %s" % summary)
57 # raise cherrypy.HTTPRedirect('/', status=302)
60 # def comment(self, id, body):
61 # """The view that handles adding a comment."""
62 # if body.strip() != '':
63 # bugdir = self.storage_callbacks.get_bugdir()
64 # bug = bugdir.bug_from_uuid(id)
65 # bug.comment_root.new_reply(body=body)
66 # self.commit(u"Added reply Re: %s" % bug.summary)
67 # raise cherrypy.HTTPRedirect('/bug?id=%s' % (bug.uuid,), status=302)
68 # raise cherrypy.HTTPRedirect('/', status=302)
71 # def edit(self, id, status=None, target=None, assignee=None, severity=None, summary=None):
72 # """The view that handles editing bug details."""
73 # bugdir = self.storage_callbacks.get_bugdir()
74 # bug = bugdir.bug_from_uuid(id)
77 # old_summary = bug.summary
78 # bug.summary = summary
79 # self.bd.vcs.commit("Changed bug summary: %s -> %s" % (old_summary, bug.summary))
81 # bug.status = status if status != 'None' else None
82 # if target != 'None':
83 # libbe.target.add_target(bugdir, bug, target)
84 # bug.assigned = assignee if assignee != 'None' else None
85 # bug.severity = severity if severity != 'None' else None
86 # self.bd.vcs.commit("Changed bug values: %s" % bug.summary)
88 # raise cherrypy.HTTPRedirect('/bug?id=%s' % (bug.uuid,), status=302)