-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,372 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Finish @types endpoint to be able to add/edit/delete CT schema [Petchesi-Iulian, avoinea] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ extends = | |
|
||
[versions] | ||
plone.restapi = | ||
plone.schema = 1.2.1 | ||
pytz = 2017.3 | ||
zope.interface = 4.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.restapi.deserializer import json_body | ||
from plone.restapi.interfaces import IPloneRestapiLayer | ||
from plone.restapi.services import Service | ||
from plone.restapi.types.utils import add_field | ||
from plone.restapi.types.utils import add_fieldset | ||
from zExceptions import BadRequest | ||
from zope.component import queryMultiAdapter | ||
from zope.interface import alsoProvides | ||
from zope.interface import implementer | ||
from zope.interface import noLongerProvides | ||
from zope.publisher.interfaces import IPublishTraverse | ||
import plone.protect.interfaces | ||
|
||
|
||
@implementer(IPublishTraverse) | ||
class TypesPost(Service): | ||
""" Creates a new field/fieldset | ||
""" | ||
|
||
def __init__(self, context, request): | ||
super(TypesPost, self).__init__(context, request) | ||
self.params = [] | ||
|
||
def publishTraverse(self, request, name): | ||
# Treat any path segments after /@types as parameters | ||
self.params.append(name) | ||
return self | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.