def is_enabled(field, schema): """Return true if field is enabled using given schema. :param field: field name :param schema: schema dict """ return schema.get(field) or schema.get(field) == {} or field not in DEFAULT_SCHEMA
def set_default_for_custom(schema, default_values, fields_map): for old_field, field in fields_map.items(): if (field == old_field or old_field == 'subject') and schema.get(field, None) is not None: default = [] for value in default_values: if value.get('scheme', None) == field: default.append(value) schema[field]['default'] = default
def init_default(doc): editor = doc['editor'] = doc.get('editor', None) schema = doc['schema'] = doc.get('schema', None) if editor and schema: for field in DEFAULT_EDITOR: # add missing fields in editor with enabled = false if editor.get(field, None) is None: editor[field] = deepcopy(DEFAULT_EDITOR[field]) editor[field]['enabled'] = False if schema.get(field, None) is None: schema[field] = deepcopy(DEFAULT_SCHEMA[field]) else: editor[field]['enabled'] = True else: doc['editor'] = deepcopy(DEFAULT_EDITOR) doc['schema'] = deepcopy(DEFAULT_SCHEMA)
def compose_subject_schema(schema, fields_map): mandatory = {} allowed = [] default = [] for old_field, field in fields_map.items(): if (old_field == field or old_field == 'subject') and schema.get(field, None): allowed.append(field) if schema[field].get('required', False): mandatory[old_field] = field else: mandatory[old_field] = None if schema[field].get('default', None): default.extend(schema[field]['default']) else: mandatory[old_field] = None if allowed: init_subject_schema(schema, default, mandatory, allowed, fields_map)
def init_schema_for_custom_fields(schema, fields_map): for field in fields_map.values(): if schema.get(field, None) and schema[field].get('default', None): list_values = schema[field]['default'] for value in list_values: value['scheme'] = field