<s> from dimagi . ext . couchdbkit import ( <EOL> BooleanProperty , <EOL> DateProperty , <EOL> DateTimeProperty , <EOL> DecimalProperty , <EOL> DictProperty , <EOL> FloatProperty , <EOL> IntegerProperty , <EOL> SchemaDictProperty , <EOL> SchemaListProperty , <EOL> SchemaProperty , <EOL> StringListProperty , <EOL> StringProperty , <EOL> ) <EOL> from corehq . pillows . core import DATE_FORMATS_ARR , DATE_FORMATS_STRING <EOL> def type_full_date ( formats = DATE_FORMATS_STRING ) : <EOL> return dict ( type = "<STR_LIT:date>" , format = formats ) <EOL> def prop_subtype ( prop_type , nested = False , dynamic = False , sub_types = None ) : <EOL> sub_types = sub_types or default_special_types <EOL> return { <EOL> '<STR_LIT:type>' : '<STR_LIT>' if nested else '<STR_LIT:object>' , <EOL> '<STR_LIT>' : dynamic , <EOL> '<STR_LIT>' : set_properties ( prop_type , custom_types = sub_types ) <EOL> } <EOL> simple_type_mapper = { <EOL> StringProperty : dict ( type = "<STR_LIT:string>" ) , <EOL> BooleanProperty : dict ( type = "<STR_LIT>" ) , <EOL> IntegerProperty : dict ( type = "<STR_LIT>" ) , <EOL> FloatProperty : dict ( type = "<STR_LIT:float>" ) , <EOL> DecimalProperty : dict ( type = "<STR_LIT>" ) , <EOL> StringListProperty : dict ( type = "<STR_LIT:string>" ) , <EOL> DateTimeProperty : type_full_date ( ) , <EOL> DateProperty : type_full_date ( ) , <EOL> DictProperty : { "<STR_LIT:type>" : "<STR_LIT:object>" , "<STR_LIT>" : False } , <EOL> } <EOL> complex_type_mapper = { <EOL> SchemaListProperty : prop_subtype , <EOL> SchemaDictProperty : prop_subtype , <EOL> SchemaProperty : prop_subtype , <EOL> } <EOL> everything_is_dict_template = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT:*>" , <EOL> "<STR_LIT>" : "<STR_LIT:string>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT:index>" : "<STR_LIT>" } , <EOL> } <EOL> } <EOL> } <EOL> def type_exact_match_string ( prop_name , dual = True ) : <EOL> """<STR_LIT>""" <EOL> if dual : <EOL> return { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> prop_name : { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT:index>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT:index>" : "<STR_LIT>" } <EOL> } <EOL> } <EOL> else : <EOL> return dict ( type = "<STR_LIT:string>" ) <EOL> default_special_types = { <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> } <EOL> default_nested_types = [ ] <EOL> case_special_types = { <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT:name>" : type_exact_match_string ( "<STR_LIT:name>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT:index>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT:index>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : False , "<STR_LIT:type>" : "<STR_LIT:object>" } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : False , "<STR_LIT:type>" : "<STR_LIT:object>" } , <EOL> "<STR_LIT:type>" : type_exact_match_string ( "<STR_LIT:type>" , dual = True ) , <EOL> } <EOL> case_nested_types = [ '<STR_LIT>' , ] <EOL> domain_special_types = { <EOL> "<STR_LIT:name>" : type_exact_match_string ( "<STR_LIT:name>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT:title>" : type_exact_match_string ( "<STR_LIT:title>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT:description>" : type_exact_match_string ( "<STR_LIT:description>" , dual = True ) , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> "<STR_LIT>" : type_exact_match_string ( "<STR_LIT>" , dual = True ) , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT:index>" : "<STR_LIT>" } , <EOL> } <EOL> } <EOL> } <EOL> app_special_types = { <EOL> "<STR_LIT:name>" : type_exact_match_string ( "<STR_LIT:name>" , dual = True ) , <EOL> "<STR_LIT>" : { "<STR_LIT:type>" : "<STR_LIT:object>" , "<STR_LIT>" : True } , <EOL> } <EOL> def set_properties ( schema_class , dynamic = False , custom_types = default_special_types , nested_types = default_nested_types , init_dict = None ) : <EOL> """<STR_LIT>""" <EOL> props_dict = init_dict or { } <EOL> for prop_name , prop_type in schema_class . properties ( ) . items ( ) : <EOL> if custom_types . has_key ( prop_name ) : <EOL> props_dict [ prop_name ] = custom_types [ prop_name ] <EOL> elif simple_type_mapper . has_key ( prop_type . __class__ ) : <EOL> props_dict [ prop_name ] = simple_type_mapper [ prop_type . __class__ ] <EOL> elif complex_type_mapper . has_key ( prop_type . __class__ ) : <EOL> func = complex_type_mapper [ prop_type . __class__ ] <EOL> sub_types = custom_types . get ( "<STR_LIT>" , { } ) . get ( prop_name ) <EOL> props_dict [ prop_name ] = func ( prop_type . _schema , nested = prop_name in nested_types , dynamic = dynamic , sub_types = sub_types ) <EOL> if not props_dict . get ( '<STR_LIT>' ) : <EOL> props_dict [ "<STR_LIT>" ] = { "<STR_LIT:type>" : "<STR_LIT:string>" , "<STR_LIT:index>" : "<STR_LIT>" } <EOL> return props_dict <EOL> DEFAULT_MAPPING_WRAPPER = { <EOL> "<STR_LIT>" : False , <EOL> '<STR_LIT>' : False , <EOL> "<STR_LIT>" : DATE_FORMATS_ARR , <EOL> "<STR_LIT>" : { "<STR_LIT>" : None } , <EOL> "<STR_LIT>" : { } <EOL> } </s>
