<s> """<STR_LIT>""" <EOL> from rest_framework . serializers import ( <EOL> ModelSerializer , ReadOnlyField , SerializerMethodField <EOL> ) <EOL> from geokey . core . serializers import FieldSelectorSerializer <EOL> from . models import ( <EOL> Category , Field , TextField , NumericField , LookupField , LookupValue , <EOL> MultipleLookupField , MultipleLookupValue <EOL> ) <EOL> class FieldSerializer ( ModelSerializer ) : <EOL> """<STR_LIT>""" <EOL> fieldtype = ReadOnlyField ( ) <EOL> class Meta : <EOL> model = Field <EOL> depth = <NUM_LIT:1> <EOL> fields = ( <EOL> '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:status>' , <EOL> '<STR_LIT>' , '<STR_LIT:status>' <EOL> ) <EOL> read_only_fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' ) <EOL> class TextFieldSerializer ( ModelSerializer ) : <EOL> """<STR_LIT>""" <EOL> fieldtype = ReadOnlyField ( ) <EOL> class Meta : <EOL> model = TextField <EOL> depth = <NUM_LIT:1> <EOL> fields = ( <EOL> '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:status>' , <EOL> '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> read_only_fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' ) <EOL> class NumericFieldSerializer ( ModelSerializer ) : <EOL> """<STR_LIT>""" <EOL> fieldtype = ReadOnlyField ( ) <EOL> class Meta : <EOL> model = NumericField <EOL> depth = <NUM_LIT:1> <EOL> fields = ( <EOL> '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:status>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> read_only_fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' ) <EOL> class LookupValueSerializer ( ModelSerializer ) : <EOL> """<STR_LIT>""" <EOL> class Meta : <EOL> model = LookupValue <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> class MultipleLookupValueSerializer ( ModelSerializer ) : <EOL> """<STR_LIT>""" <EOL> class Meta : <EOL> model = MultipleLookupValue <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> class BaseLookupSerializer ( object ) : <EOL> """<STR_LIT>""" <EOL> def get_lookupvalues ( self , field ) : <EOL> """<STR_LIT>""" <EOL> values = field . lookupvalues . filter ( status = '<STR_LIT>' ) <EOL> if isinstance ( field , LookupField ) : <EOL> serializer = LookupValueSerializer ( values , many = True ) <EOL> elif isinstance ( field , MultipleLookupField ) : <EOL> serializer = MultipleLookupValueSerializer ( values , many = True ) <EOL> return serializer . data <EOL> class LookupFieldSerializer ( ModelSerializer , BaseLookupSerializer ) : <EOL> """<STR_LIT>""" <EOL> lookupvalues = SerializerMethodField ( ) <EOL> fieldtype = ReadOnlyField ( ) <EOL> class Meta : <EOL> model = LookupField <EOL> depth = <NUM_LIT:1> <EOL> fields = ( <EOL> '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:status>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> read_only_fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' ) <EOL> write_only_fields = ( '<STR_LIT:status>' , ) <EOL> class MultipleLookupFieldSerializer ( ModelSerializer , BaseLookupSerializer ) : <EOL> """<STR_LIT>""" <EOL> lookupvalues = SerializerMethodField ( ) <EOL> fieldtype = ReadOnlyField ( ) <EOL> class Meta : <EOL> model = LookupField <EOL> depth = <NUM_LIT:1> <EOL> fields = ( <EOL> '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:status>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> read_only_fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:key>' ) <EOL> write_only_fields = ( '<STR_LIT:status>' , ) <EOL> class CategorySerializer ( FieldSelectorSerializer ) : <EOL> """<STR_LIT>""" <EOL> fields = SerializerMethodField ( '<STR_LIT>' ) <EOL> class Meta : <EOL> model = Category <EOL> depth = <NUM_LIT:1> <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT:description>' , '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> read_only_fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> def get_fields_serialized ( self , category ) : <EOL> """<STR_LIT>""" <EOL> fields = [ ] <EOL> for field in category . fields . filter ( status = '<STR_LIT>' ) : <EOL> if isinstance ( field , TextField ) : <EOL> serializer = TextFieldSerializer ( field ) <EOL> elif isinstance ( field , NumericField ) : <EOL> serializer = NumericFieldSerializer ( field ) <EOL> elif isinstance ( field , LookupField ) : <EOL> serializer = LookupFieldSerializer ( field ) <EOL> elif isinstance ( field , MultipleLookupField ) : <EOL> serializer = MultipleLookupFieldSerializer ( field ) <EOL> else : <EOL> serializer = FieldSerializer ( field ) <EOL> fields . append ( serializer . data ) <EOL> return fields </s>
