(CCing google-appengine).

Here's another usecase for custom message field:


from google.appengine.datastore.datastore_query import Cursor

class CursorMessage(messages.Message):
  encoded = messages.StringField(1)

class CursorField(messages.MessageField):
  message_type = CursorMessage

  def value_from_message(self, message):
    """Converts CursorMessage to a datastore_query.Cursor."""
    return Cursor(urlsafe=message.encoded)

  def message_from_value(self, value):
    """Converts datastore_query.Cursor to a CursorMessage."""
    return CursorMessage(encoded=value.urlsafe())


What do you guys think, makes sense?

Thanks,
Alex.


On Tuesday, 16 July 2013 19:04:24 UTC+2, Danny Hermes wrote:
>
> Why do you need this for Cloud Endpoints? Can you post this on Stack 
> Overflow?
>
>
> On Tue, Jul 16, 2013 at 3:38 AM, tevin joseph 
> <tevinj...@gmail.com<javascript:>
> > wrote:
>
>> Hi,
>>
>> I would like to create a user defined MessageField like DateTimeField. I 
>> have created one as follows:
>>
>>  class ErrorMessage(Message):
>>     code = StringField(1, required=True)
>>     message = StringField(2, required=True)
>>     reference = StringField(3, required=True)
>>
>> class ErrorField(MessageField):
>>     message_type = ErrorMessage
>>
>>     @util.positional(3)
>>     def __init__(self, number, **kwargs):
>>         super(ErrorField, self).__init__(self.message_type, number, 
>> **kwargs)
>>
>> Is it sound right? I have used this ErrorField  as one of the field in 
>> response class of Google cloud endpoints. It works well with JS client but 
>> when used with android, error object  gets in the format error="".  
>> Thanks in advance.
>>
>>          return  MyResponse(
>>             isSaved=False,
>>             error=ErrorMessage(code="200", 
>> message=simplejson.dumps(form.errors), 
>> reference="form validation error")
>>            )
>>
>>          from protorpc.messages import Message, StringField, MessageField
>>
>>          class MyResponse(Message):
>>             isSaved = StringField(1, required=True)
>>             error = ErrorField(2, required = False)
>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "ProtoRPC Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-protorpc-discuss+unsubscr...@googlegroups.com<javascript:>
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Danny Hermes
> Developer Programs Engineer 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to