From dec3d012c577d99b7490c3be9f1655acec9515bd Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Fri, 3 Mar 2023 21:05:32 +0100 Subject: [PATCH] MT#56231 repoapi: DateRange for GerritRepoInfo * supports date filters in admin panel Change-Id: I4c9580ff2ffa3f50301ff8f8d30bd060a9cae4e7 --- repoapi/admin.py | 25 +++++++++++++++++++++++-- repoapi/settings/common.py | 1 + requirements/common.txt | 1 + t/Dockerfile | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/repoapi/admin.py b/repoapi/admin.py index 0024046..d5d3cd4 100644 --- a/repoapi/admin.py +++ b/repoapi/admin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2022 The Sipwise Team - http://sipwise.com +# Copyright (C) 2015-2023 The Sipwise Team - http://sipwise.com # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . from django.contrib import admin +from django_admin_filters import DateRange from import_export import resources from import_export.admin import ImportExportModelAdmin @@ -35,10 +36,30 @@ class JenkinsBuildInfoAdmin(ImportExportModelAdmin): list_filter = ("param_release", "projectname") +class GRIDateRange(DateRange): + FILTER_LABEL = "Modified range" + BUTTON_LABEL = "Select range" + FROM_LABEL = "From" + TO_LABEL = "To" + ALL_LABEL = "All" + CUSTOM_LABEL = "custom range" + DATE_FORMAT = "YYYY-MM-DD HH:mm" + + is_null_option = False + + day_val = 60 * 60 * 24 + month_val = day_val * 30 + options = ( + ("1dp", "last 24 hours", -day_val), + ("1mp", "last 30 days", -month_val), + ("3mp", "last 3 months", -month_val * 3), + ) + + @admin.register(models.GerritRepoInfo) class GerritRepoInfoAdmin(ImportExportModelAdmin): resource_class = GerritRepoInfoResource - list_filter = ("param_ppa", "projectname") + list_filter = (("modified", GRIDateRange), "projectname", "param_ppa") class WorkfrontNoteInfoResource(resources.ModelResource): diff --git a/repoapi/settings/common.py b/repoapi/settings/common.py index 703a7d2..a4b62a6 100644 --- a/repoapi/settings/common.py +++ b/repoapi/settings/common.py @@ -35,6 +35,7 @@ INSTALLED_APPS = [ "django_celery_results", "django_extensions", "django_filters", + "django_admin_filters", "crispy_forms", "jsonify", "import_export", diff --git a/requirements/common.txt b/requirements/common.txt index e3d908b..033fad4 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -1,5 +1,6 @@ celery Django==3.2.18 +django-admin-list-filters django-appconf django-assets django-celery-beat diff --git a/t/Dockerfile b/t/Dockerfile index 4f2255f..dd3c655 100644 --- a/t/Dockerfile +++ b/t/Dockerfile @@ -5,7 +5,7 @@ FROM docker.mgm.sipwise.com/sipwise-bullseye:latest # is updated with the current date. It will force refresh of all # of the base images and things like `apt-get update` won't be using # old cached versions when the Dockerfile is built. -ENV REFRESHED_AT 2022-10-11 +ENV REFRESHED_AT 2023-03-04 RUN apt-get update && apt-get install --assume-yes python3 python3-dev \ python3-pytest python3-pytest-pep8 \