Tools for the job

Jeremy Lowery jslowery at hotmail.com
Fri Nov 30 01:20:22 EST 2001


I'm looking for an easy way to disconnect a class instance that contains biz
logic from the presentation of that object (in this case, HTML), maybe some
kind of delegation is needed. Could someone point me to a module that has a
simple cure?

Basically, some code like this:
class CheckField(ListBaseField):
    """
    A standard check field that is marked off as an item
    on the list.
    """
    def __init__(self, name):
        ListBaseField.__init__(self, name)
    def assignValue(self, value, user):
        self.value = str(str2bool(value, 1))
        self.user = user
    def display(self):
        print '<b>%s</b>' % (self.name)
        if self.value: print 'checked (%s)' % (self.user.display())
        else: print 'unchecked'
    def printNewForm(self, list):
        print '%s <input type="check" name="%s_%s" />' % (self.name,
list.name, self.name)
    def parseForm(self, list, fs):
        fname = '%s_%s' % (list.name, self.name)
        if fs.has_key(fname):
            self.assignValue(fs[fname])
        else:
            return 0
        return self.value

As I'm sure a lot of other designers feel, I don't like plugging HTML code
into strings inside my business object's defintions. Maybe a template
mechanism or something?
Of course, there are a lot of the usual ways to do this, I was just
wondering if Python had some snazzy builtin or known module that did this
kind of stuff.

Jeremy







More information about the Python-list mailing list