1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Cookbook.
5 # Cookbook is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation, either version 3 of the License, or (at your
8 # option) any later version.
10 # Cookbook is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Cookbook. If not, see <http://www.gnu.org/licenses/>.
18 """Serve cookbooks over HTTP.
24 from xml.sax import saxutils
27 from jinja2 import Environment, FileSystemLoader
30 class Server (object):
31 """Cookbook web interface."""
33 def __init__(self, cookbook, template_root):
34 self.cookbook = cookbook
35 self.cookbook.make_index()
36 self.env = Environment(loader=FileSystemLoader(template_root))
39 #self.cookbook.save('new-recipe')
43 def index(self, status='open', assignee='all', target='all'):
46 Recipes can be filtered or sorted using a variety of criteria.
48 template = self.env.get_template('recipes.html')
49 return template.render(cookbook=self.cookbook,
50 recipes=list(self.cookbook))
53 def recipe(self, name=None):
54 """Single recipe page.
57 recipe = random.choice(self.cookbook)
59 if type(name) == types.StringType:
60 name = unicode(name, encoding='utf-8')
61 recipe = self.cookbook.index[name]
62 template = self.env.get_template('recipe.html')
63 return template.render(cookbook=self.cookbook, recipe=recipe)
66 # def create(self, summary):
67 # """The view that handles the creation of a new bug."""
68 # if summary.strip() != '':
69 # bugdir = self.storage_callbacks.get_bugdir()
70 # bugdir.new_bug(summary=summary)
71 # self.commit(u"Created bug: %s" % summary)
72 # raise cherrypy.HTTPRedirect('/', status=302)
75 # def comment(self, id, body):
76 # """The view that handles adding a comment."""
77 # if body.strip() != '':
78 # bugdir = self.storage_callbacks.get_bugdir()
79 # bug = bugdir.bug_from_uuid(id)
80 # bug.comment_root.new_reply(body=body)
81 # self.commit(u"Added reply Re: %s" % bug.summary)
82 # raise cherrypy.HTTPRedirect('/bug?id=%s' % (bug.uuid,), status=302)
83 # raise cherrypy.HTTPRedirect('/', status=302)
86 # def edit(self, id, status=None, target=None, assignee=None, severity=None, summary=None):
87 # """The view that handles editing bug details."""
88 # bugdir = self.storage_callbacks.get_bugdir()
89 # bug = bugdir.bug_from_uuid(id)
92 # old_summary = bug.summary
93 # bug.summary = summary
94 # self.bd.vcs.commit("Changed bug summary: %s -> %s" % (old_summary, bug.summary))
96 # bug.status = status if status != 'None' else None
97 # if target != 'None':
98 # libbe.target.add_target(bugdir, bug, target)
99 # bug.assigned = assignee if assignee != 'None' else None
100 # bug.severity = severity if severity != 'None' else None
101 # self.bd.vcs.commit("Changed bug values: %s" % bug.summary)
103 # raise cherrypy.HTTPRedirect('/bug?id=%s' % (bug.uuid,), status=302)