9574d95690cf0df269752160c3af5fc5e4974c41
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: cgi_client.py,v 1.144 2002-07-25 07:14:05 richard Exp $
20 __doc__ = """
21 WWW request handler (also used in the stand-alone server).
22 """
24 import os, cgi, StringIO, urlparse, re, traceback, mimetypes, urllib
25 import binascii, Cookie, time, random
27 import roundupdb, htmltemplate, date, hyperdb, password
28 from roundup.i18n import _
30 class Unauthorised(ValueError):
31 pass
33 class NotFound(ValueError):
34 pass
36 def initialiseSecurity(security):
37 ''' Create some Permissions and Roles on the security object
39 This function is directly invoked by security.Security.__init__()
40 as a part of the Security object instantiation.
41 '''
42 newid = security.addPermission(name="Web Registration",
43 description="User may register through the web")
44 security.addPermissionToRole('Anonymous', newid)
46 class Client:
47 '''
48 A note about login
49 ------------------
51 If the user has no login cookie, then they are anonymous. There
52 are two levels of anonymous use. If there is no 'anonymous' user, there
53 is no login at all and the database is opened in read-only mode. If the
54 'anonymous' user exists, the user is logged in using that user (though
55 there is no cookie). This allows them to modify the database, and all
56 modifications are attributed to the 'anonymous' user.
58 Once a user logs in, they are assigned a session. The Client instance
59 keeps the nodeid of the session as the "session" attribute.
60 '''
62 def __init__(self, instance, request, env, form=None):
63 hyperdb.traceMark()
64 self.instance = instance
65 self.request = request
66 self.env = env
67 self.path = env['PATH_INFO']
68 self.split_path = self.path.split('/')
69 self.instance_path_name = env['INSTANCE_NAME']
70 url = self.env['SCRIPT_NAME'] + '/'
71 machine = self.env['SERVER_NAME']
72 port = self.env['SERVER_PORT']
73 if port != '80': machine = machine + ':' + port
74 self.base = urlparse.urlunparse(('http', env['HTTP_HOST'], url,
75 None, None, None))
77 if form is None:
78 self.form = cgi.FieldStorage(environ=env)
79 else:
80 self.form = form
81 self.headers_done = 0
82 try:
83 self.debug = int(env.get("ROUNDUP_DEBUG", 0))
84 except ValueError:
85 # someone gave us a non-int debug level, turn it off
86 self.debug = 0
88 def getuid(self):
89 try:
90 return self.db.user.lookup(self.user)
91 except KeyError:
92 if self.user is None:
93 # user is not logged in and username 'anonymous' doesn't
94 # exist in the database
95 err = _('anonymous users have read-only access only')
96 else:
97 err = _("sanity check: unknown user name `%s'")%self.user
98 raise Unauthorised, errmsg
100 def header(self, headers=None):
101 '''Put up the appropriate header.
102 '''
103 if headers is None:
104 headers = {'Content-Type':'text/html'}
105 if not headers.has_key('Content-Type'):
106 headers['Content-Type'] = 'text/html'
107 self.request.send_response(200)
108 for entry in headers.items():
109 self.request.send_header(*entry)
110 self.request.end_headers()
111 self.headers_done = 1
112 if self.debug:
113 self.headers_sent = headers
115 global_javascript = '''
116 <script language="javascript">
117 submitted = false;
118 function submit_once() {
119 if (submitted) {
120 alert("Your request is being processed.\\nPlease be patient.");
121 return 0;
122 }
123 submitted = true;
124 return 1;
125 }
127 function help_window(helpurl, width, height) {
128 HelpWin = window.open('%(base)s%(instance_path_name)s/' + helpurl, 'RoundupHelpWindow', 'scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width);
129 }
131 </script>
132 '''
133 def make_index_link(self, name):
134 '''Turn a configuration entry into a hyperlink...
135 '''
136 # get the link label and spec
137 spec = getattr(self.instance, name+'_INDEX')
139 d = {}
140 d[':sort'] = ','.join(map(urllib.quote, spec['SORT']))
141 d[':group'] = ','.join(map(urllib.quote, spec['GROUP']))
142 d[':filter'] = ','.join(map(urllib.quote, spec['FILTER']))
143 d[':columns'] = ','.join(map(urllib.quote, spec['COLUMNS']))
144 d[':pagesize'] = spec.get('PAGESIZE','50')
146 # snarf the filterspec
147 filterspec = spec['FILTERSPEC'].copy()
149 # now format the filterspec
150 for k, l in filterspec.items():
151 # fix up the CURRENT USER if needed (handle None too since that's
152 # the old flag value)
153 if l in (None, 'CURRENT USER'):
154 if not self.user:
155 continue
156 l = [self.db.user.lookup(self.user)]
158 # add
159 d[urllib.quote(k)] = ','.join(map(urllib.quote, l))
161 # finally, format the URL
162 return '<a href="%s?%s">%s</a>'%(spec['CLASS'],
163 '&'.join([k+'='+v for k,v in d.items()]), spec['LABEL'])
166 def pagehead(self, title, message=None):
167 '''Display the page heading, with information about the tracker and
168 links to more information
169 '''
171 # include any important message
172 if message is not None:
173 message = _('<div class="system-msg">%(message)s</div>')%locals()
174 else:
175 message = ''
177 # style sheet (CSS)
178 style = open(os.path.join(self.instance.TEMPLATES, 'style.css')).read()
180 # figure who the user is
181 user_name = self.user or ''
182 if user_name not in ('', 'anonymous'):
183 userid = self.db.user.lookup(self.user)
184 else:
185 userid = None
187 # figure all the header links
188 if hasattr(self.instance, 'HEADER_INDEX_LINKS'):
189 links = []
190 for name in self.instance.HEADER_INDEX_LINKS:
191 spec = getattr(self.instance, name + '_INDEX')
192 # skip if we need to fill in the logged-in user id there's
193 # no user logged in
194 if (spec['FILTERSPEC'].has_key('assignedto') and
195 spec['FILTERSPEC']['assignedto'] in ('CURRENT USER',
196 None) and userid is None):
197 continue
198 links.append(self.make_index_link(name))
199 else:
200 # no config spec - hard-code
201 links = [
202 _('All <a href="issue?status=-1,unread,deferred,chatting,need-eg,in-progress,testing,done-cbb&:sort=-activity&:filter=status&:columns=id,activity,status,title,assignedto&:group=priority&show_customization=1">Issues</a>'),
203 _('Unassigned <a href="issue?assignedto=-1&status=-1,unread,deferred,chatting,need-eg,in-progress,testing,done-cbb&:sort=-activity&:filter=status,assignedto&:columns=id,activity,status,title,assignedto&:group=priority&show_customization=1">Issues</a>')
204 ]
206 if userid:
207 # add any personal queries to the menu
208 try:
209 queries = self.db.getclass('query')
210 except KeyError:
211 # no query class
212 queries = self.instance.dbinit.Class(self.db,
213 "query",
214 klass=hyperdb.String(),
215 name=hyperdb.String(),
216 url=hyperdb.String())
217 queries.setkey('name')
218 #queries.disableJournalling()
219 try:
220 qids = self.db.getclass('user').get(userid, 'queries')
221 except KeyError, e:
222 #self.db.getclass('user').addprop(queries=hyperdb.Multilink('query'))
223 qids = []
224 for qid in qids:
225 links.append('<a href=%s?%s>%s</a>' % (queries.get(qid, 'klass'),
226 queries.get(qid, 'url'),
227 queries.get(qid, 'name')))
229 # if they're logged in, include links to their information, and the
230 # ability to add an issue
231 if user_name not in ('', 'anonymous'):
232 user_info = _('''
233 <a href="user%(userid)s">My Details</a> | <a href="logout">Logout</a>
234 ''')%locals()
236 # figure the "add class" links
237 if hasattr(self.instance, 'HEADER_ADD_LINKS'):
238 classes = self.instance.HEADER_ADD_LINKS
239 else:
240 classes = ['issue']
241 l = []
242 for class_name in classes:
243 cap_class = class_name.capitalize()
244 links.append(_('Add <a href="new%(class_name)s">'
245 '%(cap_class)s</a>')%locals())
247 # if there's no config header link spec, force a user link here
248 if not hasattr(self.instance, 'HEADER_INDEX_LINKS'):
249 links.append(_('<a href="issue?assignedto=%(userid)s&status=-1,unread,chatting,open,pending&:filter=status,resolution,assignedto&:sort=-activity&:columns=id,activity,status,resolution,title,creator&:group=type&show_customization=1">My Issues</a>')%locals())
250 else:
251 user_info = _('<a href="login">Login</a>')
252 add_links = ''
254 # if the user is admin, include admin links
255 admin_links = ''
256 if user_name == 'admin':
257 links.append(_('<a href="list_classes">Class List</a>'))
258 links.append(_('<a href="user?:sort=username">User List</a>'))
259 links.append(_('<a href="newuser">Add User</a>'))
261 # add the search links
262 if hasattr(self.instance, 'HEADER_SEARCH_LINKS'):
263 classes = self.instance.HEADER_SEARCH_LINKS
264 else:
265 classes = ['issue']
266 l = []
267 for class_name in classes:
268 cap_class = class_name.capitalize()
269 links.append(_('Search <a href="search%(class_name)s">'
270 '%(cap_class)s</a>')%locals())
272 # now we have all the links, join 'em
273 links = '\n | '.join(links)
275 # include the javascript bit
276 global_javascript = self.global_javascript%self.__dict__
278 # finally, format the header
279 self.write(_('''<html><head>
280 <title>%(title)s</title>
281 <style type="text/css">%(style)s</style>
282 </head>
283 %(global_javascript)s
284 <body bgcolor=#ffffff>
285 %(message)s
286 <table width=100%% border=0 cellspacing=0 cellpadding=2>
287 <tr class="location-bar">
288 <td><big><strong>%(title)s</strong></big></td>
289 <td align=right valign=bottom>%(user_name)s</td>
290 </tr>
291 <tr class="location-bar">
292 <td align=left>%(links)s</td>
293 <td align=right>%(user_info)s</td>
294 </tr>
295 </table><br>
296 ''')%locals())
298 def pagefoot(self):
299 if self.debug:
300 self.write(_('<hr><small><dl><dt><b>Path</b></dt>'))
301 self.write('<dd>%s</dd>'%(', '.join(map(repr, self.split_path))))
302 keys = self.form.keys()
303 keys.sort()
304 if keys:
305 self.write(_('<dt><b>Form entries</b></dt>'))
306 for k in self.form.keys():
307 v = self.form.getvalue(k, "<empty>")
308 if type(v) is type([]):
309 # Multiple username fields specified
310 v = "|".join(v)
311 self.write('<dd><em>%s</em>=%s</dd>'%(k, cgi.escape(v)))
312 keys = self.headers_sent.keys()
313 keys.sort()
314 self.write(_('<dt><b>Sent these HTTP headers</b></dt>'))
315 for k in keys:
316 v = self.headers_sent[k]
317 self.write('<dd><em>%s</em>=%s</dd>'%(k, cgi.escape(v)))
318 keys = self.env.keys()
319 keys.sort()
320 self.write(_('<dt><b>CGI environment</b></dt>'))
321 for k in keys:
322 v = self.env[k]
323 self.write('<dd><em>%s</em>=%s</dd>'%(k, cgi.escape(v)))
324 self.write('</dl></small>')
325 self.write('</body></html>')
327 def write(self, content):
328 if not self.headers_done:
329 self.header()
330 self.request.wfile.write(content)
332 def index_arg(self, arg):
333 ''' handle the args to index - they might be a list from the form
334 (ie. submitted from a form) or they might be a command-separated
335 single string (ie. manually constructed GET args)
336 '''
337 if self.form.has_key(arg):
338 arg = self.form[arg]
339 if type(arg) == type([]):
340 return [arg.value for arg in arg]
341 return arg.value.split(',')
342 return []
344 def index_sort(self):
345 # first try query string
346 x = self.index_arg(':sort')
347 if x:
348 return x
349 # nope - get the specs out of the form
350 specs = []
351 for colnm in self.db.getclass(self.classname).getprops().keys():
352 desc = ''
353 try:
354 spec = self.form[':%s_ss' % colnm]
355 except KeyError:
356 continue
357 spec = spec.value
358 if spec:
359 if spec[-1] == '-':
360 desc='-'
361 spec = spec[0]
362 specs.append((int(spec), colnm, desc))
363 specs.sort()
364 x = []
365 for _, colnm, desc in specs:
366 x.append('%s%s' % (desc, colnm))
367 return x
369 def index_filterspec(self, filter, classname=None):
370 ''' pull the index filter spec from the form
372 Links and multilinks want to be lists - the rest are straight
373 strings.
374 '''
375 if classname is None:
376 classname = self.classname
377 klass = self.db.getclass(classname)
378 filterspec = {}
379 props = klass.getprops()
380 for colnm in filter:
381 widget = ':%s_fs' % colnm
382 try:
383 val = self.form[widget]
384 except KeyError:
385 try:
386 val = self.form[colnm]
387 except KeyError:
388 # they checked the filter box but didn't enter a value
389 continue
390 propdescr = props.get(colnm, None)
391 if propdescr is None:
392 print "huh? %r is in filter & form, but not in Class!" % colnm
393 raise "butthead programmer"
394 if (isinstance(propdescr, hyperdb.Link) or
395 isinstance(propdescr, hyperdb.Multilink)):
396 if type(val) == type([]):
397 val = [arg.value for arg in val]
398 else:
399 val = val.value.split(',')
400 l = filterspec.get(colnm, [])
401 l = l + val
402 filterspec[colnm] = l
403 else:
404 filterspec[colnm] = val.value
406 return filterspec
408 def customization_widget(self):
409 ''' The customization widget is visible by default. The widget
410 visibility is remembered by show_customization. Visibility
411 is not toggled if the action value is "Redisplay"
412 '''
413 if not self.form.has_key('show_customization'):
414 visible = 1
415 else:
416 visible = int(self.form['show_customization'].value)
417 if self.form.has_key('action'):
418 if self.form['action'].value != 'Redisplay':
419 visible = self.form['action'].value == '+'
421 return visible
423 # TODO: make this go away some day...
424 default_index_sort = ['-activity']
425 default_index_group = ['priority']
426 default_index_filter = ['status']
427 default_index_columns = ['id','activity','title','status','assignedto']
428 default_index_filterspec = {'status': ['1', '2', '3', '4', '5', '6', '7']}
429 default_pagesize = '50'
431 def _get_customisation_info(self):
432 # see if the web has supplied us with any customisation info
433 for key in ':sort', ':group', ':filter', ':columns', ':pagesize':
434 if self.form.has_key(key):
435 # make list() extract the info from the CGI environ
436 self.classname = 'issue'
437 sort = group = filter = columns = filterspec = pagesize = None
438 break
439 else:
440 # TODO: look up the session first
441 # try the instance config first
442 if hasattr(self.instance, 'DEFAULT_INDEX'):
443 d = self.instance.DEFAULT_INDEX
444 self.classname = d['CLASS']
445 sort = d['SORT']
446 group = d['GROUP']
447 filter = d['FILTER']
448 columns = d['COLUMNS']
449 filterspec = d['FILTERSPEC']
450 pagesize = d.get('PAGESIZE', '50')
451 else:
452 # nope - fall back on the old way of doing it
453 self.classname = 'issue'
454 sort = self.default_index_sort
455 group = self.default_index_group
456 filter = self.default_index_filter
457 columns = self.default_index_columns
458 filterspec = self.default_index_filterspec
459 pagesize = self.default_pagesize
460 return columns, filter, group, sort, filterspec, pagesize
462 def index(self):
463 ''' put up an index - no class specified
464 '''
465 columns, filter, group, sort, filterspec, pagesize = \
466 self._get_customisation_info()
467 return self.list(columns=columns, filter=filter, group=group,
468 sort=sort, filterspec=filterspec, pagesize=pagesize)
470 def searchnode(self):
471 columns, filter, group, sort, filterspec, pagesize = \
472 self._get_customisation_info()
473 cn = self.classname
474 self.pagehead(_('%(instancename)s: Index of %(classname)s')%{
475 'classname': cn, 'instancename': self.instance.INSTANCE_NAME})
476 index = htmltemplate.IndexTemplate(self, self.instance.TEMPLATES, cn)
477 self.write('<form onSubmit="return submit_once()" action="%s">\n'%self.classname)
478 all_columns = self.db.getclass(cn).getprops().keys()
479 all_columns.sort()
480 index.filter_section('', filter, columns, group, all_columns, sort,
481 filterspec, pagesize, 0)
482 self.pagefoot()
483 index.db = index.cl = index.properties = None
484 index.clear()
486 # XXX deviates from spec - loses the '+' (that's a reserved character
487 # in URLS
488 def list(self, sort=None, group=None, filter=None, columns=None,
489 filterspec=None, show_customization=None, show_nodes=1, pagesize=None):
490 ''' call the template index with the args
492 :sort - sort by prop name, optionally preceeded with '-'
493 to give descending or nothing for ascending sorting.
494 :group - group by prop name, optionally preceeded with '-' or
495 to sort in descending or nothing for ascending order.
496 :filter - selects which props should be displayed in the filter
497 section. Default is all.
498 :columns - selects the columns that should be displayed.
499 Default is all.
501 '''
502 cn = self.classname
503 cl = self.db.classes[cn]
504 if sort is None: sort = self.index_sort()
505 if group is None: group = self.index_arg(':group')
506 if filter is None: filter = self.index_arg(':filter')
507 if columns is None: columns = self.index_arg(':columns')
508 if filterspec is None: filterspec = self.index_filterspec(filter)
509 if show_customization is None:
510 show_customization = self.customization_widget()
511 if self.form.has_key('search_text'):
512 search_text = self.form['search_text'].value
513 else:
514 search_text = ''
515 if pagesize is None:
516 if self.form.has_key(':pagesize'):
517 pagesize = self.form[':pagesize'].value
518 else:
519 pagesize = '50'
520 pagesize = int(pagesize)
521 if self.form.has_key(':startwith'):
522 startwith = int(self.form[':startwith'].value)
523 else:
524 startwith = 0
526 if self.form.has_key('Query') and self.form['Query'].value == 'Save':
527 # format a query string
528 qd = {}
529 qd[':sort'] = ','.join(map(urllib.quote, sort))
530 qd[':group'] = ','.join(map(urllib.quote, group))
531 qd[':filter'] = ','.join(map(urllib.quote, filter))
532 qd[':columns'] = ','.join(map(urllib.quote, columns))
533 for k, l in filterspec.items():
534 qd[urllib.quote(k)] = ','.join(map(urllib.quote, l))
535 url = '&'.join([k+'='+v for k,v in qd.items()])
536 url += '&:pagesize=%s' % pagesize
537 if search_text:
538 url += '&search_text=%s' % search_text
540 # create a query
541 d = {}
542 d['name'] = nm = self.form[':name'].value
543 if not nm:
544 d['name'] = nm = 'New Query'
545 d['klass'] = self.form[':classname'].value
546 d['url'] = url
547 qid = self.db.getclass('query').create(**d)
549 # and add it to the user's query multilink
550 uid = self.getuid()
551 usercl = self.db.getclass('user')
552 queries = usercl.get(uid, 'queries')
553 queries.append(qid)
554 usercl.set(uid, queries=queries)
556 self.pagehead(_('%(instancename)s: Index of %(classname)s')%{
557 'classname': cn, 'instancename': self.instance.INSTANCE_NAME})
559 index = htmltemplate.IndexTemplate(self, self.instance.TEMPLATES, cn)
560 try:
561 index.render(filterspec, search_text, filter, columns, sort,
562 group, show_customization=show_customization,
563 show_nodes=show_nodes, pagesize=pagesize, startwith=startwith)
564 except htmltemplate.MissingTemplateError:
565 self.basicClassEditPage()
566 self.pagefoot()
568 def basicClassEditPage(self):
569 '''Display a basic edit page that allows simple editing of the
570 nodes of the current class
571 '''
572 if self.user != 'admin':
573 raise Unauthorised
574 w = self.write
575 cn = self.classname
576 cl = self.db.classes[cn]
577 idlessprops = cl.getprops(protected=0).keys()
578 props = ['id'] + idlessprops
581 # get the CSV module
582 try:
583 import csv
584 except ImportError:
585 w(_('Sorry, you need the csv module to use this function.<br>\n'
586 'Get it from: <a href="http://www.object-craft.com.au/projects/csv/">http://www.object-craft.com.au/projects/csv/'))
587 return
589 # do the edit
590 if self.form.has_key('rows'):
591 rows = self.form['rows'].value.splitlines()
592 p = csv.parser()
593 found = {}
594 line = 0
595 for row in rows:
596 line += 1
597 values = p.parse(row)
598 # not a complete row, keep going
599 if not values: continue
601 # extract the nodeid
602 nodeid, values = values[0], values[1:]
603 found[nodeid] = 1
605 # confirm correct weight
606 if len(idlessprops) != len(values):
607 w(_('Not enough values on line %(line)s'%{'line':line}))
608 return
610 # extract the new values
611 d = {}
612 for name, value in zip(idlessprops, values):
613 d[name] = value.strip()
615 # perform the edit
616 if cl.hasnode(nodeid):
617 # edit existing
618 cl.set(nodeid, **d)
619 else:
620 # new node
621 found[cl.create(**d)] = 1
623 # retire the removed entries
624 for nodeid in cl.list():
625 if not found.has_key(nodeid):
626 cl.retire(nodeid)
628 w(_('''<p class="form-help">You may edit the contents of the
629 "%(classname)s" class using this form. The lines are full-featured
630 Comma-Separated-Value lines, so you may include commas and even
631 newlines by enclosing the values in double-quotes ("). Double
632 quotes themselves must be quoted by doubling ("").</p>
633 <p class="form-help">Remove entries by deleting their line. Add
634 new entries by appending
635 them to the table - put an X in the id column.</p>''')%{'classname':cn})
637 l = []
638 for name in props:
639 l.append(name)
640 w('<tt>')
641 w(', '.join(l) + '\n')
642 w('</tt>')
644 w('<form onSubmit="return submit_once()" method="POST">')
645 w('<textarea name="rows" cols=80 rows=15>')
646 p = csv.parser()
647 for nodeid in cl.list():
648 l = []
649 for name in props:
650 l.append(cgi.escape(str(cl.get(nodeid, name))))
651 w(p.join(l) + '\n')
653 w(_('</textarea><br><input type="submit" value="Save Changes"></form>'))
655 def classhelp(self):
656 '''Display a table of class info
657 '''
658 w = self.write
659 cn = self.form['classname'].value
660 cl = self.db.classes[cn]
661 props = self.form['properties'].value.split(',')
662 if cl.labelprop(1) in props:
663 sort = [cl.labelprop(1)]
664 else:
665 sort = props[0]
667 w('<table border=1 cellspacing=0 cellpaddin=2>')
668 w('<tr>')
669 for name in props:
670 w('<th align=left>%s</th>'%name)
671 w('</tr>')
672 for nodeid in cl.filter(None, {}, sort, []): #cl.list():
673 w('<tr>')
674 for name in props:
675 value = cgi.escape(str(cl.get(nodeid, name)))
676 w('<td align="left" valign="top">%s</td>'%value)
677 w('</tr>')
678 w('</table>')
680 def shownode(self, message=None, num_re=re.compile('^\d+$')):
681 ''' display an item
682 '''
683 cn = self.classname
684 cl = self.db.classes[cn]
685 if self.form.has_key(':multilink'):
686 link = self.form[':multilink'].value
687 designator, linkprop = link.split(':')
688 xtra = ' for <a href="%s">%s</a>' % (designator, designator)
689 else:
690 xtra = ''
692 # possibly perform an edit
693 keys = self.form.keys()
694 # don't try to set properties if the user has just logged in
695 if keys and not self.form.has_key('__login_name'):
696 try:
697 props = parsePropsFromForm(self.db, cl, self.form, self.nodeid)
698 # make changes to the node
699 self._changenode(props)
700 # handle linked nodes
701 self._post_editnode(self.nodeid)
702 # and some nice feedback for the user
703 if props:
704 message = _('%(changes)s edited ok')%{'changes':
705 ', '.join(props.keys())}
706 elif self.form.has_key('__note') and self.form['__note'].value:
707 message = _('note added')
708 elif (self.form.has_key('__file') and
709 self.form['__file'].filename):
710 message = _('file added')
711 else:
712 message = _('nothing changed')
713 except:
714 self.db.rollback()
715 s = StringIO.StringIO()
716 traceback.print_exc(None, s)
717 message = '<pre>%s</pre>'%cgi.escape(s.getvalue())
719 # now the display
720 id = self.nodeid
721 if cl.getkey():
722 id = cl.get(id, cl.getkey())
723 self.pagehead('%s: %s %s'%(self.classname.capitalize(), id, xtra),
724 message)
726 nodeid = self.nodeid
728 # use the template to display the item
729 item = htmltemplate.ItemTemplate(self, self.instance.TEMPLATES,
730 self.classname)
731 item.render(nodeid)
733 self.pagefoot()
734 showissue = shownode
735 showmsg = shownode
736 searchissue = searchnode
738 def showquery(self):
739 queries = self.db.getclass(self.classname)
740 if self.form.keys():
741 sort = self.index_sort()
742 group = self.index_arg(':group')
743 filter = self.index_arg(':filter')
744 columns = self.index_arg(':columns')
745 filterspec = self.index_filterspec(filter, queries.get(self.nodeid, 'klass'))
746 if self.form.has_key('search_text'):
747 search_text = self.form['search_text'].value
748 else:
749 search_text = ''
750 if self.form.has_key(':pagesize'):
751 pagesize = int(self.form[':pagesize'].value)
752 else:
753 pagesize = 50
754 # format a query string
755 qd = {}
756 qd[':sort'] = ','.join(map(urllib.quote, sort))
757 qd[':group'] = ','.join(map(urllib.quote, group))
758 qd[':filter'] = ','.join(map(urllib.quote, filter))
759 qd[':columns'] = ','.join(map(urllib.quote, columns))
760 for k, l in filterspec.items():
761 qd[urllib.quote(k)] = ','.join(map(urllib.quote, l))
762 url = '&'.join([k+'='+v for k,v in qd.items()])
763 url += '&:pagesize=%s' % pagesize
764 if search_text:
765 url += '&search_text=%s' % search_text
766 qname = self.form['name'].value
767 chgd = []
768 if qname != queries.get(self.nodeid, 'name'):
769 chgd.append('name')
770 if url != queries.get(self.nodeid, 'url'):
771 chgd.append('url')
772 if chgd:
773 queries.set(self.nodeid, name=qname, url=url)
774 message = _('%(changes)s edited ok')%{'changes': ', '.join(chgd)}
775 else:
776 message = _('nothing changed')
777 else:
778 message = None
779 nm = queries.get(self.nodeid, 'name')
780 self.pagehead('%s: %s'%(self.classname.capitalize(), nm), message)
782 # use the template to display the item
783 item = htmltemplate.ItemTemplate(self, self.instance.TEMPLATES,
784 self.classname)
785 item.render(self.nodeid)
786 self.pagefoot()
788 def _changenode(self, props):
789 ''' change the node based on the contents of the form
790 '''
791 cl = self.db.classes[self.classname]
793 # create the message
794 message, files = self._handle_message()
795 if message:
796 props['messages'] = cl.get(self.nodeid, 'messages') + [message]
797 if files:
798 props['files'] = cl.get(self.nodeid, 'files') + files
800 # make the changes
801 cl.set(self.nodeid, **props)
803 def _createnode(self):
804 ''' create a node based on the contents of the form
805 '''
806 cl = self.db.classes[self.classname]
807 props = parsePropsFromForm(self.db, cl, self.form)
809 # check for messages and files
810 message, files = self._handle_message()
811 if message:
812 props['messages'] = [message]
813 if files:
814 props['files'] = files
815 # create the node and return it's id
816 return cl.create(**props)
818 def _handle_message(self):
819 ''' generate an edit message
820 '''
821 # handle file attachments
822 files = []
823 if self.form.has_key('__file'):
824 file = self.form['__file']
825 if file.filename:
826 filename = file.filename.split('\\')[-1]
827 mime_type = mimetypes.guess_type(filename)[0]
828 if not mime_type:
829 mime_type = "application/octet-stream"
830 # create the new file entry
831 files.append(self.db.file.create(type=mime_type,
832 name=filename, content=file.file.read()))
834 # we don't want to do a message if none of the following is true...
835 cn = self.classname
836 cl = self.db.classes[self.classname]
837 props = cl.getprops()
838 note = None
839 # in a nutshell, don't do anything if there's no note or there's no
840 # NOSY
841 if self.form.has_key('__note'):
842 note = self.form['__note'].value.strip()
843 if not note:
844 return None, files
845 if not props.has_key('messages'):
846 return None, files
847 if not isinstance(props['messages'], hyperdb.Multilink):
848 return None, files
849 if not props['messages'].classname == 'msg':
850 return None, files
851 if not (self.form.has_key('nosy') or note):
852 return None, files
854 # handle the note
855 if '\n' in note:
856 summary = re.split(r'\n\r?', note)[0]
857 else:
858 summary = note
859 m = ['%s\n'%note]
861 # handle the messageid
862 # TODO: handle inreplyto
863 messageid = "<%s.%s.%s@%s>"%(time.time(), random.random(),
864 self.classname, self.instance.MAIL_DOMAIN)
866 # now create the message, attaching the files
867 content = '\n'.join(m)
868 message_id = self.db.msg.create(author=self.getuid(),
869 recipients=[], date=date.Date('.'), summary=summary,
870 content=content, files=files, messageid=messageid)
872 # update the messages property
873 return message_id, files
875 def _post_editnode(self, nid):
876 '''Do the linking part of the node creation.
878 If a form element has :link or :multilink appended to it, its
879 value specifies a node designator and the property on that node
880 to add _this_ node to as a link or multilink.
882 This is typically used on, eg. the file upload page to indicated
883 which issue to link the file to.
885 TODO: I suspect that this and newfile will go away now that
886 there's the ability to upload a file using the issue __file form
887 element!
888 '''
889 cn = self.classname
890 cl = self.db.classes[cn]
891 # link if necessary
892 keys = self.form.keys()
893 for key in keys:
894 if key == ':multilink':
895 value = self.form[key].value
896 if type(value) != type([]): value = [value]
897 for value in value:
898 designator, property = value.split(':')
899 link, nodeid = roundupdb.splitDesignator(designator)
900 link = self.db.classes[link]
901 # take a dupe of the list so we're not changing the cache
902 value = link.get(nodeid, property)[:]
903 value.append(nid)
904 link.set(nodeid, **{property: value})
905 elif key == ':link':
906 value = self.form[key].value
907 if type(value) != type([]): value = [value]
908 for value in value:
909 designator, property = value.split(':')
910 link, nodeid = roundupdb.splitDesignator(designator)
911 link = self.db.classes[link]
912 link.set(nodeid, **{property: nid})
914 def newnode(self, message=None):
915 ''' Add a new node to the database.
917 The form works in two modes: blank form and submission (that is,
918 the submission goes to the same URL). **Eventually this means that
919 the form will have previously entered information in it if
920 submission fails.
922 The new node will be created with the properties specified in the
923 form submission. For multilinks, multiple form entries are handled,
924 as are prop=value,value,value. You can't mix them though.
926 If the new node is to be referenced from somewhere else immediately
927 (ie. the new node is a file that is to be attached to a support
928 issue) then supply one of these arguments in addition to the usual
929 form entries:
930 :link=designator:property
931 :multilink=designator:property
932 ... which means that once the new node is created, the "property"
933 on the node given by "designator" should now reference the new
934 node's id. The node id will be appended to the multilink.
935 '''
936 cn = self.classname
937 cl = self.db.classes[cn]
938 if self.form.has_key(':multilink'):
939 link = self.form[':multilink'].value
940 designator, linkprop = link.split(':')
941 xtra = ' for <a href="%s">%s</a>' % (designator, designator)
942 else:
943 xtra = ''
945 # possibly perform a create
946 keys = self.form.keys()
947 if [i for i in keys if i[0] != ':']:
948 props = {}
949 try:
950 nid = self._createnode()
951 # handle linked nodes
952 self._post_editnode(nid)
953 # and some nice feedback for the user
954 message = _('%(classname)s created ok')%{'classname': cn}
956 # render the newly created issue
957 self.db.commit()
958 self.nodeid = nid
959 self.pagehead('%s: %s'%(self.classname.capitalize(), nid),
960 message)
961 item = htmltemplate.ItemTemplate(self, self.instance.TEMPLATES,
962 self.classname)
963 item.render(nid)
964 self.pagefoot()
965 return
966 except:
967 self.db.rollback()
968 s = StringIO.StringIO()
969 traceback.print_exc(None, s)
970 message = '<pre>%s</pre>'%cgi.escape(s.getvalue())
971 self.pagehead(_('New %(classname)s %(xtra)s')%{
972 'classname': self.classname.capitalize(),
973 'xtra': xtra }, message)
975 # call the template
976 newitem = htmltemplate.NewItemTemplate(self, self.instance.TEMPLATES,
977 self.classname)
978 newitem.render(self.form)
980 self.pagefoot()
981 newissue = newnode
983 def newuser(self, message=None):
984 ''' Add a new user to the database.
986 Don't do any of the message or file handling, just create the node.
987 '''
988 cn = self.classname
989 cl = self.db.classes[cn]
991 # possibly perform a create
992 keys = self.form.keys()
993 if [i for i in keys if i[0] != ':']:
994 try:
995 props = parsePropsFromForm(self.db, cl, self.form)
996 nid = cl.create(**props)
997 # handle linked nodes
998 self._post_editnode(nid)
999 # and some nice feedback for the user
1000 message = _('%(classname)s created ok')%{'classname': cn}
1001 except:
1002 self.db.rollback()
1003 s = StringIO.StringIO()
1004 traceback.print_exc(None, s)
1005 message = '<pre>%s</pre>'%cgi.escape(s.getvalue())
1006 self.pagehead(_('New %(classname)s')%{'classname':
1007 self.classname.capitalize()}, message)
1009 # call the template
1010 newitem = htmltemplate.NewItemTemplate(self, self.instance.TEMPLATES,
1011 self.classname)
1012 newitem.render(self.form)
1014 self.pagefoot()
1016 def newfile(self, message=None):
1017 ''' Add a new file to the database.
1019 This form works very much the same way as newnode - it just has a
1020 file upload.
1021 '''
1022 cn = self.classname
1023 cl = self.db.classes[cn]
1024 props = parsePropsFromForm(self.db, cl, self.form)
1025 if self.form.has_key(':multilink'):
1026 link = self.form[':multilink'].value
1027 designator, linkprop = link.split(':')
1028 xtra = ' for <a href="%s">%s</a>' % (designator, designator)
1029 else:
1030 xtra = ''
1032 # possibly perform a create
1033 keys = self.form.keys()
1034 if [i for i in keys if i[0] != ':']:
1035 try:
1036 file = self.form['content']
1037 mime_type = mimetypes.guess_type(file.filename)[0]
1038 if not mime_type:
1039 mime_type = "application/octet-stream"
1040 # save the file
1041 props['type'] = mime_type
1042 props['name'] = file.filename
1043 props['content'] = file.file.read()
1044 nid = cl.create(**props)
1045 # handle linked nodes
1046 self._post_editnode(nid)
1047 # and some nice feedback for the user
1048 message = _('%(classname)s created ok')%{'classname': cn}
1049 except:
1050 self.db.rollback()
1051 s = StringIO.StringIO()
1052 traceback.print_exc(None, s)
1053 message = '<pre>%s</pre>'%cgi.escape(s.getvalue())
1055 self.pagehead(_('New %(classname)s %(xtra)s')%{
1056 'classname': self.classname.capitalize(),
1057 'xtra': xtra }, message)
1058 newitem = htmltemplate.NewItemTemplate(self, self.instance.TEMPLATES,
1059 self.classname)
1060 newitem.render(self.form)
1061 self.pagefoot()
1063 def showuser(self, message=None, num_re=re.compile('^\d+$')):
1064 '''Display a user page for editing. Make sure the user is allowed
1065 to edit this node, and also check for password changes.
1066 '''
1067 if self.user == 'anonymous':
1068 raise Unauthorised
1070 user = self.db.user
1072 # get the username of the node being edited
1073 node_user = user.get(self.nodeid, 'username')
1075 if self.user not in ('admin', node_user):
1076 raise Unauthorised
1078 #
1079 # perform any editing
1080 #
1081 keys = self.form.keys()
1082 if keys:
1083 try:
1084 props = parsePropsFromForm(self.db, user, self.form,
1085 self.nodeid)
1086 set_cookie = 0
1087 if props.has_key('password'):
1088 password = self.form['password'].value.strip()
1089 if not password:
1090 # no password was supplied - don't change it
1091 del props['password']
1092 elif self.nodeid == self.getuid():
1093 # this is the logged-in user's password
1094 set_cookie = password
1095 user.set(self.nodeid, **props)
1096 # and some feedback for the user
1097 message = _('%(changes)s edited ok')%{'changes':
1098 ', '.join(props.keys())}
1099 except:
1100 self.db.rollback()
1101 s = StringIO.StringIO()
1102 traceback.print_exc(None, s)
1103 message = '<pre>%s</pre>'%cgi.escape(s.getvalue())
1104 else:
1105 set_cookie = 0
1107 # fix the cookie if the password has changed
1108 if set_cookie:
1109 self.set_cookie(self.user, set_cookie)
1111 #
1112 # now the display
1113 #
1114 self.pagehead(_('User: %(user)s')%{'user': node_user}, message)
1116 # use the template to display the item
1117 item = htmltemplate.ItemTemplate(self, self.instance.TEMPLATES, 'user')
1118 item.render(self.nodeid)
1119 self.pagefoot()
1121 def showfile(self):
1122 ''' display a file
1123 '''
1124 nodeid = self.nodeid
1125 cl = self.db.classes[self.classname]
1126 mime_type = cl.get(nodeid, 'type')
1127 if mime_type == 'message/rfc822':
1128 mime_type = 'text/plain'
1129 self.header(headers={'Content-Type': mime_type})
1130 self.write(cl.get(nodeid, 'content'))
1132 def classes(self, message=None):
1133 ''' display a list of all the classes in the database
1134 '''
1135 if self.user == 'admin':
1136 self.pagehead(_('Table of classes'), message)
1137 classnames = self.db.classes.keys()
1138 classnames.sort()
1139 self.write('<table border=0 cellspacing=0 cellpadding=2>\n')
1140 for cn in classnames:
1141 cl = self.db.getclass(cn)
1142 self.write('<tr class="list-header"><th colspan=2 align=left>'
1143 '<a href="%s">%s</a></th></tr>'%(cn, cn.capitalize()))
1144 for key, value in cl.properties.items():
1145 if value is None: value = ''
1146 else: value = str(value)
1147 self.write('<tr><th align=left>%s</th><td>%s</td></tr>'%(
1148 key, cgi.escape(value)))
1149 self.write('</table>')
1150 self.pagefoot()
1151 else:
1152 raise Unauthorised
1154 def login(self, message=None, newuser_form=None, action='index'):
1155 '''Display a login page.
1156 '''
1157 self.pagehead(_('Login to roundup'), message)
1158 self.write(_('''
1159 <table>
1160 <tr><td colspan=2 class="strong-header">Existing User Login</td></tr>
1161 <form onSubmit="return submit_once()" action="login_action" method=POST>
1162 <input type="hidden" name="__destination_url" value="%(action)s">
1163 <tr><td align=right>Login name: </td>
1164 <td><input name="__login_name"></td></tr>
1165 <tr><td align=right>Password: </td>
1166 <td><input type="password" name="__login_password"></td></tr>
1167 <tr><td></td>
1168 <td><input type="submit" value="Log In"></td></tr>
1169 </form>
1170 ''')%locals())
1171 if self.user is None and self.instance.ANONYMOUS_REGISTER == 'deny':
1172 self.write('</table>')
1173 self.pagefoot()
1174 return
1175 values = {'realname': '', 'organisation': '', 'address': '',
1176 'phone': '', 'username': '', 'password': '', 'confirm': '',
1177 'action': action, 'alternate_addresses': ''}
1178 if newuser_form is not None:
1179 for key in newuser_form.keys():
1180 values[key] = newuser_form[key].value
1181 self.write(_('''
1182 <p>
1183 <tr><td colspan=2 class="strong-header">New User Registration</td></tr>
1184 <tr><td colspan=2><em>marked items</em> are optional...</td></tr>
1185 <form onSubmit="return submit_once()" action="newuser_action" method=POST>
1186 <input type="hidden" name="__destination_url" value="%(action)s">
1187 <tr><td align=right><em>Name: </em></td>
1188 <td><input name="realname" value="%(realname)s" size=40></td></tr>
1189 <tr><td align=right><em>Organisation: </em></td>
1190 <td><input name="organisation" value="%(organisation)s" size=40></td></tr>
1191 <tr><td align=right>E-Mail Address: </td>
1192 <td><input name="address" value="%(address)s" size=40></td></tr>
1193 <tr><td align=right><em>Alternate E-mail Addresses: </em></td>
1194 <td><textarea name="alternate_addresses" rows=5 cols=40>%(alternate_addresses)s</textarea></td></tr>
1195 <tr><td align=right><em>Phone: </em></td>
1196 <td><input name="phone" value="%(phone)s"></td></tr>
1197 <tr><td align=right>Preferred Login name: </td>
1198 <td><input name="username" value="%(username)s"></td></tr>
1199 <tr><td align=right>Password: </td>
1200 <td><input type="password" name="password" value="%(password)s"></td></tr>
1201 <tr><td align=right>Password Again: </td>
1202 <td><input type="password" name="confirm" value="%(confirm)s"></td></tr>
1203 <tr><td></td>
1204 <td><input type="submit" value="Register"></td></tr>
1205 </form>
1206 </table>
1207 ''')%values)
1208 self.pagefoot()
1210 def login_action(self, message=None):
1211 '''Attempt to log a user in and set the cookie
1213 returns 0 if a page is generated as a result of this call, and
1214 1 if not (ie. the login is successful
1215 '''
1216 if not self.form.has_key('__login_name'):
1217 self.login(message=_('Username required'))
1218 return 0
1219 self.user = self.form['__login_name'].value
1220 # re-open the database for real, using the user
1221 self.opendb(self.user)
1222 if self.form.has_key('__login_password'):
1223 password = self.form['__login_password'].value
1224 else:
1225 password = ''
1226 # make sure the user exists
1227 try:
1228 uid = self.db.user.lookup(self.user)
1229 except KeyError:
1230 name = self.user
1231 self.make_user_anonymous()
1232 action = self.form['__destination_url'].value
1233 self.login(message=_('No such user "%(name)s"')%locals(),
1234 action=action)
1235 return 0
1237 # and that the password is correct
1238 pw = self.db.user.get(uid, 'password')
1239 if password != pw:
1240 self.make_user_anonymous()
1241 action = self.form['__destination_url'].value
1242 self.login(message=_('Incorrect password'), action=action)
1243 return 0
1245 self.set_cookie(self.user, password)
1246 return 1
1248 def newuser_action(self, message=None):
1249 '''Attempt to create a new user based on the contents of the form
1250 and then set the cookie.
1252 return 1 on successful login
1253 '''
1254 # re-open the database as "admin"
1255 self.opendb('admin')
1257 # create the new user
1258 cl = self.db.user
1259 try:
1260 props = parsePropsFromForm(self.db, cl, self.form)
1261 uid = cl.create(**props)
1262 except ValueError, message:
1263 action = self.form['__destination_url'].value
1264 self.login(message, action=action)
1265 return 0
1267 # log the new user in
1268 self.user = cl.get(uid, 'username')
1269 # re-open the database for real, using the user
1270 self.opendb(self.user)
1271 password = cl.get(uid, 'password')
1272 self.set_cookie(self.user, self.form['password'].value)
1273 return 1
1275 def set_cookie(self, user, password):
1276 # TODO generate a much, much stronger session key ;)
1277 session = binascii.b2a_base64(repr(time.time())).strip()
1279 # clean up the base64
1280 if session[-1] == '=':
1281 if session[-2] == '=':
1282 session = session[:-2]
1283 else:
1284 session = session[:-1]
1286 print 'session set to', `session`
1288 # insert the session in the sessiondb
1289 sessions = self.db.getclass('__sessions')
1290 self.session = sessions.create(sessid=session, user=user,
1291 last_use=date.Date())
1293 # and commit immediately
1294 self.db.commit()
1296 # expire us in a long, long time
1297 expire = Cookie._getdate(86400*365)
1299 # generate the cookie path - make sure it has a trailing '/'
1300 path = '/'.join((self.env['SCRIPT_NAME'], self.env['INSTANCE_NAME'],
1301 ''))
1302 self.header({'Set-Cookie': 'roundup_user=%s; expires=%s; Path=%s;'%(
1303 session, expire, path)})
1305 def make_user_anonymous(self):
1306 # make us anonymous if we can
1307 try:
1308 self.db.user.lookup('anonymous')
1309 self.user = 'anonymous'
1310 except KeyError:
1311 self.user = None
1313 def logout(self, message=None):
1314 self.make_user_anonymous()
1315 # construct the logout cookie
1316 now = Cookie._getdate()
1317 path = '/'.join((self.env['SCRIPT_NAME'], self.env['INSTANCE_NAME'],
1318 ''))
1319 self.header({'Set-Cookie':
1320 'roundup_user=deleted; Max-Age=0; expires=%s; Path=%s;'%(now,
1321 path)})
1322 self.login()
1324 def opendb(self, user):
1325 ''' Open the database - but include the definition of the sessions db.
1326 '''
1327 # open the db
1328 self.db = self.instance.open(user)
1330 # make sure we have the session Class
1331 try:
1332 sessions = self.db.getclass('__sessions')
1333 except:
1334 # add the sessions Class - use a non-journalling Class
1335 # TODO: not happy with how we're getting the Class here :(
1336 sessions = self.instance.dbinit.Class(self.db, '__sessions',
1337 sessid=hyperdb.String(), user=hyperdb.String(),
1338 last_use=hyperdb.Date())
1339 sessions.setkey('sessid')
1340 # make sure session db isn't journalled
1341 sessions.disableJournalling()
1343 def main(self):
1344 '''Wrap the database accesses so we can close the database cleanly
1345 '''
1346 # determine the uid to use
1347 self.opendb('admin')
1349 # make sure we have the session Class
1350 sessions = self.db.getclass('__sessions')
1352 # age sessions, remove when they haven't been used for a week
1353 # TODO: this shouldn't be done every access
1354 week = date.Interval('7d')
1355 now = date.Date()
1356 for sessid in sessions.list():
1357 interval = now - sessions.get(sessid, 'last_use')
1358 if interval > week:
1359 sessions.destroy(sessid)
1361 # look up the user session cookie
1362 cookie = Cookie.Cookie(self.env.get('HTTP_COOKIE', ''))
1363 user = 'anonymous'
1364 if (cookie.has_key('roundup_user') and
1365 cookie['roundup_user'].value != 'deleted'):
1367 # get the session key from the cookie
1368 session = cookie['roundup_user'].value
1370 # get the user from the session
1371 try:
1372 self.session = sessions.lookup(session)
1373 except KeyError:
1374 user = 'anonymous'
1375 else:
1376 # update the lifetime datestamp
1377 sessions.set(self.session, last_use=date.Date())
1378 self.db.commit()
1379 user = sessions.get(sessid, 'user')
1381 # make sure the anonymous user is valid if we're using it
1382 if user == 'anonymous':
1383 self.make_user_anonymous()
1384 else:
1385 self.user = user
1387 # now figure which function to call
1388 path = self.split_path
1390 # default action to index if the path has no information in it
1391 if not path or path[0] in ('', 'index'):
1392 action = 'index'
1393 else:
1394 action = path[0]
1396 # Everthing ignores path[1:]
1397 # - The file download link generator actually relies on this - it
1398 # appends the name of the file to the URL so the download file name
1399 # is correct, but doesn't actually use it.
1401 # everyone is allowed to try to log in
1402 if action == 'login_action':
1403 # try to login
1404 if not self.login_action():
1405 return
1406 # figure the resulting page
1407 action = self.form['__destination_url'].value
1408 if not action:
1409 action = 'index'
1410 self.do_action(action)
1411 return
1413 # allow anonymous people to register
1414 if action == 'newuser_action':
1415 # if we don't have a login and anonymous people aren't allowed to
1416 # register, then spit up the login form
1417 if self.instance.ANONYMOUS_REGISTER == 'deny' and self.user is None:
1418 if action == 'login':
1419 self.login() # go to the index after login
1420 else:
1421 self.login(action=action)
1422 return
1423 # try to add the user
1424 if not self.newuser_action():
1425 return
1426 # figure the resulting page
1427 action = self.form['__destination_url'].value
1428 if not action:
1429 action = 'index'
1431 # no login or registration, make sure totally anonymous access is OK
1432 elif self.instance.ANONYMOUS_ACCESS == 'deny' and self.user is None:
1433 if action == 'login':
1434 self.login() # go to the index after login
1435 else:
1436 self.login(action=action)
1437 return
1439 # re-open the database for real, using the user
1440 self.opendb(self.user)
1442 # just a regular action
1443 self.do_action(action)
1445 # commit all changes to the database
1446 self.db.commit()
1448 def do_action(self, action, dre=re.compile(r'([^\d]+)(\d+)'),
1449 nre=re.compile(r'new(\w+)'), sre=re.compile(r'search(\w+)')):
1450 '''Figure the user's action and do it.
1451 '''
1452 # here be the "normal" functionality
1453 if action == 'index':
1454 self.index()
1455 return
1456 if action == 'list_classes':
1457 self.classes()
1458 return
1459 if action == 'classhelp':
1460 self.classhelp()
1461 return
1462 if action == 'login':
1463 self.login()
1464 return
1465 if action == 'logout':
1466 self.logout()
1467 return
1469 # see if we're to display an existing node
1470 m = dre.match(action)
1471 if m:
1472 self.classname = m.group(1)
1473 self.nodeid = m.group(2)
1474 try:
1475 cl = self.db.classes[self.classname]
1476 except KeyError:
1477 raise NotFound, self.classname
1478 try:
1479 cl.get(self.nodeid, 'id')
1480 except IndexError:
1481 raise NotFound, self.nodeid
1482 try:
1483 func = getattr(self, 'show%s'%self.classname)
1484 except AttributeError:
1485 raise NotFound, 'show%s'%self.classname
1486 func()
1487 return
1489 # see if we're to put up the new node page
1490 m = nre.match(action)
1491 if m:
1492 self.classname = m.group(1)
1493 try:
1494 func = getattr(self, 'new%s'%self.classname)
1495 except AttributeError:
1496 raise NotFound, 'new%s'%self.classname
1497 func()
1498 return
1500 # see if we're to put up the new node page
1501 m = sre.match(action)
1502 if m:
1503 self.classname = m.group(1)
1504 try:
1505 func = getattr(self, 'search%s'%self.classname)
1506 except AttributeError:
1507 raise NotFound
1508 func()
1509 return
1511 # otherwise, display the named class
1512 self.classname = action
1513 try:
1514 self.db.getclass(self.classname)
1515 except KeyError:
1516 raise NotFound, self.classname
1517 self.list()
1520 class ExtendedClient(Client):
1521 '''Includes pages and page heading information that relate to the
1522 extended schema.
1523 '''
1524 showsupport = Client.shownode
1525 showtimelog = Client.shownode
1526 newsupport = Client.newnode
1527 newtimelog = Client.newnode
1528 searchsupport = Client.searchnode
1530 default_index_sort = ['-activity']
1531 default_index_group = ['priority']
1532 default_index_filter = ['status']
1533 default_index_columns = ['activity','status','title','assignedto']
1534 default_index_filterspec = {'status': ['1', '2', '3', '4', '5', '6', '7']}
1535 default_pagesize = '50'
1537 def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
1538 '''Pull properties for the given class out of the form.
1539 '''
1540 props = {}
1541 keys = form.keys()
1542 for key in keys:
1543 if not cl.properties.has_key(key):
1544 continue
1545 proptype = cl.properties[key]
1546 if isinstance(proptype, hyperdb.String):
1547 value = form[key].value.strip()
1548 elif isinstance(proptype, hyperdb.Password):
1549 value = password.Password(form[key].value.strip())
1550 elif isinstance(proptype, hyperdb.Date):
1551 value = form[key].value.strip()
1552 if value:
1553 value = date.Date(form[key].value.strip())
1554 else:
1555 value = None
1556 elif isinstance(proptype, hyperdb.Interval):
1557 value = form[key].value.strip()
1558 if value:
1559 value = date.Interval(form[key].value.strip())
1560 else:
1561 value = None
1562 elif isinstance(proptype, hyperdb.Link):
1563 value = form[key].value.strip()
1564 # see if it's the "no selection" choice
1565 if value == '-1':
1566 # don't set this property
1567 continue
1568 else:
1569 # handle key values
1570 link = cl.properties[key].classname
1571 if not num_re.match(value):
1572 try:
1573 value = db.classes[link].lookup(value)
1574 except KeyError:
1575 raise ValueError, _('property "%(propname)s": '
1576 '%(value)s not a %(classname)s')%{'propname':key,
1577 'value': value, 'classname': link}
1578 elif isinstance(proptype, hyperdb.Multilink):
1579 value = form[key]
1580 if hasattr(value, 'value'):
1581 # Quite likely to be a FormItem instance
1582 value = value.value
1583 if not isinstance(value, type([])):
1584 value = [i.strip() for i in value.split(',')]
1585 else:
1586 value = [i.strip() for i in value]
1587 link = cl.properties[key].classname
1588 l = []
1589 for entry in map(str, value):
1590 if entry == '': continue
1591 if not num_re.match(entry):
1592 try:
1593 entry = db.classes[link].lookup(entry)
1594 except KeyError:
1595 raise ValueError, _('property "%(propname)s": '
1596 '"%(value)s" not an entry of %(classname)s')%{
1597 'propname':key, 'value': entry, 'classname': link}
1598 l.append(entry)
1599 l.sort()
1600 value = l
1601 elif isinstance(proptype, hyperdb.Boolean):
1602 value = form[key].value.strip()
1603 props[key] = value = value.lower() in ('yes', 'true', 'on', '1')
1604 elif isinstance(proptype, hyperdb.Number):
1605 value = form[key].value.strip()
1606 props[key] = value = int(value)
1608 # get the old value
1609 if nodeid:
1610 try:
1611 existing = cl.get(nodeid, key)
1612 except KeyError:
1613 # this might be a new property for which there is no existing
1614 # value
1615 if not cl.properties.has_key(key): raise
1617 # if changed, set it
1618 if value != existing:
1619 props[key] = value
1620 else:
1621 props[key] = value
1622 return props
1624 #
1625 # $Log: not supported by cvs2svn $
1626 # Revision 1.143 2002/07/20 19:29:10 gmcm
1627 # Fixes/improvements to the search form & saved queries.
1628 #
1629 # Revision 1.142 2002/07/18 11:17:30 gmcm
1630 # Add Number and Boolean types to hyperdb.
1631 # Add conversion cases to web, mail & admin interfaces.
1632 # Add storage/serialization cases to back_anydbm & back_metakit.
1633 #
1634 # Revision 1.141 2002/07/17 12:39:10 gmcm
1635 # Saving, running & editing queries.
1636 #
1637 # Revision 1.140 2002/07/14 23:17:15 richard
1638 # cleaned up structure
1639 #
1640 # Revision 1.139 2002/07/14 06:14:40 richard
1641 # Some more TODOs
1642 #
1643 # Revision 1.138 2002/07/14 04:03:13 richard
1644 # Implemented a switch to disable journalling for a Class. CGI session
1645 # database now uses it.
1646 #
1647 # Revision 1.137 2002/07/10 07:00:30 richard
1648 # removed debugging
1649 #
1650 # Revision 1.136 2002/07/10 06:51:08 richard
1651 # . #576241 ] MultiLink problems in parsePropsFromForm
1652 #
1653 # Revision 1.135 2002/07/10 00:22:34 richard
1654 # . switched to using a session-based web login
1655 #
1656 # Revision 1.134 2002/07/09 04:19:09 richard
1657 # Added reindex command to roundup-admin.
1658 # Fixed reindex on first access.
1659 # Also fixed reindexing of entries that change.
1660 #
1661 # Revision 1.133 2002/07/08 15:32:05 gmcm
1662 # Pagination of index pages.
1663 # New search form.
1664 #
1665 # Revision 1.132 2002/07/08 07:26:14 richard
1666 # ehem
1667 #
1668 # Revision 1.131 2002/07/08 06:53:57 richard
1669 # Not sure why the cgi_client had an indexer argument.
1670 #
1671 # Revision 1.130 2002/06/27 12:01:53 gmcm
1672 # If the form has a :multilink, put a back href in the pageheader (back to the linked-to node).
1673 # Some minor optimizations (only compile regexes once).
1674 #
1675 # Revision 1.129 2002/06/20 23:52:11 richard
1676 # Better handling of unauth attempt to edit stuff
1677 #
1678 # Revision 1.128 2002/06/12 21:28:25 gmcm
1679 # Allow form to set user-properties on a Fileclass.
1680 # Don't assume that a Fileclass is named "files".
1681 #
1682 # Revision 1.127 2002/06/11 06:38:24 richard
1683 # . #565996 ] The "Attach a File to this Issue" fails
1684 #
1685 # Revision 1.126 2002/05/29 01:16:17 richard
1686 # Sorry about this huge checkin! It's fixing a lot of related stuff in one go
1687 # though.
1688 #
1689 # . #541941 ] changing multilink properties by mail
1690 # . #526730 ] search for messages capability
1691 # . #505180 ] split MailGW.handle_Message
1692 # - also changed cgi client since it was duplicating the functionality
1693 # . build htmlbase if tests are run using CVS checkout (removed note from
1694 # installation.txt)
1695 # . don't create an empty message on email issue creation if the email is empty
1696 #
1697 # Revision 1.125 2002/05/25 07:16:24 rochecompaan
1698 # Merged search_indexing-branch with HEAD
1699 #
1700 # Revision 1.124 2002/05/24 02:09:24 richard
1701 # Nothing like a live demo to show up the bugs ;)
1702 #
1703 # Revision 1.123 2002/05/22 05:04:13 richard
1704 # Oops
1705 #
1706 # Revision 1.122 2002/05/22 04:12:05 richard
1707 # . applied patch #558876 ] cgi client customization
1708 # ... with significant additions and modifications ;)
1709 # - extended handling of ML assignedto to all places it's handled
1710 # - added more NotFound info
1711 #
1712 # Revision 1.121 2002/05/21 06:08:10 richard
1713 # Handle migration
1714 #
1715 # Revision 1.120 2002/05/21 06:05:53 richard
1716 # . #551483 ] assignedto in Client.make_index_link
1717 #
1718 # Revision 1.119 2002/05/15 06:21:21 richard
1719 # . node caching now works, and gives a small boost in performance
1720 #
1721 # As a part of this, I cleaned up the DEBUG output and implemented TRACE
1722 # output (HYPERDBTRACE='file to trace to') with checkpoints at the start of
1723 # CGI requests. Run roundup with python -O to skip all the DEBUG/TRACE stuff
1724 # (using if __debug__ which is compiled out with -O)
1725 #
1726 # Revision 1.118 2002/05/12 23:46:33 richard
1727 # ehem, part 2
1728 #
1729 # Revision 1.117 2002/05/12 23:42:29 richard
1730 # ehem
1731 #
1732 # Revision 1.116 2002/05/02 08:07:49 richard
1733 # Added the ADD_AUTHOR_TO_NOSY handling to the CGI interface.
1734 #
1735 # Revision 1.115 2002/04/02 01:56:10 richard
1736 # . stop sending blank (whitespace-only) notes
1737 #
1738 # Revision 1.114.2.4 2002/05/02 11:49:18 rochecompaan
1739 # Allow customization of the search filters that should be displayed
1740 # on the search page.
1741 #
1742 # Revision 1.114.2.3 2002/04/20 13:23:31 rochecompaan
1743 # We now have a separate search page for nodes. Search links for
1744 # different classes can be customized in instance_config similar to
1745 # index links.
1746 #
1747 # Revision 1.114.2.2 2002/04/19 19:54:42 rochecompaan
1748 # cgi_client.py
1749 # removed search link for the time being
1750 # moved rendering of matches to htmltemplate
1751 # hyperdb.py
1752 # filtering of nodes on full text search incorporated in filter method
1753 # roundupdb.py
1754 # added paramater to call of filter method
1755 # roundup_indexer.py
1756 # added search method to RoundupIndexer class
1757 #
1758 # Revision 1.114.2.1 2002/04/03 11:55:57 rochecompaan
1759 # . Added feature #526730 - search for messages capability
1760 #
1761 # Revision 1.114 2002/03/17 23:06:05 richard
1762 # oops
1763 #
1764 # Revision 1.113 2002/03/14 23:59:24 richard
1765 # . #517734 ] web header customisation is obscure
1766 #
1767 # Revision 1.112 2002/03/12 22:52:26 richard
1768 # more pychecker warnings removed
1769 #
1770 # Revision 1.111 2002/02/25 04:32:21 richard
1771 # ahem
1772 #
1773 # Revision 1.110 2002/02/21 07:19:08 richard
1774 # ... and label, width and height control for extra flavour!
1775 #
1776 # Revision 1.109 2002/02/21 07:08:19 richard
1777 # oops
1778 #
1779 # Revision 1.108 2002/02/21 07:02:54 richard
1780 # The correct var is "HTTP_HOST"
1781 #
1782 # Revision 1.107 2002/02/21 06:57:38 richard
1783 # . Added popup help for classes using the classhelp html template function.
1784 # - add <display call="classhelp('priority', 'id,name,description')">
1785 # to an item page, and it generates a link to a popup window which displays
1786 # the id, name and description for the priority class. The description
1787 # field won't exist in most installations, but it will be added to the
1788 # default templates.
1789 #
1790 # Revision 1.106 2002/02/21 06:23:00 richard
1791 # *** empty log message ***
1792 #
1793 # Revision 1.105 2002/02/20 05:52:10 richard
1794 # better error handling
1795 #
1796 # Revision 1.104 2002/02/20 05:45:17 richard
1797 # Use the csv module for generating the form entry so it's correct.
1798 # [also noted the sf.net feature request id in the change log]
1799 #
1800 # Revision 1.103 2002/02/20 05:05:28 richard
1801 # . Added simple editing for classes that don't define a templated interface.
1802 # - access using the admin "class list" interface
1803 # - limited to admin-only
1804 # - requires the csv module from object-craft (url given if it's missing)
1805 #
1806 # Revision 1.102 2002/02/15 07:08:44 richard
1807 # . Alternate email addresses are now available for users. See the MIGRATION
1808 # file for info on how to activate the feature.
1809 #
1810 # Revision 1.101 2002/02/14 23:39:18 richard
1811 # . All forms now have "double-submit" protection when Javascript is enabled
1812 # on the client-side.
1813 #
1814 # Revision 1.100 2002/01/16 07:02:57 richard
1815 # . lots of date/interval related changes:
1816 # - more relaxed date format for input
1817 #
1818 # Revision 1.99 2002/01/16 03:02:42 richard
1819 # #503793 ] changing assignedto resets nosy list
1820 #
1821 # Revision 1.98 2002/01/14 02:20:14 richard
1822 # . changed all config accesses so they access either the instance or the
1823 # config attriubute on the db. This means that all config is obtained from
1824 # instance_config instead of the mish-mash of classes. This will make
1825 # switching to a ConfigParser setup easier too, I hope.
1826 #
1827 # At a minimum, this makes migration a _little_ easier (a lot easier in the
1828 # 0.5.0 switch, I hope!)
1829 #
1830 # Revision 1.97 2002/01/11 23:22:29 richard
1831 # . #502437 ] rogue reactor and unittest
1832 # in short, the nosy reactor was modifying the nosy list. That code had
1833 # been there for a long time, and I suspsect it was there because we
1834 # weren't generating the nosy list correctly in other places of the code.
1835 # We're now doing that, so the nosy-modifying code can go away from the
1836 # nosy reactor.
1837 #
1838 # Revision 1.96 2002/01/10 05:26:10 richard
1839 # missed a parsePropsFromForm in last update
1840 #
1841 # Revision 1.95 2002/01/10 03:39:45 richard
1842 # . fixed some problems with web editing and change detection
1843 #
1844 # Revision 1.94 2002/01/09 13:54:21 grubert
1845 # _add_assignedto_to_nosy did set nosy to assignedto only, no adding.
1846 #
1847 # Revision 1.93 2002/01/08 11:57:12 richard
1848 # crying out for real configuration handling... :(
1849 #
1850 # Revision 1.92 2002/01/08 04:12:05 richard
1851 # Changed message-id format to "<%s.%s.%s%s@%s>" so it complies with RFC822
1852 #
1853 # Revision 1.91 2002/01/08 04:03:47 richard
1854 # I mucked the intent of the code up.
1855 #
1856 # Revision 1.90 2002/01/08 03:56:55 richard
1857 # Oops, missed this before the beta:
1858 # . #495392 ] empty nosy -patch
1859 #
1860 # Revision 1.89 2002/01/07 20:24:45 richard
1861 # *mutter* stupid cutnpaste
1862 #
1863 # Revision 1.88 2002/01/02 02:31:38 richard
1864 # Sorry for the huge checkin message - I was only intending to implement #496356
1865 # but I found a number of places where things had been broken by transactions:
1866 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
1867 # for _all_ roundup-generated smtp messages to be sent to.
1868 # . the transaction cache had broken the roundupdb.Class set() reactors
1869 # . newly-created author users in the mailgw weren't being committed to the db
1870 #
1871 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
1872 # on when I found that stuff :):
1873 # . #496356 ] Use threading in messages
1874 # . detectors were being registered multiple times
1875 # . added tests for mailgw
1876 # . much better attaching of erroneous messages in the mail gateway
1877 #
1878 # Revision 1.87 2001/12/23 23:18:49 richard
1879 # We already had an admin-specific section of the web heading, no need to add
1880 # another one :)
1881 #
1882 # Revision 1.86 2001/12/20 15:43:01 rochecompaan
1883 # Features added:
1884 # . Multilink properties are now displayed as comma separated values in
1885 # a textbox
1886 # . The add user link is now only visible to the admin user
1887 # . Modified the mail gateway to reject submissions from unknown
1888 # addresses if ANONYMOUS_ACCESS is denied
1889 #
1890 # Revision 1.85 2001/12/20 06:13:24 rochecompaan
1891 # Bugs fixed:
1892 # . Exception handling in hyperdb for strings-that-look-like numbers got
1893 # lost somewhere
1894 # . Internet Explorer submits full path for filename - we now strip away
1895 # the path
1896 # Features added:
1897 # . Link and multilink properties are now displayed sorted in the cgi
1898 # interface
1899 #
1900 # Revision 1.84 2001/12/18 15:30:30 rochecompaan
1901 # Fixed bugs:
1902 # . Fixed file creation and retrieval in same transaction in anydbm
1903 # backend
1904 # . Cgi interface now renders new issue after issue creation
1905 # . Could not set issue status to resolved through cgi interface
1906 # . Mail gateway was changing status back to 'chatting' if status was
1907 # omitted as an argument
1908 #
1909 # Revision 1.83 2001/12/15 23:51:01 richard
1910 # Tested the changes and fixed a few problems:
1911 # . files are now attached to the issue as well as the message
1912 # . newuser is a real method now since we don't want to do the message/file
1913 # stuff for it
1914 # . added some documentation
1915 # The really big changes in the diff are a result of me moving some code
1916 # around to keep like methods together a bit better.
1917 #
1918 # Revision 1.82 2001/12/15 19:24:39 rochecompaan
1919 # . Modified cgi interface to change properties only once all changes are
1920 # collected, files created and messages generated.
1921 # . Moved generation of change note to nosyreactors.
1922 # . We now check for changes to "assignedto" to ensure it's added to the
1923 # nosy list.
1924 #
1925 # Revision 1.81 2001/12/12 23:55:00 richard
1926 # Fixed some problems with user editing
1927 #
1928 # Revision 1.80 2001/12/12 23:27:14 richard
1929 # Added a Zope frontend for roundup.
1930 #
1931 # Revision 1.79 2001/12/10 22:20:01 richard
1932 # Enabled transaction support in the bsddb backend. It uses the anydbm code
1933 # where possible, only replacing methods where the db is opened (it uses the
1934 # btree opener specifically.)
1935 # Also cleaned up some change note generation.
1936 # Made the backends package work with pydoc too.
1937 #
1938 # Revision 1.78 2001/12/07 05:59:27 rochecompaan
1939 # Fixed small bug that prevented adding issues through the web.
1940 #
1941 # Revision 1.77 2001/12/06 22:48:29 richard
1942 # files multilink was being nuked in post_edit_node
1943 #
1944 # Revision 1.76 2001/12/05 14:26:44 rochecompaan
1945 # Removed generation of change note from "sendmessage" in roundupdb.py.
1946 # The change note is now generated when the message is created.
1947 #
1948 # Revision 1.75 2001/12/04 01:25:08 richard
1949 # Added some rollbacks where we were catching exceptions that would otherwise
1950 # have stopped committing.
1951 #
1952 # Revision 1.74 2001/12/02 05:06:16 richard
1953 # . We now use weakrefs in the Classes to keep the database reference, so
1954 # the close() method on the database is no longer needed.
1955 # I bumped the minimum python requirement up to 2.1 accordingly.
1956 # . #487480 ] roundup-server
1957 # . #487476 ] INSTALL.txt
1958 #
1959 # I also cleaned up the change message / post-edit stuff in the cgi client.
1960 # There's now a clearly marked "TODO: append the change note" where I believe
1961 # the change note should be added there. The "changes" list will obviously
1962 # have to be modified to be a dict of the changes, or somesuch.
1963 #
1964 # More testing needed.
1965 #
1966 # Revision 1.73 2001/12/01 07:17:50 richard
1967 # . We now have basic transaction support! Information is only written to
1968 # the database when the commit() method is called. Only the anydbm
1969 # backend is modified in this way - neither of the bsddb backends have been.
1970 # The mail, admin and cgi interfaces all use commit (except the admin tool
1971 # doesn't have a commit command, so interactive users can't commit...)
1972 # . Fixed login/registration forwarding the user to the right page (or not,
1973 # on a failure)
1974 #
1975 # Revision 1.72 2001/11/30 20:47:58 rochecompaan
1976 # Links in page header are now consistent with default sort order.
1977 #
1978 # Fixed bugs:
1979 # - When login failed the list of issues were still rendered.
1980 # - User was redirected to index page and not to his destination url
1981 # if his first login attempt failed.
1982 #
1983 # Revision 1.71 2001/11/30 20:28:10 rochecompaan
1984 # Property changes are now completely traceable, whether changes are
1985 # made through the web or by email
1986 #
1987 # Revision 1.70 2001/11/30 00:06:29 richard
1988 # Converted roundup/cgi_client.py to use _()
1989 # Added the status file, I18N_PROGRESS.txt
1990 #
1991 # Revision 1.69 2001/11/29 23:19:51 richard
1992 # Removed the "This issue has been edited through the web" when a valid
1993 # change note is supplied.
1994 #
1995 # Revision 1.68 2001/11/29 04:57:23 richard
1996 # a little comment
1997 #
1998 # Revision 1.67 2001/11/28 21:55:35 richard
1999 # . login_action and newuser_action return values were being ignored
2000 # . Woohoo! Found that bloody re-login bug that was killing the mail
2001 # gateway.
2002 # (also a minor cleanup in hyperdb)
2003 #
2004 # Revision 1.66 2001/11/27 03:00:50 richard
2005 # couple of bugfixes from latest patch integration
2006 #
2007 # Revision 1.65 2001/11/26 23:00:53 richard
2008 # This config stuff is getting to be a real mess...
2009 #
2010 # Revision 1.64 2001/11/26 22:56:35 richard
2011 # typo
2012 #
2013 # Revision 1.63 2001/11/26 22:55:56 richard
2014 # Feature:
2015 # . Added INSTANCE_NAME to configuration - used in web and email to identify
2016 # the instance.
2017 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
2018 # signature info in e-mails.
2019 # . Some more flexibility in the mail gateway and more error handling.
2020 # . Login now takes you to the page you back to the were denied access to.
2021 #
2022 # Fixed:
2023 # . Lots of bugs, thanks Roché and others on the devel mailing list!
2024 #
2025 # Revision 1.62 2001/11/24 00:45:42 jhermann
2026 # typeof() instead of type(): avoid clash with database field(?) "type"
2027 #
2028 # Fixes this traceback:
2029 #
2030 # Traceback (most recent call last):
2031 # File "roundup\cgi_client.py", line 535, in newnode
2032 # self._post_editnode(nid)
2033 # File "roundup\cgi_client.py", line 415, in _post_editnode
2034 # if type(value) != type([]): value = [value]
2035 # UnboundLocalError: local variable 'type' referenced before assignment
2036 #
2037 # Revision 1.61 2001/11/22 15:46:42 jhermann
2038 # Added module docstrings to all modules.
2039 #
2040 # Revision 1.60 2001/11/21 22:57:28 jhermann
2041 # Added dummy hooks for I18N and some preliminary (test) markup of
2042 # translatable messages
2043 #
2044 # Revision 1.59 2001/11/21 03:21:13 richard
2045 # oops
2046 #
2047 # Revision 1.58 2001/11/21 03:11:28 richard
2048 # Better handling of new properties.
2049 #
2050 # Revision 1.57 2001/11/15 10:24:27 richard
2051 # handle the case where there is no file attached
2052 #
2053 # Revision 1.56 2001/11/14 21:35:21 richard
2054 # . users may attach files to issues (and support in ext) through the web now
2055 #
2056 # Revision 1.55 2001/11/07 02:34:06 jhermann
2057 # Handling of damaged login cookies
2058 #
2059 # Revision 1.54 2001/11/07 01:16:12 richard
2060 # Remove the '=' padding from cookie value so quoting isn't an issue.
2061 #
2062 # Revision 1.53 2001/11/06 23:22:05 jhermann
2063 # More IE fixes: it does not like quotes around cookie values; in the
2064 # hope this does not break anything for other browser; if it does, we
2065 # need to check HTTP_USER_AGENT
2066 #
2067 # Revision 1.52 2001/11/06 23:11:22 jhermann
2068 # Fixed debug output in page footer; added expiry date to the login cookie
2069 # (expires 1 year in the future) to prevent probs with certain versions
2070 # of IE
2071 #
2072 # Revision 1.51 2001/11/06 22:00:34 jhermann
2073 # Get debug level from ROUNDUP_DEBUG env var
2074 #
2075 # Revision 1.50 2001/11/05 23:45:40 richard
2076 # Fixed newuser_action so it sets the cookie with the unencrypted password.
2077 # Also made it present nicer error messages (not tracebacks).
2078 #
2079 # Revision 1.49 2001/11/04 03:07:12 richard
2080 # Fixed various cookie-related bugs:
2081 # . bug #477685 ] base64.decodestring breaks
2082 # . bug #477837 ] lynx does not like the cookie
2083 # . bug #477892 ] Password edit doesn't fix login cookie
2084 # Also closed a security hole - a logged-in user could edit another user's
2085 # details.
2086 #
2087 # Revision 1.48 2001/11/03 01:30:18 richard
2088 # Oops. uses pagefoot now.
2089 #
2090 # Revision 1.47 2001/11/03 01:29:28 richard
2091 # Login page didn't have all close tags.
2092 #
2093 # Revision 1.46 2001/11/03 01:26:55 richard
2094 # possibly fix truncated base64'ed user:pass
2095 #
2096 # Revision 1.45 2001/11/01 22:04:37 richard
2097 # Started work on supporting a pop3-fetching server
2098 # Fixed bugs:
2099 # . bug #477104 ] HTML tag error in roundup-server
2100 # . bug #477107 ] HTTP header problem
2101 #
2102 # Revision 1.44 2001/10/28 23:03:08 richard
2103 # Added more useful header to the classic schema.
2104 #
2105 # Revision 1.43 2001/10/24 00:01:42 richard
2106 # More fixes to lockout logic.
2107 #
2108 # Revision 1.42 2001/10/23 23:56:03 richard
2109 # HTML typo
2110 #
2111 # Revision 1.41 2001/10/23 23:52:35 richard
2112 # Fixed lock-out logic, thanks Roch'e for pointing out the problems.
2113 #
2114 # Revision 1.40 2001/10/23 23:06:39 richard
2115 # Some cleanup.
2116 #
2117 # Revision 1.39 2001/10/23 01:00:18 richard
2118 # Re-enabled login and registration access after lopping them off via
2119 # disabling access for anonymous users.
2120 # Major re-org of the htmltemplate code, cleaning it up significantly. Fixed
2121 # a couple of bugs while I was there. Probably introduced a couple, but
2122 # things seem to work OK at the moment.
2123 #
2124 # Revision 1.38 2001/10/22 03:25:01 richard
2125 # Added configuration for:
2126 # . anonymous user access and registration (deny/allow)
2127 # . filter "widget" location on index page (top, bottom, both)
2128 # Updated some documentation.
2129 #
2130 # Revision 1.37 2001/10/21 07:26:35 richard
2131 # feature #473127: Filenames. I modified the file.index and htmltemplate
2132 # source so that the filename is used in the link and the creation
2133 # information is displayed.
2134 #
2135 # Revision 1.36 2001/10/21 04:44:50 richard
2136 # bug #473124: UI inconsistency with Link fields.
2137 # This also prompted me to fix a fairly long-standing usability issue -
2138 # that of being able to turn off certain filters.
2139 #
2140 # Revision 1.35 2001/10/21 00:17:54 richard
2141 # CGI interface view customisation section may now be hidden (patch from
2142 # Roch'e Compaan.)
2143 #
2144 # Revision 1.34 2001/10/20 11:58:48 richard
2145 # Catch errors in login - no username or password supplied.
2146 # Fixed editing of password (Password property type) thanks Roch'e Compaan.
2147 #
2148 # Revision 1.33 2001/10/17 00:18:41 richard
2149 # Manually constructing cookie headers now.
2150 #
2151 # Revision 1.32 2001/10/16 03:36:21 richard
2152 # CGI interface wasn't handling checkboxes at all.
2153 #
2154 # Revision 1.31 2001/10/14 10:55:00 richard
2155 # Handle empty strings in HTML template Link function
2156 #
2157 # Revision 1.30 2001/10/09 07:38:58 richard
2158 # Pushed the base code for the extended schema CGI interface back into the
2159 # code cgi_client module so that future updates will be less painful.
2160 # Also removed a debugging print statement from cgi_client.
2161 #
2162 # Revision 1.29 2001/10/09 07:25:59 richard
2163 # Added the Password property type. See "pydoc roundup.password" for
2164 # implementation details. Have updated some of the documentation too.
2165 #
2166 # Revision 1.28 2001/10/08 00:34:31 richard
2167 # Change message was stuffing up for multilinks with no key property.
2168 #
2169 # Revision 1.27 2001/10/05 02:23:24 richard
2170 # . roundup-admin create now prompts for property info if none is supplied
2171 # on the command-line.
2172 # . hyperdb Class getprops() method may now return only the mutable
2173 # properties.
2174 # . Login now uses cookies, which makes it a whole lot more flexible. We can
2175 # now support anonymous user access (read-only, unless there's an
2176 # "anonymous" user, in which case write access is permitted). Login
2177 # handling has been moved into cgi_client.Client.main()
2178 # . The "extended" schema is now the default in roundup init.
2179 # . The schemas have had their page headings modified to cope with the new
2180 # login handling. Existing installations should copy the interfaces.py
2181 # file from the roundup lib directory to their instance home.
2182 # . Incorrectly had a Bizar Software copyright on the cgitb.py module from
2183 # Ping - has been removed.
2184 # . Fixed a whole bunch of places in the CGI interface where we should have
2185 # been returning Not Found instead of throwing an exception.
2186 # . Fixed a deviation from the spec: trying to modify the 'id' property of
2187 # an item now throws an exception.
2188 #
2189 # Revision 1.26 2001/09/12 08:31:42 richard
2190 # handle cases where mime type is not guessable
2191 #
2192 # Revision 1.25 2001/08/29 05:30:49 richard
2193 # change messages weren't being saved when there was no-one on the nosy list.
2194 #
2195 # Revision 1.24 2001/08/29 04:49:39 richard
2196 # didn't clean up fully after debugging :(
2197 #
2198 # Revision 1.23 2001/08/29 04:47:18 richard
2199 # Fixed CGI client change messages so they actually include the properties
2200 # changed (again).
2201 #
2202 # Revision 1.22 2001/08/17 00:08:10 richard
2203 # reverted back to sending messages always regardless of who is doing the web
2204 # edit. change notes weren't being saved. bleah. hackish.
2205 #
2206 # Revision 1.21 2001/08/15 23:43:18 richard
2207 # Fixed some isFooTypes that I missed.
2208 # Refactored some code in the CGI code.
2209 #
2210 # Revision 1.20 2001/08/12 06:32:36 richard
2211 # using isinstance(blah, Foo) now instead of isFooType
2212 #
2213 # Revision 1.19 2001/08/07 00:24:42 richard
2214 # stupid typo
2215 #
2216 # Revision 1.18 2001/08/07 00:15:51 richard
2217 # Added the copyright/license notice to (nearly) all files at request of
2218 # Bizar Software.
2219 #
2220 # Revision 1.17 2001/08/02 06:38:17 richard
2221 # Roundupdb now appends "mailing list" information to its messages which
2222 # include the e-mail address and web interface address. Templates may
2223 # override this in their db classes to include specific information (support
2224 # instructions, etc).
2225 #
2226 # Revision 1.16 2001/08/02 05:55:25 richard
2227 # Web edit messages aren't sent to the person who did the edit any more. No
2228 # message is generated if they are the only person on the nosy list.
2229 #
2230 # Revision 1.15 2001/08/02 00:34:10 richard
2231 # bleah syntax error
2232 #
2233 # Revision 1.14 2001/08/02 00:26:16 richard
2234 # Changed the order of the information in the message generated by web edits.
2235 #
2236 # Revision 1.13 2001/07/30 08:12:17 richard
2237 # Added time logging and file uploading to the templates.
2238 #
2239 # Revision 1.12 2001/07/30 06:26:31 richard
2240 # Added some documentation on how the newblah works.
2241 #
2242 # Revision 1.11 2001/07/30 06:17:45 richard
2243 # Features:
2244 # . Added ability for cgi newblah forms to indicate that the new node
2245 # should be linked somewhere.
2246 # Fixed:
2247 # . Fixed the agument handling for the roundup-admin find command.
2248 # . Fixed handling of summary when no note supplied for newblah. Again.
2249 # . Fixed detection of no form in htmltemplate Field display.
2250 #
2251 # Revision 1.10 2001/07/30 02:37:34 richard
2252 # Temporary measure until we have decent schema migration...
2253 #
2254 # Revision 1.9 2001/07/30 01:25:07 richard
2255 # Default implementation is now "classic" rather than "extended" as one would
2256 # expect.
2257 #
2258 # Revision 1.8 2001/07/29 08:27:40 richard
2259 # Fixed handling of passed-in values in form elements (ie. during a
2260 # drill-down)
2261 #
2262 # Revision 1.7 2001/07/29 07:01:39 richard
2263 # Added vim command to all source so that we don't get no steenkin' tabs :)
2264 #
2265 # Revision 1.6 2001/07/29 04:04:00 richard
2266 # Moved some code around allowing for subclassing to change behaviour.
2267 #
2268 # Revision 1.5 2001/07/28 08:16:52 richard
2269 # New issue form handles lack of note better now.
2270 #
2271 # Revision 1.4 2001/07/28 00:34:34 richard
2272 # Fixed some non-string node ids.
2273 #
2274 # Revision 1.3 2001/07/23 03:56:30 richard
2275 # oops, missed a config removal
2276 #
2277 # Revision 1.2 2001/07/22 12:09:32 richard
2278 # Final commit of Grande Splite
2279 #
2280 # Revision 1.1 2001/07/22 11:58:35 richard
2281 # More Grande Splite
2282 #
2283 #
2284 # vim: set filetype=python ts=4 sw=4 et si