mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
5 years ago
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
# coding: utf-8
|
||
|
|
||
|
from django.utils import timezone
|
||
|
|
||
|
|
||
|
__all__ = ["DatetimeSearchMixin"]
|
||
|
|
||
|
|
||
|
class DatetimeSearchMixin:
|
||
|
date_format = '%Y-%m-%d'
|
||
|
date_from = date_to = None
|
||
|
|
||
|
def get_date_range(self):
|
||
|
date_from_s = self.request.GET.get('date_from')
|
||
|
date_to_s = self.request.GET.get('date_to')
|
||
|
|
||
|
if date_from_s:
|
||
|
date_from = timezone.datetime.strptime(date_from_s, self.date_format)
|
||
|
tz = timezone.get_current_timezone()
|
||
|
self.date_from = tz.localize(date_from)
|
||
|
else:
|
||
|
self.date_from = timezone.now() - timezone.timedelta(7)
|
||
|
|
||
|
if date_to_s:
|
||
|
date_to = timezone.datetime.strptime(
|
||
|
date_to_s + ' 23:59:59', self.date_format + ' %H:%M:%S'
|
||
|
)
|
||
|
self.date_to = date_to.replace(
|
||
|
tzinfo=timezone.get_current_timezone()
|
||
|
)
|
||
|
else:
|
||
|
self.date_to = timezone.now()
|
||
|
|
||
|
def get(self, request, *args, **kwargs):
|
||
|
self.get_date_range()
|
||
|
return super().get(request, *args, **kwargs)
|