示例#1
0
 def api_action_group_edit(self, request):
     validator = DictParameter(
         attrs={"ids": ListOfParameter(element=ModelParameter(self.model), convert=True)}
     )
     rv = self.deserialize(request.body)
     try:
         v = validator.clean(rv)
     except InterfaceTypeError as e:
         self.logger.info("Bad request: %r (%s)", request.body, e)
         return self.render_json(
             {"status": False, "message": "Bad request", "traceback": str(e)},
             status=self.BAD_REQUEST,
         )
     objects = v["ids"]
     del v["ids"]
     try:
         v = self.clean(v)
     except ValueError as e:
         return self.render_json(
             {"status": False, "message": "Bad request", "traceback": str(e)},
             status=self.BAD_REQUEST,
         )
     for o in objects:
         for p in v:
             setattr(o, p, v[p])
         o.save()
     return "%d records has been updated" % len(objects)
示例#2
0
 def clean_config(self, handler):
     v = {}
     if isinstance(handler.config, dict):
         ci = DictParameter(attrs=handler.config)
     else:
         ci = handler.config
     # Read config
     for opt in self.config.options(handler.name):
         if opt not in ("enabled", "handler"):
             v[opt] = self.config.get(handler.name, opt)
     # Clean config
     return ci.clean(v)