<s> from __future__ import absolute_import , print_function <EOL> from rest_framework import serializers <EOL> from sentry . models import User <EOL> from sentry . utils . auth import find_users <EOL> class UserField ( serializers . WritableField ) : <EOL> def to_native ( self , obj ) : <EOL> return obj . username <EOL> def from_native ( self , data ) : <EOL> if not data : <EOL> return None <EOL> if isinstance ( data , ( int , long ) ) or data . isdigit ( ) : <EOL> try : <EOL> return User . objects . get ( id = data ) <EOL> except User . DoesNotExist : <EOL> pass <EOL> try : <EOL> return find_users ( data ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> raise serializers . ValidationError ( '<STR_LIT>' ) </s>
