class IModelFieldSchema(Interface): """Model field schema""" type_model = schema.ASCII(title="Type of model", default="tf") file = CloudFileField(title="Model binary file") version = schema.Int(title="Version of the model", default=1)
async def prepare(self): # we want have the field name = self.request.matchdict["field_name"] fti = query_utility(IFactory, name=self.context.type_name) schema = fti.schema field = None self.behavior = None if name in schema: field = schema[name] else: # TODO : We need to optimize and move to content.py iterSchema for behavior_schema in fti.behaviors or (): if name in behavior_schema: field = behavior_schema[name] self.behavior = behavior_schema(self.context) break for behavior_name in self.context.__behaviors__ or (): behavior_schema = BEHAVIOR_CACHE[behavior_name] if name in behavior_schema: field = behavior_schema[name] self.behavior = behavior_schema(self.context) break # Check that its a File Field if field is None: raise HTTPNotFound(content={"reason": "No valid name"}) if self.behavior is not None: ctx = self.behavior else: ctx = self.context if self.behavior is not None and IAsyncBehavior.implementedBy( self.behavior.__class__): # providedBy not working here? await self.behavior.load() if IDict.providedBy(field) and ICloudFileField.providedBy( field.value_type): key = self.request.matchdict.get("file_key") if key is not None: self.field = CloudFileField(__name__=name).bind( DictFieldProxy(key, ctx, name)) elif ICloudFileField.providedBy(field): self.field = field.bind(ctx) if self.field is None: raise HTTPNotFound(content={"reason": "No valid name"}) return self
class IFile(IItem): fieldset_field("file", "default") file = CloudFileField(title="File", required=False, widget="file")
class IFileContent(IItem): file = CloudFileField(required=False)
class IMultiAttachment(Interface): files = Dict( key_type=TextLine(), value_type=CloudFileField(), missing_value={} )
class IAttachment(Interface): file = CloudFileField()
class IImageAttachment(Interface): image = CloudFileField() caption = schema.TextLine()
class ILeadImage(Interface): lead = CloudFileField()
class IMultiAttachment(Interface): files = Dict(key_type=TextLine(), value_type=CloudFileField(), default={}, missing_value={}, max_length=1000)
class IFile(IItem): fieldset_field('file', 'default') file = CloudFileField(title='File', required=False, widget='file')