Person_getHateoasComputerList.py 1.16 KB
Newer Older
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
from zExceptions import Unauthorized
if REQUEST is None:
  raise Unauthorized

response = REQUEST.RESPONSE
mime_type = 'application/hal+json'

if REQUEST.other['method'] != "GET":
  response.setStatus(405)
  return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
  response.setStatus(406)
  return ""
elif context.getPortalType() != "Person":
  response.setStatus(403)
  return ""

import json
result_dict = {
  '_links': {
    "self": { "href": context.Base_getRequestUrl() },
    # XXX current type
    "index": {
      "href": "urn:jio:get:%s" % context.getRelativeUrl(),
      "title": "Person"
    },
    "content": [],
  },
}

for sql_obj in context.getPortalObject().portal_catalog(
                                               portal_type="Computer",
                                               default_source_administration_uid=context.getUid(),
                                               ):
  obj = sql_obj.getObject()
  result_dict['_links']['content'].append({
    'href': '%s/ERP5Document_getHateoas' % obj.absolute_url(),
38
    'title': sql_obj.title,
39 40 41 42
  })

response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)