How to use the template.Base function in template

To help you get started, we’ve selected a few template examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github roundup-tracker / roundup / template.py View on Github external
def __call__(self, **args):
        l = ['',
            '',
            '',
            '',
            '',
            '']

        for id, date, user, action, args in self.cl.history(self.nodeid):
            l.append(''%(
               date, user, action, args))
        l.append('<table cellpadding="2" cellspacing="0" border="0" width="100%"><tbody><tr class="list-header"><td><span class="list-item"><strong>Date</strong></span></td><td><span class="list-item"><strong>User</strong></span></td><td><span class="list-item"><strong>Action</strong></span></td><td><span class="list-item"><strong>Args</strong></span></td></tr><tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr></tbody></table>')
        return '\n'.join(l)

# XXX new function
class Submit(Base):
    ''' add a submit button for the item
    '''
    def __call__(self):
        if self.nodeid:
            return '<input value="Submit Changes" type="submit">'
        elif self.form is not None:
            return '<input value="Submit New Entry" type="submit">'
        else:
            return '[Submit: not called from item]'


#
#   INDEX TEMPLATES
#
class IndexTemplateReplace:
    def __init__(self, globals, locals, props):
github roundup-tracker / roundup / template.py View on Github external
l.append('%s:<input value="%s" name="%s" type="checkbox">'%(
                    option, checked, propclass.classname, option))
            return '\n'.join(l)
        return '[Checklist: not a link]'

class Note(Base):
    ''' display a "note" field, which is a text area for entering a note to
        go along with a change. 
    '''
    def __call__(self, rows=5, cols=80):
       # TODO: pull the value from the form
        return '<textarea cols="%s" rows="%s" name="__note"></textarea>'%(rows,
            cols)

# XXX new function
class List(Base):
    ''' list the items specified by property using the standard index for
        the class
    '''
    def __call__(self, property, **args):
        propclass = self.properties[property]
        if not propclass.isMultilinkType:
            return '[List: not a Multilink]'
        fp = StringIO.StringIO()
        args['show_display_form'] = 0
        value = self.cl.get(self.nodeid, property)
        index(fp, self.db, propclass.classname, nodeids=value,
            show_display_form=0)
        return fp.getvalue()

# XXX new function
class History(Base):
github roundup-tracker / roundup / template.py View on Github external
value = self.cl.get(self.nodeid, property)
        if propclass.isLinkType:
            linkcl = self.db.classes[propclass.classname]
            linkvalue = linkcl.get(value, k)
            return '<a href="%s%s">%s</a>'%(linkcl, value, linkvalue)
        if propclass.isMultilinkType:
            linkcl = self.db.classes[propclass.classname]
            l = []
            for value in value:
                linkvalue = linkcl.get(value, k)
                l.append('<a href="%s%s">%s</a>'%(linkcl, value, linkvalue))
            return ', '.join(l)
        return '[Download: not a link]'


class Checklist(Base):
    ''' for a Link or Multilink property, display checkboxes for the available
        choices to permit filtering
    '''
    def __call__(self, property, **args):
        propclass = self.properties[property]
        if self.nodeid:
            value = self.cl.get(self.nodeid, property)
        else:
            value = []
        if propclass.isLinkType or propclass.isMultilinkType:
            linkcl = self.db.classes[propclass.classname]
            l = []
            k = linkcl.getkey()
            for optionid in linkcl.list():
                option = linkcl.get(optionid, k)
                if optionid in value:
github roundup-tracker / roundup / template.py View on Github external
if propclass.isLinkType or propclass.isMultilinkType:
            linkcl = self.db.classes[propclass.classname]
            l = []
            k = linkcl.getkey()
            for optionid in linkcl.list():
                option = linkcl.get(optionid, k)
                if optionid in value:
                    checked = 'checked'
                else:
                    checked = ''
                l.append('%s:<input value="%s" name="%s" type="checkbox">'%(
                    option, checked, propclass.classname, option))
            return '\n'.join(l)
        return '[Checklist: not a link]'

class Note(Base):
    ''' display a "note" field, which is a text area for entering a note to
        go along with a change. 
    '''
    def __call__(self, rows=5, cols=80):
       # TODO: pull the value from the form
        return '<textarea cols="%s" rows="%s" name="__note"></textarea>'%(rows,
            cols)

# XXX new function
class List(Base):
    ''' list the items specified by property using the standard index for
        the class
    '''
    def __call__(self, property, **args):
        propclass = self.properties[property]
        if not propclass.isMultilinkType:
github roundup-tracker / roundup / template.py View on Github external
if optionid in value:
                    s = 'selected '
                if showid:
                    lab = '%s%s: %s'%(propclass.classname, optionid, option)
                else:
                    lab = option
                if size is not None and len(lab) &gt; size:
                    lab = lab[:size-3] + '...'
                l.append('<option>%s</option>'%(s, optionid, lab))
            l.append('')
            s = '\n'.join(l)
        else:
            s = 'Plain: bad propclass "%s"'%propclass
        return s

class Menu(Base):
    ''' for a Link property, display a menu of the available choices
    '''
    def __call__(self, property, size=None, height=None, showid=0):
        propclass = self.properties[property]
        if self.nodeid:
            value = self.cl.get(self.nodeid, property)
        else:
            # TODO: pull the value from the form
            if propclass.isMultilinkType: value = []
            else: value = None
        if propclass.isLinkType:
            linkcl = self.db.classes[propclass.classname]
            l = ['<select name="%s">'%property]
            k = linkcl.getkey()
            for optionid in linkcl.list():
                option = linkcl.get(optionid, k)</select>
