Example #1
0
 def __call__(self):
     if self.schema_factory is not None:
         self.schema = self.schema_factory()
     if self.use_csrf_token and 'csrf_token' not in self.schema:
         self.schema.children.append(CSRFSchema()['csrf_token'])
     result = super(BaseFormView, self).__call__()
     if isinstance(result, dict):
         result.update(self.more_template_vars())
     return result
Example #2
0
 def __call__(self):
     if self.use_csrf_token and 'csrf_token' not in self.schema:
         self.schema.children.append(CSRFSchema()['csrf_token'])
     try:
         result = FormView.__call__(self)
     except colander.Invalid, exc:
         self.logger.exception(
             "Exception while rendering form "
             "'%s': %s - struct received: %s",
             self.title, exc, self.appstruct())
         raise
    def __call__(self):
        """Build up the schema and return the form view.
        """
        # build the schema if it not exist
        if self.schema is None:
            if self.schema_factory is None:
                self.schema_factory = SettingsSchema
            self.schema = self.schema_factory()
        # append csrf token if needed
        if self.use_csrf_token and 'csrf_token' not in self.schema:
            self.schema.children.append(CSRFSchema()['csrf_token'])
        # enhance the schema with the given definitions
        for setting_obj in self.settings.settings_objs:
            node = colander.SchemaNode(self.colander_type(setting_obj.type)(),
                                       name=setting_obj.field_name,
                                       title=setting_obj.title,
                                       description=setting_obj.description,
                                       default=setting_obj.default)

            self.schema.children.append(node)
        # the names of the children should begin with the module name
        settings = get_settings()
        bind_values = self.settings.bind.copy()
        for child in self.schema.children:
            bind_attrs = bind_values.get(child.name, None)
            if child.name == 'csrf_token':
                continue
            if not child.name.startswith(self.settings.module):
                child.name = "%s-%s" % (self.settings.module, child.name)
                child.default = settings.get(child.name)
            if bind_attrs:
                for k, v in bind_attrs.iteritems():
                    if callable(v):
                        v = v()
                    setattr(child, k, v)
        # Build up the buttons dynamically, so we can check what setting form
        # was saved.
        save = 'save_' + self.form_id
        self.buttons = (deform.Button(save, _(u'Save')),
                        deform.Button('cancel', _(u'Cancel')))
        setattr(self, save + '_success', self.save_success)
        return super(SettingsFormView, self).__call__()
Example #4
0
class SignoutView(FormView):
    schema = CSRFSchema()
    buttons = 'signout',

    def signout_success(self, appstruct):
        return httpexceptions.HTTPSeeOther('/', headers=forget(self.request))
Example #5
0
def login_forms(request):
    return {
        'signin': Form(Signin().bind(request=request)),
        'signout': Form(CSRFSchema().bind(request=request)),
    }