Commit f4fc7573 authored by jym503558564's avatar jym503558564

[Bugfix] 修改导出登录日志的日期选择从开始时间的00:00:00,到结束时间的23:59:59

parent 334e3bef
......@@ -88,11 +88,15 @@ class UserLoginLog(models.Model):
datetime = models.DateTimeField(default=timezone.now, verbose_name=_('Date login'))
@classmethod
def get_login_logs(cls, date_form=None, date_to=None, user=None, keyword=None):
def get_login_logs(cls, date_from=None, date_to=None, user=None, keyword=None, date_format=None):
login_logs = cls.objects.all()
if date_form and date_to:
if date_from and date_to:
date_from = timezone.datetime.strptime(date_from, date_format)
date_to = timezone.datetime.strptime(
date_to + ' 23:59:59', date_format + ' %H:%M:%S'
)
login_logs = login_logs.filter(
datetime__gt=date_form, datetime__lt=date_to
datetime__gte=date_from, datetime__lte=date_to
)
if user:
login_logs = login_logs.filter(username=user)
......
......@@ -121,7 +121,7 @@
});
})
.on('click', '.btn_export', function () {
var date_form = $('#id_date_from').val();
var date_from = $('#id_date_from').val();
var date_to = $('#id_date_to').val();
var user = $('.select2 option:selected').val();
var keyword = $('#search').val();
......@@ -129,7 +129,7 @@
url: "{% url "audits:login-log-export" %}",
method: 'POST',
data: JSON.stringify({
'date_form':date_form,
'date_from':date_from,
'date_to':date_to,
'user':user,
'keyword':keyword
......
......@@ -255,6 +255,7 @@ class CommandExecutionListView(UserCommandExecutionListView):
@method_decorator(csrf_exempt, name='dispatch')
class LoginLogExportView(PermissionsMixin, View):
permission_classes = [IsValidUser]
date_format = '%Y-%m-%d'
def get(self, request):
fields = [
......@@ -273,13 +274,14 @@ class LoginLogExportView(PermissionsMixin, View):
def post(self, request):
try:
date_form = json.loads(request.body).get('date_form', [])
date_from = json.loads(request.body).get('date_from', [])
date_to = json.loads(request.body).get('date_to', [])
user = json.loads(request.body).get('user', [])
keyword = json.loads(request.body).get('keyword', [])
login_logs = UserLoginLog.get_login_logs(
date_form=date_form, date_to=date_to, user=user, keyword=keyword)
date_from=date_from, date_to=date_to, user=user,
keyword=keyword, date_format=self.date_format)
except ValueError:
return HttpResponse('Json object not valid', status=400)
spm = uuid.uuid4().hex
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment