1
# Twisted, the Framework of Your Internet
2
# Copyright (C) 2001 Matthew W. Lefkowitz
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of version 2.1 of the GNU Lesser General Public
6
# License as published by the Free Software Foundation.
8
# This library is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# Lesser General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public
14
# License along with this library; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Web interface to the bugs database."""
23
from twisted.web import widgets
26
class BugsPage(widgets.WidgetPage):
27
"""Default look for bug pages."""
30
P, BODY, TD, OL, UL, MENU, BLOCKQUOTE, DIV
32
font-family: Lucida, Verdana, Helvetica, Arial;
40
%%%%self.stylesheet%%%%
42
<title>%%%%self.title%%%%</title>
43
<base href="%%%%request.prePathURL()%%%%">
47
<a href=".">View all bugs</a> || <a href="create">Submit a new bug</a>
55
class BugsGadget(widgets.StreamWidget, widgets.Gadget):
56
"""The main bugs gadget."""
58
title = "List of Bugs"
61
def __init__(self, database):
62
widgets.Gadget.__init__(self)
63
self.database = database
64
self.putWidget('create', CreateNewForm(self.database))
65
self.putWidget('view_bug', ViewBug(self.database))
67
def stream(self, write, request):
68
"""Display the intro list of bugs. This is only called if there is no URI.
70
write(self.database.getAllBugs().addCallback(self._cbBugs))
72
def _cbBugs(self, data):
74
l.append( '<table cellpadding=4 cellspacing=1 border=0 width="95%">'
75
'<tr bgcolor="#ff9900">'
76
'<td COLOR="#000000"><b> Summary </b> </td>'
77
'<td COLOR="#000000"><b> Type </b> </td>'
78
'<td COLOR="#000000"><b> Status </b> </td>'
79
'<td COLOR="#000000"><b> Assigned </b> </td>'
80
'<td COLOR="#000000"><b> Modification Date </b> </td>'
83
for (id, summary, type, status, assigned, date_mod) in data:
84
l.append( "<tr> <td> <a href='view_bug?bug_id=%d'>%s</a></td><td> %s </td> <td> %s</d><td> %s </td><td> %s </td></tr>\n" % (id, summary, type, status, assigned, date_mod) )
89
class CreateNewForm(widgets.Form):
90
"""Form for creating new bugs."""
92
title = "Create a new bug report:"
94
def __init__(self, database):
95
self.database = database
97
def display(self, request):
98
self.request = request
100
for t in self.database.types:
101
typeNames.append((t, string.capitalize(t)))
103
['string', 'Name: ', 'name', ''],
104
['string', 'Email:', 'email', ''],
105
['string', 'Version:', 'version', ''],
106
['string', 'OS:', 'os', ''],
107
['checkbox', 'Security Related:', 'security', 0],
108
['menu', 'Type:', 'type', typeNames],
109
['string', 'Summary:', 'summary', ''],
110
['text', 'Description:', 'description', ''],
113
return widgets.Form.display(self, self.request)
115
def process(self, write, request, submit, name, email, version, os, security, type, summary, description):
116
write(self.database.createBug(name, email, version, os, security, type, summary, description).addCallback(self._cbPosted))
118
def _cbPosted(self, result):
119
return ["Posted new bug."]
122
class AddCommentsForm(widgets.Form):
123
"""Form for adding comments to a bug."""
125
def __init__(self, database):
126
self.database = database
128
def getFormFields(self, request, fieldSet=[]):
129
bug_id = int(request.args.get('bug_id',[0])[0])
130
formFields = [['string', 'Name: ', 'name', ''],
131
['string', 'Email:', 'email', ''],
132
['text', 'Comment:', 'comment', ''],
133
['hidden', '', 'bug_id', bug_id],
135
return widgets.Form.getFormFields(self, request, formFields)
137
def process(self, write, request, submit, bug_id, name, email, comment):
138
write(self.database.createComment(bug_id, name, email, comment).addCallback(self._cbPosted))
140
def _cbPosted(self, result):
141
return ["Added new comment."]
144
class ViewBug(widgets.Widget):
147
def __init__(self, database):
148
self.database = database
149
self.addComments = AddCommentsForm(database)
151
def display(self, request):
152
bug_id = int(request.args.get('bug_id',[0])[0])
154
return [db.getBug(bug_id).addCallback(self._cbBug), "\n<p> </p>\n<h3>Add a comment</h3>\n"] + \
155
self.addComments.display(request) + \
156
['<p> </p>\n', db.getBugComments(bug_id).addCallback(self._cbComments)]
158
def _cbBug(self, result):
161
email = cgi.escape(result[0][2], 1)
162
result = map(cgi.escape, map(str, result[0]))
163
l.append('<h3>%s</h3>\n' % result[11])
164
l.append('<p>\n<b>Submitted by <a href="mailto:%s">%s</a> on %s</b><br>\n' % (email, result[1], result[4]))
165
l.append('<b>Last modified:</b> %s<br>\n' % result[5])
166
l.append('<b>Version:</b> %s<br>\n'% result[6])
167
l.append('<b>OS:</b> %s<br>\n' % result[7])
168
l.append('<b>Type:</b> %s<br>\n' % result[9])
169
l.append('<b>Status:</b> %s<br>\n' % result[10])
170
l.append('<b>Assigned to:</b> %s<br>\n</p>\n' % result[3])
171
l.append('<pre>\n%s\n</pre>' % desc)
174
def _cbComments(self, result):
175
l = ["<h3>Comments</h3>\n"]
176
for id, name, email, date, comment in result:
177
l.append('<p><b><a href="mailto:%s">%s</a> on %s:</b><br>\n'
178
'<pre>%s</pre></p>\n' % (cgi.escape(email, 1), cgi.escape(name), date, comment))