def _set_default_configuration(self): defaults = {} tile_type = getUtility(ITileType, name=self.tile.__name__) fields = getFieldNamesInOrder(tile_type.schema) for name, field in getFieldsInOrder(tile_type.schema): order = unicode(fields.index(name)) # default configuration attributes for all fields defaults[name] = {'order': order, 'visibility': u'on'} if name == 'css_class': # css_class, set default defaults[name] = field.default if ITextLine.providedBy(field): # field is TextLine, we should add 'htmltag' defaults[name]['htmltag'] = u'h2' elif INamedBlobImageField.providedBy(field): # field is an image, we should add 'position' and 'imgsize' defaults[name]['position'] = u'left' defaults[name]['imgsize'] = u'mini 200:200' elif IInt.providedBy(field): defaults[name][name] = field.default elif IDatetime.providedBy(field): # field is Datetime, we should add 'format' defaults[name]['format'] = 'datetime' return defaults
def _set_default_configuration(self): defaults = {} tile_type = getUtility(ITileType, name=self.tile.__name__) fields = getFieldNamesInOrder(tile_type.schema) for name, field in getFieldsInOrder(tile_type.schema): order = unicode(fields.index(name)) # default configuration attributes for all fields defaults[name] = {"order": order, "visibility": u"on"} if name == "css_class": # css_class, set default defaults[name] = field.default if ITextLine.providedBy(field): # field is TextLine, we should add 'htmltag' defaults[name]["htmltag"] = u"h2" elif INamedBlobImageField.providedBy(field): # field is an image, we should add 'position' and 'imgsize' defaults[name]["position"] = u"left" defaults[name]["imgsize"] = u"mini 200:200" elif IInt.providedBy(field): defaults[name][name] = field.default elif IDatetime.providedBy(field): # field is Datetime, we should add 'format' defaults[name]["format"] = "datetime" return defaults
def get_collection_schema_from_interface_schema(self, schema): collection = {} for name in schema: if IDate.providedBy(schema[name]) or \ IDatetime.providedBy(schema[name]): collection['field.'+name] = 'time' elif IDecimal.providedBy(schema[name]) or \ IFloat.providedBy(schema[name]) or \ IInt.providedBy(schema[name]): collection['field.'+name] = 'number' elif IBool.providedBy(schema[name]): collection['field.'+name] = 'bool' elif ICollection.providedBy(schema[name]): if not ICollection.providedBy(schema[name].value_type) and not \ IDict.providedBy(schema[name].value_type): collection['field.'+name] = 'array' elif IDict.providedBy(schema[name]): if IText.providedBy(schema[name].key_type) and \ IText.providedBy(schema[name].value_type): collection['field.'+name] = 'array' # this is a pretty weak check for a IP address field. We might want # to update this to look for a field validator based on the ipaddress package # or mark this field with a special interface indicating it is an # IP address elif IDottedName.providedBy(schema[name]) and \ (schema[name].min_dots == schema[name].max_dots == 3): collection['field.'+name] = 'cidr' elif IText.providedBy(schema[name]) or \ INativeString.providedBy(schema[name]): collection['field.'+name] = 'string' return collection
def theme_options(self): data = {} for name in self.schema.names(): field = self.schema[name] if not IField.providedBy(field): continue value = getattr(self.settings, name, None) if value == None: continue name = name.replace(self.theme + '_', '', 1) if IBool.providedBy(field): data[name] = jsbool(value) elif IChoice.providedBy(field) or ITextLine.providedBy(field): data[name] = '"' + value + '"' elif IInt.providedBy(field) or IFloat.providedBy(field): data[name] = str(value) return data