From 584e9ef5618adb176d48bbae2cb30effa056a99a Mon Sep 17 00:00:00 2001 From: pamfilos Date: Mon, 16 Sep 2024 13:18:56 +0200 Subject: [PATCH] tools(format): update export forms, move to admin site Signed-off-by: pamfilos --- config/urls.py | 6 +++++- scoap3/exports/forms.py | 19 ++++++++----------- scoap3/exports/views.py | 5 +++-- scoap3/misc/models.py | 1 + 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/config/urls.py b/config/urls.py index dc57cd08..5229a6eb 100644 --- a/config/urls.py +++ b/config/urls.py @@ -15,7 +15,11 @@ "about/", TemplateView.as_view(template_name="pages/about.html"), name="about" ), # Django Admin, use {% url 'admin:index' %} - path(settings.ADMIN_URL + "tools/", admin.site.admin_view(ExportView.as_view()), name="admin_tools"), + path( + settings.ADMIN_URL + "tools/", + admin.site.admin_view(ExportView.as_view()), + name="admin_tools", + ), path(settings.ADMIN_URL, admin.site.urls), path("select2/", include("django_select2.urls")), # User management diff --git a/scoap3/exports/forms.py b/scoap3/exports/forms.py index 3fb42eee..45f98e9c 100644 --- a/scoap3/exports/forms.py +++ b/scoap3/exports/forms.py @@ -3,17 +3,14 @@ from scoap3.misc.models import Country + class CountryWidget(ModelSelect2Widget): - search_fields = [ - "code__icontains", - "name__icontains" - ] + search_fields = ["code__icontains", "name__icontains"] + class Country2Widget(ModelSelect2Widget): - search_fields = [ - "code__icontains", - "name__icontains" - ] + search_fields = ["code__icontains", "name__icontains"] + class AffiliationExportForm(forms.Form): aff_year = forms.IntegerField(label="Year", required=True) @@ -21,7 +18,7 @@ class AffiliationExportForm(forms.Form): queryset=Country.objects.all(), widget=Country2Widget, label="Country", - required=True + required=True, ) @@ -31,5 +28,5 @@ class AuthorExportForm(forms.Form): queryset=Country.objects.all(), widget=CountryWidget, label="Country", - required=True - ) \ No newline at end of file + required=True, + ) diff --git a/scoap3/exports/views.py b/scoap3/exports/views.py index 3fedc203..511b4385 100644 --- a/scoap3/exports/views.py +++ b/scoap3/exports/views.py @@ -2,7 +2,8 @@ from datetime import datetime from django.contrib import messages -from django.contrib.auth.mixins import PermissionRequiredMixin + +# from django.contrib.auth.mixins import PermissionRequiredMixin from django.http import HttpResponse from django.views.generic.edit import FormView @@ -27,7 +28,7 @@ def generate_csv_response(data, action_name, write_header=True): return response -class ExportView( FormView): +class ExportView(FormView): # permission_required = "users.partner_export" template_name = "admin/tools.html" form_class = AffiliationExportForm diff --git a/scoap3/misc/models.py b/scoap3/misc/models.py index fc54474e..6c44cacb 100644 --- a/scoap3/misc/models.py +++ b/scoap3/misc/models.py @@ -16,6 +16,7 @@ class Meta: def __str__(self): return f"{self.name} ({self.code})" + class Affiliation(models.Model): author_id = models.ManyToManyField("authors.Author", blank=True) country = models.ForeignKey("misc.Country", on_delete=models.CASCADE, null=True)