All pastes #1385119 Raw Edit

Miscellany

public python v1 · immutable
#1385119 ·published 2009-04-07 18:46 UTC
rendered paste body
from Products.Five.viewlet.viewlet import ViewletBasefrom Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFileclass ProjectEditViewlet(ViewletBase):    sort_order = 0 # not too important probably, the relative sort order    title = "Advanced Preferences" # you need a title or it will explode    def update(self):        """ do nothing -- just satisfying an interface requirement """        pass    template = ZopeTwoPageTemplateFile("editfields.pt")    def render(self):        return self.template()    def save(self):        """        save form data, if necessary. you might not need to do anything here,         if you are using standard ArcheTypes attributes -- they will be saved by         the main project preferences/add form handlers        no return value.         """        # you can do things like:        # do_something_with(self.request.form)        # save_some_project_data(self.context)    def validate(self):        """        like other validate() methods -- access stuff in self.request.form,        and return an 'error mapping' dictionary        always return a dictionary, even an empty one if there are no errors.        """        if self.request.form.has_key('projpass') and self.request.form['projpass'] != 'gandalf':            return {'projpass': "You got the password wrong."}		elif self.request.form.has_key('projtype') and self.request.form['projtype'] is not in ("mentor","industry","incubator","community"):            return {'projtype': "You have got the wrong project type."}        else:            return {}