X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fhtmltemplate.py;h=ed0fefff9b5ae62f6a6cac876c86aca879395b78;hb=b943dac0b0687483aece8a79b0d93434665e3899;hp=f39a72bc80daf69024f5a22d81069c1aed1fa7bf;hpb=0de467c34d61f65bf129155a4969591e6c04a115;p=roundup.git diff --git a/roundup/htmltemplate.py b/roundup/htmltemplate.py index f39a72b..ed0feff 100644 --- a/roundup/htmltemplate.py +++ b/roundup/htmltemplate.py @@ -1,15 +1,16 @@ -# $Id: htmltemplate.py,v 1.6 2001-07-29 04:06:42 richard Exp $ +# $Id: htmltemplate.py,v 1.16 2001-08-01 03:52:23 richard Exp $ import os, re, StringIO, urllib, cgi, errno import hyperdb, date class Base: - def __init__(self, db, templates, classname, nodeid=None, form=None): + def __init__(self, db, templates, classname, nodeid=None, form=None, + filterspec=None): # TODO: really not happy with the way templates is passed on here self.db, self.templates = db, templates self.classname, self.nodeid = classname, nodeid - self.form = form + self.form, self.filterspec = form, filterspec self.cl = self.db.classes[self.classname] self.properties = self.cl.getprops() @@ -41,32 +42,12 @@ class Plain(Base): value = str(value) elif propclass.isLinkType: linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() if value: value = str(linkcl.get(value, k)) else: value = '[unselected]' elif propclass.isMultilinkType: linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() value = ', '.join([linkcl.get(i, k) for i in value]) else: s = 'Plain: bad propclass "%s"'%propclass @@ -77,11 +58,21 @@ class Field(Base): to be edited ''' def __call__(self, property, size=None, height=None, showid=0): - if not self.nodeid and self.form is None: + if not self.nodeid and self.form is None and self.filterspec is None: return '[Field: not called from item]' propclass = self.properties[property] if self.nodeid: - value = self.cl.get(self.nodeid, property) + value = self.cl.get(self.nodeid, property, None) + # TODO: remove this from the code ... it's only here for + # handling schema changes, and they should be handled outside + # of this code... + if propclass.isMultilinkType and value is None: + value = [] + elif self.filterspec is not None: + if propclass.isMultilinkType: + value = self.filterspec.get(property, []) + else: + value = self.filterspec.get(property, '') else: # TODO: pull the value from the form if propclass.isMultilinkType: value = [] @@ -98,17 +89,7 @@ class Field(Base): elif propclass.isLinkType: linkcl = self.db.classes[propclass.classname] l = [''%(property, height)] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() for optionid in list: option = linkcl.get(optionid, k) s = '' @@ -171,17 +142,7 @@ class Menu(Base): if propclass.isLinkType: linkcl = self.db.classes[propclass.classname] l = [''%(property, height)] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() for optionid in list: option = linkcl.get(optionid, k) s = '' @@ -241,32 +192,12 @@ class Link(Base): if value is None: return '[not assigned]' linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() linkvalue = linkcl.get(value, k) return '%s'%(linkcl, value, linkvalue) if propclass.isMultilinkType: linkcl = self.db.classes[propclass.classname] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() l = [] for value in value: linkvalue = linkcl.get(value, k) @@ -345,30 +276,22 @@ class Checklist(Base): propclass = self.properties[property] if self.nodeid: value = self.cl.get(self.nodeid, property) + elif self.filterspec is not None: + value = self.filterspec.get(property, []) else: value = [] if propclass.isLinkType or propclass.isMultilinkType: linkcl = self.db.classes[propclass.classname] l = [] - k = linkcl.getkey() - # if the linked-to class doesn't have a key property, then try - # 'name', then 'title' and then just use a random one. - if not k: - linkprops = linkcl.getprops() - if linkprops.has_key('name'): - k = 'name' - elif linkprops.has_key('title'): - k = 'title' - else: - k = linkprops.keys()[0] + k = linkcl.labelprop() for optionid in linkcl.list(): option = linkcl.get(optionid, k) - if optionid in value: + if optionid in value or option in value: checked = 'checked' else: checked = '' l.append('%s:'%( - option, checked, propclass.classname, option)) + option, checked, property, option)) return '\n'.join(l) return '[Checklist: not a link]' @@ -403,6 +326,9 @@ class History(Base): ''' list the history of the item ''' def __call__(self, **args): + if self.nodeid is None: + return "[History: node doesn't exist]" + l = ['', '', '', @@ -476,14 +402,14 @@ def sortby(sort_name, columns, filter, sort, group, filterspec): for name in sort: dir = name[0] if dir == '-': - dir = '' - else: name = name[1:] + else: + dir = '' if sort_name == name: - if dir == '': - s_dir = '-' - elif dir == '-': + if dir == '-': s_dir = '' + else: + s_dir = '-' else: m.append(dir+urllib.quote(name)) m.insert(0, s_dir+urllib.quote(sort_name)) @@ -495,22 +421,23 @@ def index(client, templates, db, classname, filterspec={}, filter=[], columns=[], sort=[], group=[], show_display_form=1, nodeids=None, col_re=re.compile(r']+)">')): globals = { - 'plain': Plain(db, templates, classname, form={}), - 'field': Field(db, templates, classname, form={}), - 'menu': Menu(db, templates, classname, form={}), - 'link': Link(db, templates, classname, form={}), - 'count': Count(db, templates, classname, form={}), - 'reldate': Reldate(db, templates, classname, form={}), - 'download': Download(db, templates, classname, form={}), - 'checklist': Checklist(db, templates, classname, form={}), - 'list': List(db, templates, classname, form={}), - 'history': History(db, templates, classname, form={}), - 'submit': Submit(db, templates, classname, form={}), - 'note': Note(db, templates, classname, form={}) + 'plain': Plain(db, templates, classname, filterspec=filterspec), + 'field': Field(db, templates, classname, filterspec=filterspec), + 'menu': Menu(db, templates, classname, filterspec=filterspec), + 'link': Link(db, templates, classname, filterspec=filterspec), + 'count': Count(db, templates, classname, filterspec=filterspec), + 'reldate': Reldate(db, templates, classname, filterspec=filterspec), + 'download': Download(db, templates, classname, filterspec=filterspec), + 'checklist': Checklist(db, templates, classname, filterspec=filterspec), + 'list': List(db, templates, classname, filterspec=filterspec), + 'history': History(db, templates, classname, filterspec=filterspec), + 'submit': Submit(db, templates, classname, filterspec=filterspec), + 'note': Note(db, templates, classname, filterspec=filterspec) } cl = db.classes[classname] properties = cl.getprops() w = client.write + w('
') try: template = open(os.path.join(templates, classname+'.filter')).read() @@ -521,28 +448,26 @@ def index(client, templates, db, classname, filterspec={}, filter=[], all_filters = [] if template and filter: # display the filter section - w('') w('
Date
') w('') w(' ') w('') replace = IndexTemplateReplace(globals, locals(), filter) w(replace.go(template)) - if columns: - w(''%','.join(columns)) - if filter: - w(''%','.join(filter)) - if sort: - w(''%','.join(sort)) - if group: - w(''%','.join(group)) - for k, v in filterspec.items(): - if type(v) == type([]): v = ','.join(v) - w(''%(k, v)) w('') w('') w('
Filter specification...
 
