def add_fields(self, ctype, data): allow = [ctype.schema.__identifier__, ""] required = data.get("required", []) for name, field in data.get("properties", {}).items(): if name in ctype.schema: continue behavior = field.get("behavior", "") if behavior not in allow: continue if name in required: field["required"] = True field["id"] = name add_field(ctype, self.request, field)
def reply(self): if not self.params: raise BadRequest("Missing parameter typename") data = json_body(self.request) # Disable CSRF protection if "IDisableCSRFProtection" in dir(plone.protect.interfaces): alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection) # Make sure we get the right dexterity-types adapter if IPloneRestapiLayer.providedBy(self.request): noLongerProvides(self.request, IPloneRestapiLayer) name = self.params.pop() context = queryMultiAdapter((self.context, self.request), name="dexterity-types") context = context.publishTraverse(self.request, name) factory = data.get("factory", None) if not factory: raise BadRequest("Missing parameter: 'factory'") if factory == "fieldset": res = add_fieldset(context, self.request, data) else: res = add_field(context, self.request, data) self.request.response.setStatus(201) return res
def reply_for_field(self, name, field_name, data, create=False): context = queryMultiAdapter((self.context, self.request), name="dexterity-types") # Get content type SchemaContext context = context.publishTraverse(self.request, name) data["id"] = field_name if create: info = get_info_for_type(context, self.request, name) existing = info.get("properties", {}) if field_name not in existing: add_field(context, self.request, data) if field_name in context.schema: update_field(context, self.request, data) serializeSchema(context.schema) return self.reply_no_content()