[grpc-io] Re: How can we send a Django User object and a list of users?

2017-06-10 Thread jome . akpoduado
Hi. Please could you tell me how you got the grpc server to run with the 
django process?

On Friday, 17 March 2017 18:08:22 UTC+2, Rajeev R wrote:
>
> Hello All,
>
> I have two django applications and I want to send a user object from one 
> django application to other django application through gRPC. I have seen 
> string and integer types working fine. Please find the code attached.
>
>
>
> service Usermanagement {
>   rpc UserLogin (UserRequest) returns (UserResponse) {}
> }
>
> // The request message containing the user's name.
> message UserRequest {
>   string username = 1;
>   string password = 2;
> }
>
> // The response message containing the greetings
> message UserResponse {
>   string message = 1;
>   string fullname = 2;
>   string token = 4;
>   int32 status = 5;
> }
>
> This is my Django application code.
>
> import grpc
>
> from userservice import userservices_pb2
> from userservice import userservices_pb2_grpc
> from usermanagement.models import AppUser as User
> from django.contrib.auth import authenticate
> from rest_framework.authtoken.models import Token
> from google.protobuf import any_pb2
>
> class Usermanagement(userservices_pb2_grpc.UsermanagementServicer):
>
> def UserLogin(self, request, context):
> User = authenticate(username=request.username, password=request.
> password)
> if User is not None:
> (token, created) = Token.objects.get_or_create(user=User)
> User.authentication_token = token.key
> return userservices_pb2.UserResponse(message='success', status
> =0, fullname=User.fullname, token = token.key)
> else:
> return userservices_pb2.UserResponse(message='Incorrect 
> Username/Password', status=1)
>
>
> Please anyone can help me "How can I include the User object or user list" 
> in the return response.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/be83da42-3def-443e-8247-ce67e3be4fea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[grpc-io] Re: How can we send a Django User object and a list of users?

2017-03-20 Thread Rajeev R
Actually I found the answer. 
https://developers.google.com/protocol-buffers/docs/proto3#nested

message UserResponse {
  string message = 1;
  string fullname = 2;
  string token = 4;
  int32 status = 5;
}

message UserListRequest {

}

message UserListResponse {
message Result {
string fullname = 1;
  }
  repeated Result results = 1;
}
in my django application code,

def UserList(self, request, context):
UserListRes = User.objects.all().values('fullname')
return userservices_pb2.UserListResponse(results=UserListRes)




On Friday, 17 March 2017 21:38:22 UTC+5:30, Rajeev R wrote:
>
> Hello All,
>
> I have two django applications and I want to send a user object from one 
> django application to other django application through gRPC. I have seen 
> string and integer types working fine. Please find the code attached.
>
>
>
> service Usermanagement {
>   rpc UserLogin (UserRequest) returns (UserResponse) {}
> }
>
> // The request message containing the user's name.
> message UserRequest {
>   string username = 1;
>   string password = 2;
> }
>
> // The response message containing the greetings
> message UserResponse {
>   string message = 1;
>   string fullname = 2;
>   string token = 4;
>   int32 status = 5;
> }
>
> This is my Django application code.
>
> import grpc
>
> from userservice import userservices_pb2
> from userservice import userservices_pb2_grpc
> from usermanagement.models import AppUser as User
> from django.contrib.auth import authenticate
> from rest_framework.authtoken.models import Token
> from google.protobuf import any_pb2
>
> class Usermanagement(userservices_pb2_grpc.UsermanagementServicer):
>
> def UserLogin(self, request, context):
> User = authenticate(username=request.username, password=request.
> password)
> if User is not None:
> (token, created) = Token.objects.get_or_create(user=User)
> User.authentication_token = token.key
> return userservices_pb2.UserResponse(message='success', status
> =0, fullname=User.fullname, token = token.key)
> else:
> return userservices_pb2.UserResponse(message='Incorrect 
> Username/Password', status=1)
>
>
> Please anyone can help me "How can I include the User object or user list" 
> in the return response.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/9461e5da-777e-4c19-8c58-20f701dfd174%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.