diff --git a/benefits/core/admin.py b/benefits/core/admin.py index cb468b629..6a06fee20 100644 --- a/benefits/core/admin.py +++ b/benefits/core/admin.py @@ -5,6 +5,7 @@ import logging import requests +from adminsortable2.admin import SortableAdminMixin from django.conf import settings from django.contrib import admin from . import models @@ -17,7 +18,6 @@ for model in [ models.EligibilityType, - models.EligibilityVerifier, models.PaymentProcessor, models.PemData, models.TransitAgency, @@ -26,6 +26,11 @@ admin.site.register(model) +@admin.register(models.EligibilityVerifier) +class SortableEligibilityVerifierAdmin(SortableAdminMixin, admin.ModelAdmin): + pass + + def pre_login_user(user, request): logger.debug(f"Running pre-login callback for user: {user.username}") token = request.session.get("google_sso_access_token") diff --git a/benefits/core/migrations/0004_alter_eligibilityverifier_display_order.py b/benefits/core/migrations/0004_alter_eligibilityverifier_display_order.py new file mode 100644 index 000000000..f455e8e24 --- /dev/null +++ b/benefits/core/migrations/0004_alter_eligibilityverifier_display_order.py @@ -0,0 +1,30 @@ +# Generated by Django 5.0.3 on 2024-03-19 20:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0003_eligibilitytype_expiration"), + ] + + # see https://django-admin-sortable2.readthedocs.io/en/latest/usage.html#initial-data + def set_initial_display_order(apps, schema_editor): + EligibilityVerifier = apps.get_model("core", "EligibilityVerifier") + for order, item in enumerate(EligibilityVerifier.objects.all(), 1): + item.display_order = order + item.save(update_fields=["display_order"]) + + operations = [ + migrations.AlterModelOptions( + name="eligibilityverifier", + options={"ordering": ["display_order"]}, + ), + migrations.AddField( + model_name="eligibilityverifier", + name="display_order", + field=models.PositiveSmallIntegerField(default=0), + ), + migrations.RunPython(set_initial_display_order, reverse_code=migrations.RunPython.noop), + ] diff --git a/benefits/core/models.py b/benefits/core/models.py index ec3c3499b..36010414a 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -158,6 +158,7 @@ class EligibilityVerifier(models.Model): id = models.AutoField(primary_key=True) name = models.TextField() + display_order = models.PositiveSmallIntegerField(default=0, blank=False, null=False) active = models.BooleanField(default=False) api_url = models.TextField(null=True) api_auth_header = models.TextField(null=True) @@ -177,6 +178,9 @@ class EligibilityVerifier(models.Model): # reference to a form class used by this Verifier, e.g. benefits.app.forms.FormClass form_class = models.TextField(null=True) + class Meta: + ordering = ["display_order"] + def __str__(self): return self.name diff --git a/benefits/settings.py b/benefits/settings.py index 35163a339..7e19d3e74 100644 --- a/benefits/settings.py +++ b/benefits/settings.py @@ -49,6 +49,7 @@ def RUNTIME_ENVIRONMENT(): "django.contrib.messages", "django.contrib.sessions", "django.contrib.staticfiles", + "adminsortable2", "django_google_sso", "benefits.core", "benefits.enrollment", diff --git a/pyproject.toml b/pyproject.toml index 1b2323b94..71c529665 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ dependencies = [ "azure-identity==1.15.0", "Django==5.0.3", "django-csp==3.8", + "django-admin-sortable2==2.1.5", "django-google-sso==6.0.2", "eligibility-api==2023.9.1", "calitp-littlepay==2024.3.1",