Skip to content

Commit

Permalink
feat(model): allow configuring display order of EligibilityVerifiers
Browse files Browse the repository at this point in the history
use `django-admin-sortable2` to handle updating / editing.
  • Loading branch information
angela-tran committed Mar 19, 2024
1 parent 33d11d5 commit 09be83e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion benefits/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +18,6 @@

for model in [
models.EligibilityType,
models.EligibilityVerifier,
models.PaymentProcessor,
models.PemData,
models.TransitAgency,
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
]
4 changes: 4 additions & 0 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions benefits/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def RUNTIME_ENVIRONMENT():
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.staticfiles",
"adminsortable2",
"django_google_sso",
"benefits.core",
"benefits.enrollment",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 09be83e

Please sign in to comment.