github roundup-tracker / roundup / template.py View on Github external
s = ''
                if optionid in value:
                    s = 'selected '
                if showid:
                    lab = '%s%s: %s'%(propclass.classname, optionid, option)
                else:
                    lab = option
                if size is not None and len(lab) &gt; size:
                    lab = lab[:size-3] + '...'
                l.append('<option>%s</option>'%(s, optionid, option))
            l.append('')
            return '\n'.join(l)
        return '[Menu: not a link]'

#XXX deviates from spec
class Link(Base):
    ''' for a Link or Multilink property, display the names of the linked
        nodes, hyperlinked to the item views on those nodes
        for other properties, link to this node with the property as the text
    '''
    def __call__(self, property=None, **args):
        if not self.nodeid and self.form is None:
            return '[Link: not called from item]'
        propclass = self.properties[property]
        if self.nodeid:
            value = self.cl.get(self.nodeid, property)
        else:
            if propclass.isMultilinkType: value = []
            else: value = ''
        if propclass.isLinkType:
            linkcl = self.db.classes[propclass.classname]
            linkvalue = linkcl.get(value, k)
github roundup-tracker / roundup / template.py View on Github external
return '[Reldate: not a Date]'
        if self.nodeid:
            value = self.cl.get(self.nodeid, property)
        else:
            value = date.Date('.')
        interval = value - date.Date('.')
        if pretty:
            if not self.nodeid:
                return 'now'
            pretty = interval.pretty()
            if pretty is None:
                pretty = value.pretty()
            return pretty
        return str(interval)

class Download(Base):
    ''' show a Link("file") or Multilink("file") property using links that
        allow you to download files
    '''
    def __call__(self, property, **args):
        if not self.nodeid:
            return '[Download: not called from item]'
        propclass = self.properties[property]
        value = self.cl.get(self.nodeid, property)
        if propclass.isLinkType:
            linkcl = self.db.classes[propclass.classname]
            linkvalue = linkcl.get(value, k)
            return '<a href="%s%s">%s</a>'%(linkcl, value, linkvalue)
        if propclass.isMultilinkType:
            linkcl = self.db.classes[propclass.classname]
            l = []
            for value in value:
github roundup-tracker / roundup / template.py View on Github external
''' list the items specified by property using the standard index for
        the class
    '''
    def __call__(self, property, **args):
        propclass = self.properties[property]
        if not propclass.isMultilinkType:
            return '[List: not a Multilink]'
        fp = StringIO.StringIO()
        args['show_display_form'] = 0
        value = self.cl.get(self.nodeid, property)
        index(fp, self.db, propclass.classname, nodeids=value,
            show_display_form=0)
        return fp.getvalue()

# XXX new function
class History(Base):
    ''' list the history of the item
    '''
    def __call__(self, **args):
        l = ['',
            '',
            '',
            '',
            '',
            '']

        for id, date, user, action, args in self.cl.history(self.nodeid):
            l.append(''%(
               date, user, action, args))
        l.append('<table cellpadding="2" cellspacing="0" border="0" width="100%"><tbody><tr class="list-header"><td><span class="list-item"><strong>Date</strong></span></td><td><span class="list-item"><strong>User</strong></span></td><td><span class="list-item"><strong>Action</strong></span></td><td><span class="list-item"><strong>Args</strong></span></td></tr><tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr></tbody></table>')
        return '\n'.join(l)
github roundup-tracker / roundup / template.py View on Github external
# $Id: template.py,v 1.5 2001-07-20 07:34:43 richard Exp $

import os, re, StringIO, urllib, cgi

import hyperdb, date

class Base:
    def __init__(self, db, classname, nodeid=None, form=None):
        self.db, self.classname, self.nodeid = db, classname, nodeid
        self.form = form
        self.cl = self.db.classes[self.classname]
        self.properties = self.cl.getprops()

class Plain(Base):
    ''' display a String property directly;

        display a Date property in a specified time zone with an option to
        omit the time from the date stamp;

        for a Link or Multilink property, display the key strings of the
        linked nodes (or the ids if the linked class has no key property)
    '''
    def __call__(self, property):
        if not self.nodeid and self.form is None:
            return '[Field: not called from item]'
        propclass = self.properties[property]
        if self.nodeid:
            value = self.cl.get(self.nodeid, property)
        else:
            # TODO: pull the value from the form
github roundup-tracker / roundup / template.py View on Github external
value = str(value)
        elif propclass.isIntervalType:
            value = str(value)
        elif propclass.isLinkType:
            linkcl = self.db.classes[propclass.classname]
            if value: value = str(linkcl.get(value, linkcl.getkey()))
            else: value = '[unselected]'
        elif propclass.isMultilinkType:
            linkcl = self.db.classes[propclass.classname]
            k = linkcl.getkey()
            value = ', '.join([linkcl.get(i, k) for i in value])
        else:
            s = 'Plain: bad propclass "%s"'%propclass
        return value

class Field(Base):
    ''' display a property like the plain displayer, but in a text field
        to be edited
    '''
    def __call__(self, property, size=None, height=None, showid=0):
        if not self.nodeid and self.form is None:
            return '[Field: not called from item]'
        propclass = self.properties[property]
        if self.nodeid:
            value = self.cl.get(self.nodeid, property)
        else:
            # TODO: pull the value from the form
            if propclass.isMultilinkType: value = []
            else: value = ''
        if (propclass.isStringType or propclass.isDateType or
                propclass.isIntervalType):
            size = size or 30