From 431ba36a26871c56a0d18ba072018754112fe97b Mon Sep 17 00:00:00 2001 From: xinwen Date: Wed, 3 Jun 2020 15:05:55 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=E4=BC=9A=E8=AF=9D=E7=AE=A1=E7=90=86/?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=AE=B0=E5=BD=95=20=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=20bug=20(#4070)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/command.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/terminal/api/command.py b/apps/terminal/api/command.py index eb0955648..12141bef1 100644 --- a/apps/terminal/api/command.py +++ b/apps/terminal/api/command.py @@ -5,6 +5,7 @@ from django.utils import timezone from django.shortcuts import HttpResponse from rest_framework import viewsets from rest_framework import generics +from rest_framework.fields import DateTimeField from rest_framework.response import Response from django.template import loader @@ -71,12 +72,22 @@ class CommandQueryMixin: def get_date_range(self): now = timezone.now() days_ago = now - timezone.timedelta(days=self.default_days_ago) - default_start_st = days_ago.timestamp() - default_end_st = now.timestamp() + date_from_st = days_ago.timestamp() + date_to_st = now.timestamp() + query_params = self.request.query_params - date_from_st = query_params.get("date_from") or default_start_st - date_to_st = query_params.get("date_to") or default_end_st - return float(date_from_st), float(date_to_st) + date_from_q = query_params.get("date_from") + date_to_q = query_params.get("date_to") + + dt_parser = DateTimeField().to_internal_value + + if date_from_q: + date_from_st = dt_parser(date_from_q).timestamp() + + if date_to_q: + date_to_st = dt_parser(date_to_q).timestamp() + + return date_from_st, date_to_st class CommandViewSet(CommandQueryMixin, viewsets.ModelViewSet):