예제 #1
0
파일: put.py 프로젝트: plone/plone.restapi
 def add_fieldsets(self, ctype, data):
     fieldsets = OrderedDict(
         (f.get("id"), f) for f in data.get("fieldsets", []))
     info = get_info_for_type(ctype, self.request, ctype.getId())
     existing = {f.get("id") for f in info.get("fieldsets", [])}
     for name, fieldset in fieldsets.items():
         if name not in existing:
             add_fieldset(ctype, self.request, fieldset)
예제 #2
0
파일: add.py 프로젝트: eea/plone.restapi
    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
예제 #3
0
    def reply_for_fieldset(self, name, fieldset_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"] = fieldset_name

        if create:
            info = get_info_for_type(context, self.request, name)
            existing = {f.get("id") for f in info.get("fieldsets", [])}
            if fieldset_name not in existing:
                add_fieldset(context, self.request, data)
        update_fieldset(context, self.request, data)

        serializeSchema(context.schema)
        return self.reply_no_content()