From 8da6c9cb487baef8f18ba03a84120bcd9b86b112 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 20 Jan 2022 15:58:43 +0100 Subject: [PATCH] TT#121955 define resources for django-import-export https://django-import-export.readthedocs.io/en/latest/getting_started.html#creating-import-export-resource * admin integration https://django-import-export.readthedocs.io/en/latest/getting_started.html#admin-integration Change-Id: I67da67943eea7b39fe63d7d8a910e2b889f92f6e --- build/admin.py | 12 ++++++++++-- hotfix/admin.py | 29 ++++++++++++++++++++++++++++ release_changed/admin.py | 13 ++++++++++--- release_dashboard/admin.py | 39 +++++++++++++++++++++++++++++++------- repoapi/admin.py | 33 ++++++++++++++++++++++---------- 5 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 hotfix/admin.py diff --git a/build/admin.py b/build/admin.py index bb4d956..869f24b 100644 --- a/build/admin.py +++ b/build/admin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017 The Sipwise Team - http://sipwise.com +# Copyright (C) 2017-2022 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,12 +13,20 @@ # 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 import_export import resources +from import_export.admin import ImportExportModelAdmin from . import models +class BuildReleaseResource(resources.ModelResource): + class Meta: + model = models.BuildRelease + + @admin.register(models.BuildRelease) -class BuildReleaseAdmin(admin.ModelAdmin): +class BuildReleaseAdmin(ImportExportModelAdmin): + resource_class = BuildReleaseResource list_filter = ("release",) readonly_fields = ("projects",) modify_readonly_fields = ( diff --git a/hotfix/admin.py b/hotfix/admin.py new file mode 100644 index 0000000..d2937b1 --- /dev/null +++ b/hotfix/admin.py @@ -0,0 +1,29 @@ +# Copyright (C) 2022 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 +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# 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 import_export import resources +from import_export.admin import ImportExportModelAdmin + +from . import models + + +class WorkfrontNoteInfoResource(resources.ModelResource): + class Meta: + model = models.WorkfrontNoteInfo + + +@admin.register(models.WorkfrontNoteInfo) +class WorkfrontNoteInfoAdmin(ImportExportModelAdmin): + resource_class = WorkfrontNoteInfoResource diff --git a/release_changed/admin.py b/release_changed/admin.py index a2cd6a5..35f5793 100644 --- a/release_changed/admin.py +++ b/release_changed/admin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2020 The Sipwise Team - http://sipwise.com +# Copyright (C) 2020-2022 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,10 +13,17 @@ # 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 import_export import resources +from import_export.admin import ImportExportModelAdmin from . import models +class ReleaseChangedResource(resources.ModelResource): + class Meta: + model = models.ReleaseChanged + + @admin.register(models.ReleaseChanged) -class ReleaseChangedAdmin(admin.ModelAdmin): - pass +class ReleaseChangedAdmin(ImportExportModelAdmin): + resource_class = ReleaseChangedResource diff --git a/release_dashboard/admin.py b/release_dashboard/admin.py index 9c7beb8..60ed668 100644 --- a/release_dashboard/admin.py +++ b/release_dashboard/admin.py @@ -1,24 +1,49 @@ -# Copyright (C) 2016 The Sipwise Team - http://sipwise.com - +# Copyright (C) 2016-2022 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 # Software Foundation, either version 3 of the License, or (at your option) # any later version. - +# # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. - +# # 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 import_export import resources +from import_export.admin import ImportExportModelAdmin + from . import models +class ProjectResource(resources.ModelResource): + class Meta: + model = models.Project + + +class DockerTagResource(resources.ModelResource): + class Meta: + model = models.DockerTag + + +class DockerImageResource(resources.ModelResource): + class Meta: + model = models.DockerImage + + @admin.register(models.DockerTag) +class DockerTagAdmin(ImportExportModelAdmin): + resource_class = DockerTagResource + + @admin.register(models.DockerImage) +class DockerImageAdmin(ImportExportModelAdmin): + resource_class = DockerImageResource + + @admin.register(models.Project) -class ProjectAdmin(admin.ModelAdmin): - pass +class ProjectAdmin(ImportExportModelAdmin): + resource_class = ProjectResource diff --git a/repoapi/admin.py b/repoapi/admin.py index e4ecde6..7e64f76 100644 --- a/repoapi/admin.py +++ b/repoapi/admin.py @@ -1,27 +1,40 @@ -# Copyright (C) 2015 The Sipwise Team - http://sipwise.com - +# Copyright (C) 2015-2022 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 # Software Foundation, either version 3 of the License, or (at your option) # any later version. - +# # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. - +# # 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 repoapi import models +from import_export import resources +from import_export.admin import ImportExportModelAdmin + +from . import models + + +class JenkinsBuildInfoResource(resources.ModelResource): + class Meta: + model = models.JenkinsBuildInfo + + +class GerritRepoInfoResource(resources.ModelResource): + class Meta: + model = models.GerritRepoInfo @admin.register(models.JenkinsBuildInfo) -class JenkinsBuildInfoAdmin(admin.ModelAdmin): - list_filter = ('param_release', 'projectname') +class JenkinsBuildInfoAdmin(ImportExportModelAdmin): + resource_class = JenkinsBuildInfoResource + list_filter = ("param_release", "projectname") @admin.register(models.GerritRepoInfo) -class GerritRepoInfoAdmin(admin.ModelAdmin): - pass +class GerritRepoInfoAdmin(ImportExportModelAdmin): + resource_class = GerritRepoInfoResource