') - w('') + + # If the filters aren't being displayed, then hide their current + # value in the form + if not filter: + for k, v in filterspec.items(): + if type(v) == type([]): v = ','.join(v) + w(''%(k, v)) + + # make sure that the sorting doesn't get lost either + if sort: + w(''%','.join(sort)) # XXX deviate from spec here ... # load the index section template and figure the default columns from it @@ -630,13 +555,8 @@ def index(client, templates, db, classname, filterspec={}, filter=[], return # now add in the filter/columns/group/etc config table form - w('

') + w('

') w('') - for k,v in filterspec.items(): - if type(v) == type([]): v = ','.join(v) - w(''%(k, v)) - if sort: - w(''%','.join(sort)) names = [] for name in cl.getprops().keys(): if name in all_filters or name in all_columns: @@ -790,13 +710,56 @@ def newitem(client, templates, db, classname, form, replace=re.compile( s = open(os.path.join(templates, classname+'.newitem')).read() except: s = open(os.path.join(templates, classname+'.item')).read() - w(''%classname) + w(''%classname) + for key in form.keys(): + if key[0] == ':': + value = form[key].value + if type(value) != type([]): value = [value] + for value in value: + w(''%(key, value)) replace = ItemTemplateReplace(globals, locals(), None, None) w(replace.go(s)) w('') # # $Log: not supported by cvs2svn $ +# Revision 1.15 2001/07/30 08:12:17 richard +# Added time logging and file uploading to the templates. +# +# Revision 1.14 2001/07/30 06:17:45 richard +# Features: +# . Added ability for cgi newblah forms to indicate that the new node +# should be linked somewhere. +# Fixed: +# . Fixed the agument handling for the roundup-admin find command. +# . Fixed handling of summary when no note supplied for newblah. Again. +# . Fixed detection of no form in htmltemplate Field display. +# +# Revision 1.13 2001/07/30 02:37:53 richard +# Temporary measure until we have decent schema migration. +# +# Revision 1.12 2001/07/30 01:24:33 richard +# Handles new node display now. +# +# Revision 1.11 2001/07/29 09:31:35 richard +# oops +# +# Revision 1.10 2001/07/29 09:28:23 richard +# Fixed sorting by clicking on column headings. +# +# Revision 1.9 2001/07/29 08:27:40 richard +# Fixed handling of passed-in values in form elements (ie. during a +# drill-down) +# +# Revision 1.8 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# +# Revision 1.7 2001/07/29 05:36:14 richard +# Cleanup of the link label generation. +# +# Revision 1.6 2001/07/29 04:06:42 richard +# Fixed problem in link display when Link value is None. +# # Revision 1.5 2001/07/28 08:17:09 richard # fixed use of stylesheet # @@ -816,3 +779,5 @@ def newitem(client, templates, db, classname, form, replace=re.compile( # Revision 1.1 2001/07/22 11:58:35 richard # More Grande Splite # +# +# vim: set filetype=python ts=4 sw=4 et si