-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
summary.py
49 lines (40 loc) · 1.45 KB
/
summary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
from plone.app.contentlisting.interfaces import IContentListingObject
from plone.restapi.interfaces import ISerializeToJsonSummary
from Products.CMFPlone.interfaces import IPloneSiteRoot
from zope.component import adapter
from zope.interface import implementer
from zope.interface import Interface
@implementer(ISerializeToJsonSummary)
@adapter(Interface, Interface)
class DefaultJSONSummarySerializer(object):
"""Default ISerializeToJsonSummary adapter.
Requires context to be adaptable to IContentListingObject, which is
the case for all content objects providing IContentish.
"""
def __init__(self, context, request):
self.context = context
self.request = request
def __call__(self):
obj = IContentListingObject(self.context)
summary = {
'@id': obj.getURL(),
'title': obj.Title(),
'description': obj.Description()
}
return summary
@implementer(ISerializeToJsonSummary)
@adapter(IPloneSiteRoot, Interface)
class SiteRootJSONSummarySerializer(object):
"""ISerializeToJsonSummary adapter for the Plone Site root.
"""
def __init__(self, context, request):
self.context = context
self.request = request
def __call__(self):
summary = {
'@id': self.context.absolute_url(),
'title': self.context.title,
'description': self.context.description
}
return summary