Пример #1
0
def get_series(request, token_id):
    try:
        token = CollectorToken.objects.get(pk=token_id)
        resp = []

        serie = {
            'name': token.name,
            'data': [],
            'type': "area",
        }

        for r in token.records.all().order_by("-date_added"):
            serie['data'].append(
                [
                    {
                        'year': r.date_added.year,
                        'month': r.date_added.month,
                        'day': r.date_added.day,
                        'hours': r.date_added.hour,
                        'minutes': r.date_added.minute,
                        'seconds': r.date_added.second,
                        'ms': r.date_added.microsecond,
                    },
                    r.data
                ]
            )

        resp.append(serie)
        return jsonResp(resp)

    except CollectorToken.DoesNotExist:
        raise PermissionDenied
Пример #2
0
def add_record(request):
    if request.method != "POST":
        raise NotImplementedError

    token = request.POST.get("token", None)
    data = request.POST.get("data", None)

    if not token:
        raise PermissionDenied

    if not data:
        raise PermissionDenied

    try:
        data = float(data)
    except ValueError:
        raise PermissionDenied

    try:
        token = CollectorToken.objects.get(token=token)
        r = Record(
            data=data,
            token=token,
        )
        r.save()
        return jsonResp(r.to_dict())
    except CollectorToken.DoesNotExist:
        raise PermissionDenied