示例#1
0
def get_alarm(request):
    now = datetime.now()
    data = {human_date(now - timedelta(days=x + 1)): 0 for x in range(14)}
    for alarm in Alarm.objects.filter(status='1', created_at__gt=human_date(now - timedelta(days=14))):
        date = alarm.created_at[:10]
        if date in data:
            data[date] += 1
    data = [{'date': k, 'value': v} for k, v in data.items()]
    return json_response(data)
示例#2
0
def get_alarm(request):
    form, error = JsonParser(
        Argument('type', required=False),
        Argument('name', required=False)
    ).parse(request.GET, True)
    if error is None:
        now = datetime.now()
        data = {human_date(now - timedelta(days=x + 1)): 0 for x in range(14)}
        for alarm in Alarm.objects.filter(status='1', created_at__gt=human_date(now - timedelta(days=14)), **form):
            date = alarm.created_at[:10]
            if date in data:
                data[date] += 1
        data = [{'date': k, 'value': v} for k, v in data.items()]
        return json_response(data)
    return json_response(error=error)
示例#3
0
文件: views.py 项目: yinzhengjie/spug
def get_request(request):
    data = {x.id: {'name': x.name, 'count': 0} for x in App.objects.all()}
    for req in DeployRequest.objects.filter(created_at__gt=human_date()):
        data[req.deploy.app_id]['count'] += 1
    data = sorted(data.values(), key=lambda x: x['count'], reverse=True)[:5]
    return json_response(data)