Comments (4)
I recently did this in our own project integration of plone.restapi
.
I would propose to include @type
in the default summary (and maybe drop description
while we're at it). @tisto any thoughts regarding this?
@pigeonflight for now, this can be done by registering your own ISerializeToJsonSummary
adapter for your project's browser layer:
from my.project import IMyProjectLayer
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.serializer.summary import DefaultJSONSummarySerializer
from zope.component import adapter
from zope.interface import implementer
from zope.interface import Interface
@implementer(ISerializeToJsonSummary)
@adapter(Interface, IMyProjectLayer)
class MyJSONSummarySerializer(DefaultJSONSummarySerializer):
"""Customize summary representations to include the object's portal_type.
"""
def __init__(self, context, request):
self.context = context
self.request = request
def __call__(self):
# Get the default summary first, then modify it as needed
summary = super(MyJSONSummarySerializer, self).__call__()
# Include portal_type
summary['@type'] = self.context.portal_type
return summary
<adapter factory=".summary.MyJSONSummarySerializer" />
Note that this will override the DefaultJSONSummarySerializer
and therefore affect summary representations for items other than the site root in all places (not just collections, but also relation lists, folder contents, parent pointers (and eventually search results)).
Also note that plone.restapi
is still in pre-alpha state: This behavior might still change in the future.
from plone.restapi.
@lukasgraf thanks for the pointer, will look into that.
Definitely keep description. plone.restapi advertises itself as an "out of the box" restful api for Plone. In that context the description is important.
Having the type will allow me to filter the json results based on content type.
BTW.. I'm on a project now where we're using Plone as an API.
update:
@lukasgraf I just tested the workaround. Works very well. I needed to swap out the "IMyProjectLayer" of course for my own, apart from that, it works as advertised! Thanks again.
from plone.restapi.
@lukasgraf +1 for adding a type to listing (and keep the description). I wasn't 100% sure if we should use "@type" or just "type" since "@type" has a very specifig meaning in JSON-LD/Hydra. Though, I think "@type" is the correct key to use. See:
https://www.w3.org/TR/json-ld/#typed-values
https://www.hydra-cg.com/spec/latest/core/#collections
http://stackoverflow.com/a/25306010/644831 (first answer by the main author of hydra)
from plone.restapi.
I also believe @type
is correct - the way I understand it, it should be a term in one of the document's vocabularies. Eventually, that term should be derefenceable (be an URI that can actually be fetched), but it may very well be a relative URI, as described in the StackOverflow example above.
The way I understand it, we would eventually be building our own dynamic JSON-LD contexts, vocabularies and types, based on information from FTIs, (probably annotated) schema interfaces, and field types. Related: #11
from plone.restapi.
Related Issues (20)
- relatedItems field returns None in the serializer if the related item is deleted HOT 1
- Site Administrator cannot add user to group
- Add remote_url(getRemoteUrl) to link content-types in navigation HOT 4
- Include release notes in Plone 6 Documentation
- Authentication error messages from PAS Plugins aren't returned by the restapi HOT 1
- restapi double parameter is broking code. HOT 8
- In content that uses the plone.blocks behavior, it is not possible to add fields to SearchableText with "plone.app.dexterity.textindexer" HOT 6
- Community Forum App Icon Not Filling Correctly. HOT 1
- Add plone.app.discussion control panel
- Types control panel does not allow to enable/disable discussion for a content type
- Implement SummaryDiscussionListingTemplate to fix Discussion url in listings HOT 1
- Documentation of event content type does not return a timezone
- NoneType' object has no attribute 'getProperty': when searching users HOT 1
- @querystring shouldn't list userids
- Test with Plone 6.1 HOT 1
- Require plone.app.iterate on test extras
- Require plone.app.upgrade in test extras
- @aliases endpoint should allow to filter by how an alias has been added (automatically, manually)
- @aliases endpoint should support filtering by date (from, to) HOT 3
- @aliases endpoint should allow to upload/download all aliases and allow to download filtered aliases as CSV file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plone.restapi.