Exemplo n.º 1
0
    def output_relative_to(self):
        """Transform the raw value to the output mimetype, within a specified context.

        If the value's mimetype is already the same as the output mimetype,
        no transformation is performed.

        The context parameter is relevant when the transformation is
        context-dependent. For example, Guillotina's resolveuid-and-caption
        transform converts relative links to absolute links using the context
        as a base.

        If a transformer cannot be found for the specified context, a
        transformer with the container as a context is used instead.
        """
        if self.mimeType == self.outputMimeType:
            return self.raw_encoded

        transformer = queryAdapter(self, ITransformer, self.outputMimeType)
        if transformer is None:
            return None

        return transformer()
Exemplo n.º 2
0
    async def __call__(self, value):
        headers = {}
        if _is_guillotina_response(value):
            json_value = value.response
            headers = value.headers
            status = value.status
        else:
            # Not a Response object, don't convert
            return value
        # Framing of options
        frame = self.request.get('frame')
        frame = self.request.GET['frame'] if 'frame' in self.request.GET else ''
        if frame:
            framer = queryAdapter(self.request, IFrameFormatsJson, frame)
            json_value = await framer(json_value)
        resp = json_response(json_value)
        resp.headers.update(headers)
        resp.headers.update({'Content-Type': 'application/json'})
        resp.set_status(status)
        # Actions / workflow / roles

        return resp
Exemplo n.º 3
0
async def default_get(context, request):
    """We show the available schemas."""
    result = {}
    factory = get_cached_factory(context.type_name)
    result['static'] = []
    for schema in factory.behaviors or ():
        result['static'].append(schema.__identifier__)

    # convert to list, could be frozenset
    result['dynamic'] = [b for b in context.__behaviors__]

    result['available'] = []

    for iface, utility in getUtilitiesFor(IBehavior):
        serialize = False
        if isinstance(iface, str):
            name = iface
        else:
            name = iface.__identifier__
        if name not in result['dynamic'] and name not in result['static']:
            adaptable = queryAdapter(context,
                                     utility.interface,
                                     name='',
                                     default=None)
            if adaptable:
                result['available'].append(name)
                serialize = True
                schema_serializer = getMultiAdapter(
                    (utility.interface, request), ISchemaSerializeToJson)
                result[name] = await schema_serializer()
        else:
            serialize = True
        if serialize:
            schema_serializer = getMultiAdapter((utility.interface, request),
                                                ISchemaSerializeToJson)
            result[name] = await schema_serializer()
    return result
Exemplo n.º 4
0
 async def get_data(self, content):
     data = {}
     adapter = queryAdapter(content, ICatalogDataAdapter)
     if adapter:
         data.update(await adapter())
     return data
Exemplo n.º 5
0
 async def get_json(self):
     if not app_settings.get('store_json', True):
         return {}
     adapter = queryAdapter(self._obj, ICatalogDataAdapter)
     if adapter is not None:
         return await adapter()
Exemplo n.º 6
0
 def _callFUT(self, *args, **kw):
     from guillotina.component import queryAdapter
     return queryAdapter(*args, **kw)
Exemplo n.º 7
0
 async def get_json(self):
     adapter = queryAdapter(self._obj, ICatalogDataAdapter)
     if adapter is not None:
         return await adapter()
Exemplo n.º 8
0
 def part(self):
     if self._obj is not None:
         adapter = queryAdapter(self._obj, IPartition)
         if adapter is not None:
             return adapter()
     return None