<s> import endpoints <EOL> from google . appengine . ext import ndb <EOL> from protorpc import messages <EOL> from protorpc import remote <EOL> from endpoints_proto_datastore . ndb import EndpointsAliasProperty <EOL> from endpoints_proto_datastore . ndb import EndpointsModel <EOL> class Order ( messages . Enum ) : <EOL> MYFIRST = <NUM_LIT:1> <EOL> MYSECOND = <NUM_LIT:2> <EOL> class MyModel ( EndpointsModel ) : <EOL> _message_fields_schema = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> attr1 = ndb . StringProperty ( required = True ) <EOL> attr2 = ndb . StringProperty ( required = True ) <EOL> created = ndb . DateTimeProperty ( auto_now_add = True ) <EOL> owner = ndb . UserProperty ( required = True ) <EOL> def OrderSet ( self , value ) : <EOL> if not isinstance ( value , Order ) : <EOL> raise TypeError ( '<STR_LIT>' % ( value , ) ) <EOL> if value == Order . MYFIRST : <EOL> super ( MyModel , self ) . OrderSet ( '<STR_LIT>' ) <EOL> elif value == Order . MYSECOND : <EOL> super ( MyModel , self ) . OrderSet ( '<STR_LIT>' ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' % ( value , ) ) <EOL> @ EndpointsAliasProperty ( setter = OrderSet , property_type = Order , <EOL> default = Order . MYFIRST ) <EOL> def order ( self ) : <EOL> return super ( MyModel , self ) . order <EOL> @ endpoints . api ( name = '<STR_LIT>' , version = '<STR_LIT>' , description = '<STR_LIT>' ) <EOL> class MyApi ( remote . Service ) : <EOL> @ MyModel . method ( request_fields = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> user_required = True , <EOL> path = '<STR_LIT>' , http_method = '<STR_LIT:POST>' , name = '<STR_LIT>' ) <EOL> def MyModelInsert ( self , my_model ) : <EOL> my_model . owner = endpoints . get_current_user ( ) <EOL> my_model . put ( ) <EOL> return my_model <EOL> @ MyModel . query_method ( query_fields = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> user_required = True , <EOL> path = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> def MyModelList ( self , query ) : <EOL> return query . filter ( MyModel . owner == endpoints . get_current_user ( ) ) <EOL> application = endpoints . api_server ( [ MyApi ] , restricted = False ) </s>
