blob: dffc347790e4bd21af6e3105accba2e7ac5d3d5a [file] [log] [blame]
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +02001import base64
2import time
Scott Bakerb96ba432018-02-26 09:53:48 -08003from protos import xos_pb2, xos_pb2_grpc
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +02004from google.protobuf.empty_pb2 import Empty
5
6from django.contrib.auth import authenticate as django_authenticate
7from xos.exceptions import *
8from apihelper import XOSAPIHelperMixin, translate_exceptions
9
Scott Bakerb96ba432018-02-26 09:53:48 -080010class XosService(xos_pb2_grpc.xosServicer, XOSAPIHelperMixin):
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020011 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 }}")
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040024 return self.list(model, user)
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020025
26 @translate_exceptions
27 def Filter{{ object.name }}(self, request, context):
28 user=self.authenticate(context)
29 model=self.get_model("{{ object.name }}")
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040030 return self.filter(model, user, request)
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020031
32 @translate_exceptions
33 def Get{{ object.name }}(self, request, context):
34 user=self.authenticate(context)
35 model=self.get_model("{{ object.name }}")
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040036 return self.get(model, user, request.id)
Sapan Bhatiacb35e7f2017-05-24 12:17:28 +020037
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