コード例 #1
0
async def deserialize_cloud_field(field, value, context):
    data_context = context
    if IContentBehavior.implementedBy(context.__class__):
        field = field.bind(context)
        context = context.context
    else:
        field = field.bind(context)

    if isinstance(value, dict):
        try:
            file_ob = field.get(data_context)
        except AttributeError:
            return
        if file_ob:
            # update file fields
            for key, item_value in value.items():
                if key in serialize_mappings:
                    setattr(file_ob, serialize_mappings[key], item_value)
            data_context._p_register()
            return file_ob
    else:
        value = convert_base64_to_binary(value)
        request = get_current_request()
        file_manager = get_multi_adapter((context, request, field),
                                         IFileManager)
        val = await file_manager.save_file(partial(_generator, value),
                                           content_type=value['content_type'],
                                           size=len(value['data']))
        return val
コード例 #2
0
def find_field(content, name):
    if IContentBehavior.implementedBy(content.__class__):
        content = content.context
    while content is not None:
        if IDynamicFields.__identifier__ in content.__behaviors__:
            behavior = IDynamicFields(content)
            _fields = behavior.fields or {}
            if name in _fields:
                return _fields[name]
        content = content.__parent__
コード例 #3
0
 async def __call__(self, context, request):
     if IContentBehavior.implementedBy(context.__class__):
         field = self.field.bind(context)
         context = context.context
     else:
         field = self.field.bind(context)
     file_manager = getMultiAdapter((context, request, field), IFileManager)
     val = await file_manager.save_file(
         self.generator,
         content_type=self.value['content_type'],
         size=len(self.value['data']))
     return val
コード例 #4
0
async def deserialize_cloud_field(field, value, context):
    request = get_current_request()
    value = convert_base64_to_binary(value)
    if IContentBehavior.implementedBy(context.__class__):
        field = field.bind(context)
        context = context.context
    else:
        field = field.bind(context)
    file_manager = get_multi_adapter((context, request, field), IFileManager)
    val = await file_manager.save_file(partial(_generator, value),
                                       content_type=value['content_type'],
                                       size=len(value['data']))
    return val
コード例 #5
0
ファイル: annotation.py プロジェクト: nazrulworld/guillotina
    async def set(self, obj, value):
        obj._p_register()
        if IContentBehavior.providedBy(obj):
            anno_context = obj.__dict__['context']
            self.__key_name__ = obj.__dict__['schema'].__identifier__ + '.' + self.__name__
        else:
            anno_context = obj
            self.__key_name__ = self.__name__

        operation_name = value['op']
        bound_field = self.bind(obj)
        operation = query_adapter(bound_field, IPatchFieldOperation, name=operation_name)
        await operation(obj, anno_context, value['value'])
コード例 #6
0
    async def set(self, obj, value):

        if IContentBehavior.providedBy(obj):
            anno_context = obj.__dict__["context"]
            self.__key_name__ = (obj.__dict__["schema"].__identifier__ + "." +
                                 self.__name__)
        else:
            anno_context = obj
            self.__key_name__ = self.__name__

        subobj = NumPyArrayValue("numpy." + self.__key_name__)
        await subobj.set(anno_context, value)

        setattr(anno_context, self.__key_name__, subobj)
        anno_context.register()
コード例 #7
0
ファイル: annotation.py プロジェクト: sunfirescm/guillotina
    async def set(self, obj, value):
        obj._p_register()
        if IContentBehavior.providedBy(obj):
            anno_context = obj.__dict__['context']
            self.__key_name__ = obj.__dict__[
                'schema'].__identifier__ + '.' + self.__name__
        else:
            anno_context = obj
            self.__key_name__ = self.__name__

        operation_name = value['op']
        bound_field = self.bind(obj)
        operation = query_adapter(bound_field,
                                  IPatchFieldOperation,
                                  name=operation_name)
        await operation(obj, anno_context, value['value'])
コード例 #8
0
ファイル: annotation.py プロジェクト: Inqbus/guillotina
    async def set(self, obj, value):
        try:
            obj.register()
            if IContentBehavior.providedBy(obj):
                anno_context = obj.__dict__["context"]
                self.__key_name__ = obj.__dict__[
                    "schema"].__identifier__ + "." + self.__name__
            else:
                anno_context = obj
                self.__key_name__ = self.__name__

            operation_name = value["op"]
            bound_field = self.bind(obj)
            operation = query_adapter(bound_field,
                                      IPatchFieldOperation,
                                      name=operation_name)
            await operation(obj, anno_context, value["value"])
        except Exception:
            logger.warning("Unhandled error setting value", exc_info=True)
            raise ValueDeserializationError(self, value, "Unhandled error")
コード例 #9
0
async def deserialize_cloud_field(field, value, context):
    # It supports base64 web value or a dict
    data_context = context
    if IContentBehavior.implementedBy(context.__class__):
        field = field.bind(context)
        context = context.context
    else:
        field = field.bind(context)

    if isinstance(value, dict):
        try:
            file_ob = field.get(data_context)
        except AttributeError:
            file_ob = None
        if file_ob is not None:
            # update file fields
            for key, item_value in value.items():
                if key in serialize_mappings:
                    setattr(file_ob, serialize_mappings[key], item_value)
            data_context.register()
        if "data" in value:
            value["data"] = base64.b64decode(value["data"])
        else:
            # already updated necessary values
            return file_ob
    else:
        # base64 web value
        value = convert_base64_to_binary(value)

    # There is not file and expecting a dict
    # 'data', 'encoding', 'content-type', 'filename'
    request = get_current_request()
    file_manager = get_multi_adapter((context, request, field), IFileManager)
    content_type = value.get("content_type", value.get("content-type"))
    filename = value.get("filename", None)
    val = await file_manager.save_file(partial(_generator, value),
                                       content_type=content_type,
                                       size=len(value["data"]),
                                       filename=filename)
    return val
コード例 #10
0
ファイル: field.py プロジェクト: nazrulworld/guillotina
async def deserialize_cloud_field(field, value, context):
    # It supports base64 web value or a dict
    data_context = context
    if IContentBehavior.implementedBy(context.__class__):
        field = field.bind(context)
        context = context.context
    else:
        field = field.bind(context)

    if isinstance(value, dict):
        try:
            file_ob = field.get(data_context)
        except AttributeError:
            file_ob = None
        if file_ob is not None:
            # update file fields
            for key, item_value in value.items():
                if key in serialize_mappings:
                    setattr(file_ob, serialize_mappings[key], item_value)
            data_context._p_register()
        if 'data' in value:
            value['data'] = base64.b64decode(value['data'])
        else:
            # already updated necessary values
            return file_ob
    else:
        # base64 web value
        value = convert_base64_to_binary(value)

    # There is not file and expecting a dict
    # 'data', 'encoding', 'content-type', 'filename'
    request = get_current_request()
    file_manager = get_multi_adapter((context, request, field), IFileManager)
    content_type = value.get('content_type', value.get('content-type'))
    filename = value.get('filename', None)
    val = await file_manager.save_file(
        partial(_generator, value), content_type=content_type,
        size=len(value['data']), filename=filename)
    return val