exposse pointing docs
This commit is contained in:
parent
3989284f75
commit
8fb46ade9a
|
@ -3,14 +3,22 @@ import time
|
|||
|
||||
from DateTime import DateTime
|
||||
|
||||
from zope import component
|
||||
from zope.app.intid.interfaces import IIntIds
|
||||
from zc.relation.interfaces import ICatalog
|
||||
from plone.dexterity import utils
|
||||
import plone.dexterity.schema
|
||||
from Products.Five import BrowserView
|
||||
|
||||
import themis.fields
|
||||
|
||||
from utils import UtilityView, convert
|
||||
|
||||
class GenericJson(BrowserView):
|
||||
def __call__(self):
|
||||
intids = component.getUtility(IIntIds)
|
||||
catalog = component.getUtility(ICatalog)
|
||||
|
||||
basename = self.context.portal_type
|
||||
schemaName = utils.portalTypeToSchemaName(basename)
|
||||
schema = getattr(plone.dexterity.schema.generated, schemaName)
|
||||
|
@ -18,8 +26,12 @@ class GenericJson(BrowserView):
|
|||
for attr in schema.names():
|
||||
if not hasattr(self.context, attr):
|
||||
continue
|
||||
value = getattr(self.context, attr)
|
||||
d[attr] = convert(value, attr, context=self.context)
|
||||
if isinstance(schema._InterfaceClass__attrs[attr], themis.fields.PointingDocs):
|
||||
doc_intid = intids.getId(self.context)
|
||||
d[attr] = [x.from_object.getId() for x in catalog.findRelations({'to_id': doc_intid})]
|
||||
else:
|
||||
value = getattr(self.context, attr)
|
||||
d[attr] = convert(value, attr, context=self.context)
|
||||
d['id'] = self.context.id
|
||||
d['object_type'] = self.context.Type()
|
||||
d['portal_type'] = basename
|
||||
|
|
Reference in New Issue