Sapan Bhatia | cb35e7f | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 1 | import base64 |
| 2 | import time |
| 3 | from protos import xos_pb2 |
| 4 | from google.protobuf.empty_pb2 import Empty |
| 5 | |
| 6 | from django.contrib.auth import authenticate as django_authenticate |
| 7 | from xos.exceptions import * |
| 8 | from apihelper import XOSAPIHelperMixin, translate_exceptions |
| 9 | |
| 10 | class XosService(xos_pb2.xosServicer, XOSAPIHelperMixin): |
| 11 | def __init__(self, thread_pool): |
| 12 | self.thread_pool = thread_pool |
| 13 | XOSAPIHelperMixin.__init__(self) |
| 14 | |
| 15 | def stop(self): |
| 16 | pass |
| 17 | |
| 18 | {% for object in proto.messages | sort(attribute='name') %} |
| 19 | {%- if object.name!='XOSBase' %} |
| 20 | @translate_exceptions |
| 21 | def List{{ object.name }}(self, request, context): |
| 22 | user=self.authenticate(context) |
| 23 | model=self.get_model("{{ object.name }}") |
| 24 | return self.querysetToProto(model, model.objects.all()) |
| 25 | |
| 26 | @translate_exceptions |
| 27 | def Filter{{ object.name }}(self, request, context): |
| 28 | user=self.authenticate(context) |
| 29 | model=self.get_model("{{ object.name }}") |
| 30 | return self.filter(model, request) |
| 31 | |
| 32 | @translate_exceptions |
| 33 | def Get{{ object.name }}(self, request, context): |
| 34 | user=self.authenticate(context) |
| 35 | model=self.get_model("{{ object.name }}") |
| 36 | return self.get(model, request.id) |
| 37 | |
| 38 | @translate_exceptions |
| 39 | def Create{{ object.name }}(self, request, context): |
| 40 | user=self.authenticate(context) |
| 41 | model=self.get_model("{{ object.name }}") |
| 42 | return self.create(model, user, request) |
| 43 | |
| 44 | @translate_exceptions |
| 45 | def Delete{{ object.name }}(self, request, context): |
| 46 | user=self.authenticate(context) |
| 47 | model=self.get_model("{{ object.name }}") |
| 48 | return self.delete(model, user, request.id) |
| 49 | |
| 50 | @translate_exceptions |
| 51 | def Update{{ object.name }}(self, request, context): |
| 52 | user=self.authenticate(context) |
| 53 | model=self.get_model("{{ object.name }}") |
| 54 | return self.update(model, user, request.id, request, context) |
| 55 | {%- endif %} |
| 56 | {% endfor %} |
| 57 | |
| 58 | |