<s> from wq . db . rest . serializers import ModelSerializer <EOL> from django . conf import settings <EOL> HAS_SOCIAL_AUTH = ( '<STR_LIT>' in settings . INSTALLED_APPS ) <EOL> if HAS_SOCIAL_AUTH : <EOL> from social . apps . django_app . default . models import UserSocialAuth <EOL> class SocialAuthSerializer ( ModelSerializer ) : <EOL> def to_representation ( self , instance ) : <EOL> return { <EOL> '<STR_LIT>' : str ( instance . provider ) , <EOL> '<STR_LIT>' : instance . provider . title ( ) , <EOL> '<STR_LIT:id>' : instance . pk , <EOL> '<STR_LIT:label>' : instance . uid , <EOL> '<STR_LIT>' : type ( instance ) . allowed_to_disconnect ( <EOL> user = instance . user , <EOL> backend_name = instance . provider , <EOL> association_id = instance . pk <EOL> ) <EOL> } <EOL> class Meta : <EOL> model = UserSocialAuth <EOL> class UserSerializer ( ModelSerializer ) : <EOL> if HAS_SOCIAL_AUTH : <EOL> social_auth = SocialAuthSerializer ( many = True , read_only = True ) <EOL> def to_representation ( self , instance ) : <EOL> result = super ( UserSerializer , self ) . to_representation ( instance ) <EOL> if ( HAS_SOCIAL_AUTH and '<STR_LIT>' in result ) : <EOL> if len ( result [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> result [ '<STR_LIT>' ] = { '<STR_LIT>' : result [ '<STR_LIT>' ] } <EOL> else : <EOL> result [ '<STR_LIT>' ] = None <EOL> return result <EOL> class Meta : <EOL> exclude = ( '<STR_LIT:id>' , '<STR_LIT:password>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> readonly_fields = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_exclude = ( '<STR_LIT>' , ) </s>
