예제 #1
0
    def list(self, request):
        print('get groups scheme_id: ' + self.request.GET.get('id', '0') +
              ' user_id: ' + str(request.user.id))
        scheme = get_scheme(self.request)
        print('2 get groups scheme_id: ' + self.request.GET.get('id', '0') +
              ' user_id: ' + str(request.user.id))
        values = scheme.groups.values_list(
            'scheme_group_user__user_id', 'scheme_group_user__user__username',
            'scheme_group_user__user__first_name',
            'scheme_group_user__user__last_name')
        result = []
        for id, login, fname, lname in values:
            if id:
                name = ''
                if fname:
                    name = fname
                if lname:
                    if name:
                        name += ' '
                    name += lname
                if not name:
                    name = login
                result.append({'id': id, 'name': name})

        return Response({'count': len(result), 'results': result})
예제 #2
0
    def put(self, req, format=None):
        scheme = get_scheme(req)

        user_id = str(req.user.id)
        project_id = req.GET.get('id')
        devitem_id = req.GET.get('item_id')
        input_file = req.FILES['fileKey']
        file_name = input_file.name
        #        file_path = '/var/tmp/dai_item_file_' + str(time.time())
        file_path = '/opt/firmware/dai_item_file_' + str(time.time())
        file_path += '.dat'
        with open(file_path, 'wb+') as destination:
            for chunk in input_file.chunks():
                destination.write(chunk)

        import dbus
        obj = dbus.SystemBus().get_object('ru.deviceaccess.Dai.Server', '/')
        obj.write_item_file(project_id,
                            user_id,
                            devitem_id,
                            file_name,
                            file_path,
                            dbus_interface='ru.deviceaccess.Dai.iface')

        #print(subprocess.run(['/usr/bin/sudo', '/bin/sh', '-c', '/opt/test.sh'], capture_output=True))
        #args = ['/usr/bin/sudo', settings.DAI_SERVER_PATH, '-l', '--user_id', user_id, '--project_id', project_id, '--devitem_id', devitem_id, '--send_file', file_path, '--send_file_name', file_name]
        #ret = subprocess.run(args, capture_output=True)
        #if ret.returncode != 0:
        #    print(ret)
        #    print('Failed upload device item file')
        return Response(status=204)
예제 #3
0
    def get_queryset(self):
        data = self.request.GET['data']
        items = self.get_id_list(data)

        scheme = get_scheme(self.request)
        q_scheme = Q(scheme_id=scheme.id)

        ts_from = self.request.GET['ts_from']
        ts_to = self.request.GET['ts_to']
        q_time = Q(timestamp_msecs__range=[ts_from, ts_to])
        return self.get_typed_queryset(q_scheme, q_time, items)
예제 #4
0
    def get_queryset(self):
        scheme = get_scheme(self.request)

        try:
            ts_from = int(self.request.GET.get('ts_from'))
            ts_to = int(self.request.GET.get('ts_to'))
            if pk_from != 0 and pk_to != 0:
                in_range = Q(timestamp_msecs__range=[ts_from, ts_to])
                one_scheme = Q(scheme_id=scheme.id)
                return models.Log_Value.objects.filter(in_range & one_scheme)
        except:
            pass

        return models.Log_Value.objects.filter(scheme_id=scheme.id)
예제 #5
0
 def get_queryset(self):
     scheme = get_scheme(self.request)
     scheme_id = scheme.parent_id if scheme.parent_id else scheme.id
     return models.Save_Timer.objects.filter(scheme_id=scheme_id)
예제 #6
0
 def get_queryset(self):
     scheme = get_scheme(self.request)
     scheme_id = scheme.parent_id if scheme.parent_id else scheme.id
     return models.Plugin_Type.objects.filter(scheme_id=scheme_id)
예제 #7
0
def device_items(req):
    scheme = get_scheme(req)
    scheme_id = scheme.parent_id if scheme.parent_id else scheme.id
    return models.DeviceItem.objects.filter(scheme_id=scheme_id)
예제 #8
0
def devitem_types(request):
    scheme = get_scheme(request)
    scheme_id = scheme.parent_id if scheme.parent_id else scheme.id
    return models.ItemType.objects.filter(scheme_id=scheme_id)