示例#1
0
 def get(self, request, *args, **kwargs):
     hub = AuthServiceApi.get_hub(self.kwargs.get('hub'))
     self.hub = hub
     token = self.request.COOKIES.get('user_token')
     self.device = InternalApi.get_device(token, self.hub,
                                          self.kwargs.get('device'))
     self.unit = InternalApi.get_unit(token, hub, self.kwargs.get('device'),
                                      self.kwargs.get('pk'))
     self.data = InternalApi.get_data_from_unit(token, hub,
                                                self.kwargs.get('device'),
                                                self.kwargs.get('pk'))
     self.has_write_perms = AuthServiceApi.has_write_permission(
         hub['pk'], self.kwargs.get('device'), self.user['pk'])
     return super(UnitDataView, self).get(request, *args, **kwargs)
示例#2
0
 def post(self, request, *args, **kwargs):
     self.hub = AuthServiceApi.get_hub(self.kwargs.get('hub'))
     self.token = self.request.COOKIES.get('user_token')
     self.device = InternalApi.get_device(self.token, self.hub,
                                          self.kwargs.get('device'))
     self.unit = InternalApi.get_unit(self.token, self.hub,
                                      self.kwargs.get('device'),
                                      self.kwargs.get('pk'))
     self.data = InternalApi.get_data_from_unit(self.token, self.hub,
                                                self.kwargs.get('device'),
                                                self.kwargs.get('pk'))
     self.has_write_perms = AuthServiceApi.has_write_permission(
         self.hub['pk'], self.kwargs.get('device'), self.user['pk'])
     if not self.has_write_perms['has_write_perm']:
         return HttpResponseRedirect(self.get_success_url())
     return super(UnitDataView, self).post(request, *args, **kwargs)