Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 999:8d54c0f3198e
Fixed history and its nihilism. Added convenience method for submit buttons
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sat, 31 Aug 2002 12:07:48 +0000 |
| parents | 55ab0c5b49f9 |
| children | 1798d2fa9fec |
comparison
equal
deleted
inserted
replaced
| 998:a1922b2521a7 | 999:8d54c0f3198e |
|---|---|
| 1 import sys, cgi, urllib | 1 import sys, cgi, urllib, os |
| 2 | 2 |
| 3 from roundup import hyperdb, date | 3 from roundup import hyperdb, date |
| 4 from roundup.i18n import _ | 4 from roundup.i18n import _ |
| 5 | 5 |
| 6 | 6 |
| 201 ''' | 201 ''' |
| 202 return '<a href="javascript:help_window(\'classhelp?classname=%s&' \ | 202 return '<a href="javascript:help_window(\'classhelp?classname=%s&' \ |
| 203 'properties=%s\', \'%s\', \'%s\')"><b>(%s)</b></a>'%(self.classname, | 203 'properties=%s\', \'%s\', \'%s\')"><b>(%s)</b></a>'%(self.classname, |
| 204 properties, width, height, label) | 204 properties, width, height, label) |
| 205 | 205 |
| 206 def submit(self, label="Submit New Entry"): | |
| 207 ''' Generate a submit button (and action hidden element) | |
| 208 ''' | |
| 209 return ' <input type="hidden" name=":action" value="new">\n'\ | |
| 210 ' <input type="submit" name="submit" value="%s">'%label | |
| 211 | |
| 206 def history(self): | 212 def history(self): |
| 207 return 'New node - no history' | 213 return 'New node - no history' |
| 208 | 214 |
| 209 def renderWith(self, name, **kwargs): | 215 def renderWith(self, name, **kwargs): |
| 210 ''' Render this class with the given template. | 216 ''' Render this class with the given template. |
| 263 if isinstance(prop, klass): | 269 if isinstance(prop, klass): |
| 264 return htmlklass(self.db, self.nodeid, prop, attr, value) | 270 return htmlklass(self.db, self.nodeid, prop, attr, value) |
| 265 | 271 |
| 266 # no good | 272 # no good |
| 267 raise AttributeError, attr | 273 raise AttributeError, attr |
| 274 | |
| 275 def submit(self, label="Submit Changes"): | |
| 276 ''' Generate a submit button (and action hidden element) | |
| 277 ''' | |
| 278 return ' <input type="hidden" name=":action" value="edit">\n'\ | |
| 279 ' <input type="submit" name="submit" value="%s">'%label | |
| 268 | 280 |
| 269 # XXX this probably should just return the history items, not the HTML | 281 # XXX this probably should just return the history items, not the HTML |
| 270 def history(self, direction='descending'): | 282 def history(self, direction='descending'): |
| 271 l = ['<table width=100% border=0 cellspacing=0 cellpadding=2>', | 283 l = ['<table width=100% border=0 cellspacing=0 cellpadding=2>', |
| 272 '<tr class="list-header">', | 284 '<tr class="list-header">', |
| 303 cell = [] | 315 cell = [] |
| 304 for k in args.keys(): | 316 for k in args.keys(): |
| 305 # try to get the relevant property and treat it | 317 # try to get the relevant property and treat it |
| 306 # specially | 318 # specially |
| 307 try: | 319 try: |
| 308 prop = props[k] | 320 prop = self.props[k] |
| 309 except: | 321 except KeyError: |
| 310 prop = None | 322 prop = None |
| 311 if prop is not None: | 323 if prop is not None: |
| 312 if args[k] and (isinstance(prop, hyperdb.Multilink) or | 324 if args[k] and (isinstance(prop, hyperdb.Multilink) or |
| 313 isinstance(prop, hyperdb.Link)): | 325 isinstance(prop, hyperdb.Link)): |
| 314 # figure what the link class is | 326 # figure what the link class is |
| 318 except KeyError: | 330 except KeyError: |
| 319 labelprop = None | 331 labelprop = None |
| 320 comments[classname] = _('''The linked class | 332 comments[classname] = _('''The linked class |
| 321 %(classname)s no longer exists''')%locals() | 333 %(classname)s no longer exists''')%locals() |
| 322 labelprop = linkcl.labelprop(1) | 334 labelprop = linkcl.labelprop(1) |
| 323 # hrefable = os.path.exists( | 335 hrefable = os.path.exists( |
| 324 # os.path.join(self.instance.TEMPLATES, | 336 os.path.join(self.db.config.TEMPLATES, |
| 325 # classname+'.item')) | 337 classname+'.item')) |
| 326 | 338 |
| 327 if isinstance(prop, hyperdb.Multilink) and \ | 339 if isinstance(prop, hyperdb.Multilink) and \ |
| 328 len(args[k]) > 0: | 340 len(args[k]) > 0: |
| 329 ml = [] | 341 ml = [] |
| 330 for linkid in args[k]: | 342 for linkid in args[k]: |
| 347 comments['no_link'] = _('''<strike>The | 359 comments['no_link'] = _('''<strike>The |
| 348 linked node no longer | 360 linked node no longer |
| 349 exists</strike>''') | 361 exists</strike>''') |
| 350 subml.append('<strike>%s</strike>'%label) | 362 subml.append('<strike>%s</strike>'%label) |
| 351 else: | 363 else: |
| 352 # if hrefable: | 364 if hrefable: |
| 353 subml.append('<a href="%s%s">%s</a>'%( | 365 subml.append('<a href="%s%s">%s</a>'%( |
| 354 classname, linkid, label)) | 366 classname, linkid, label)) |
| 355 ml.append(sublabel + ', '.join(subml)) | 367 ml.append(sublabel + ', '.join(subml)) |
| 356 cell.append('%s:\n %s'%(k, ', '.join(ml))) | 368 cell.append('%s:\n %s'%(k, ', '.join(ml))) |
| 357 elif isinstance(prop, hyperdb.Link) and args[k]: | 369 elif isinstance(prop, hyperdb.Link) and args[k]: |
| 358 label = classname + args[k] | 370 label = classname + args[k] |
| 359 # if we have a label property, try to use it | 371 # if we have a label property, try to use it |
