def _update(self, item, format): if format == 'json': params = json.loads(request.body) #elif format == 'atom': # from lxml import etree # params = Setting.parse_xml(etree.fromstring(request.body)) elif format == 'html': from formencode import NestedVariables params = NestedVariables.to_python(request.POST.mixed()) else: raise UnacceptedFormat(format) item.update_from_dict(params) item.save() app_globals.clear_settings() return item
def validate(self, force_validate=False, params=None): """ Runs validation and returns True/False whether form is valid. This will check if the form should be validated (i.e. the request method matches) and the schema validates. Validation will only be run once; subsequent calls to validate() will have no effect, i.e. will just return the original result. The `errors` and `data` dicts will be updated accordingly. `force_validate` : will run validation regardless of request method. `params` : dict or MultiDict of params. By default will use **request.POST** (if HTTP POST) or **request.params**. """ if self.is_validated: return not(self.errors) if not force_validate: if self.method and self.method != self.request.method: return False if params is None: if self.method == "POST": params = self.request.POST else: params = self.request.params params = NestedVariables.to_python(params, None) self.data.update(params) if self.schema: try: self.data = self.schema.deserialize(params) except colander.Invalid, e: self.errors = e.asdict()
def nestedvars_tool(): if hasattr(cherrypy.request, 'params'): cherrypy.request.params = NestedVariables.to_python( cherrypy.request.params or {})
def nestedvars_tool(): if hasattr(cherrypy.request, 'params'): cherrypy.request.params = NestedVariables.to_python(cherrypy.request.params or {})
class AddLuckyNumbersForm(Schema): pre_validators = [NestedVariables()] allow_extra_fields = True filter_extra_fields = True lucky = ForEach(AddLuckyNumberForm())