mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 04:59:59 +02:00
Adding all the status filter and custom filter set up for dropdown
This commit is contained in:
parent
d8d9475938
commit
77ddc6700a
2 changed files with 80 additions and 11 deletions
|
@ -1478,9 +1478,31 @@ class BaseInvitationAdmin(ListHeaderAdmin):
|
|||
return response
|
||||
|
||||
|
||||
# class DomainInvitationAdminForm(forms.ModelForm):
|
||||
# """Custom form for DomainInvitation in admin to only allow cancellations."""
|
||||
|
||||
# STATUS_CHOICES = [
|
||||
# ("", "------"), # no action
|
||||
# ("canceled", "Canceled"),
|
||||
# ]
|
||||
|
||||
# status = forms.ChoiceField(choices=STATUS_CHOICES, required=False, label="Status")
|
||||
|
||||
# class Meta:
|
||||
# model = models.DomainInvitation
|
||||
# fields = "__all__"
|
||||
|
||||
# def clean_status(self):
|
||||
# # Clean status - we purposely dont edit anything so we dont mess with the state
|
||||
# status = self.cleaned_data.get("status")
|
||||
# return status
|
||||
|
||||
|
||||
class DomainInvitationAdmin(BaseInvitationAdmin):
|
||||
"""Custom domain invitation admin class."""
|
||||
|
||||
# form = DomainInvitationAdminForm
|
||||
|
||||
class Meta:
|
||||
model = models.DomainInvitation
|
||||
fields = "__all__"
|
||||
|
@ -1505,23 +1527,49 @@ class DomainInvitationAdmin(BaseInvitationAdmin):
|
|||
|
||||
search_help_text = "Search by email or domain."
|
||||
|
||||
# Mark the FSM field 'status' as readonly
|
||||
# to allow admin users to create Domain Invitations
|
||||
# without triggering the FSM Transition Not Allowed
|
||||
# error.
|
||||
# # Mark the FSM field 'status' as readonly
|
||||
# # to allow admin users to create Domain Invitations
|
||||
# # without triggering the FSM Transition Not Allowed
|
||||
# # error.
|
||||
# readonly_fields = ["status"]
|
||||
|
||||
# Now it can be edited
|
||||
readonly_fields = ["status"]
|
||||
|
||||
autocomplete_fields = ["domain"]
|
||||
|
||||
change_form_template = "django/admin/domain_invitation_change_form.html"
|
||||
|
||||
# Select domain invitations to change -> Domain invitations
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
if extra_context is None:
|
||||
extra_context = {}
|
||||
extra_context["tabtitle"] = "Domain invitations"
|
||||
# Get the filtered values
|
||||
return super().changelist_view(request, extra_context=extra_context)
|
||||
# # Custom status filter within DomainInvitationAdmin
|
||||
# class StatusListFilter(admin.SimpleListFilter):
|
||||
# # custom filter for status field
|
||||
|
||||
# title = _("status")
|
||||
# parameter_name = "status"
|
||||
|
||||
# def lookups(self, request, model_admin):
|
||||
# # only return cancel as option
|
||||
# return [
|
||||
# ('canceled', _('Canceled')),
|
||||
# ('invited', _('Invited')),
|
||||
# ('retrieved', _('Retrieved')),
|
||||
# ]
|
||||
|
||||
# def queryset(self, request, queryset):
|
||||
# """Filter the queryset based on the selected status."""
|
||||
# if self.value():
|
||||
# return queryset.filter(status=self.value()) # Apply the filter based on the selected status
|
||||
# return queryset
|
||||
|
||||
# list_filter = (StatusListFilter,) # Apply the custom filter to the list view
|
||||
|
||||
# # Select domain invitations to change -> Domain invitations
|
||||
# def changelist_view(self, request, extra_context=None):
|
||||
# if extra_context is None:
|
||||
# extra_context = {}
|
||||
# extra_context["tabtitle"] = "Domain invitations"
|
||||
# # Get the filtered values
|
||||
# return super().changelist_view(request, extra_context=extra_context)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
"""
|
||||
|
@ -1531,6 +1579,23 @@ class DomainInvitationAdmin(BaseInvitationAdmin):
|
|||
which will be successful if a single User exists for that email; otherwise, will
|
||||
just continue to create the invitation.
|
||||
"""
|
||||
|
||||
# print("***** IN SAVE_MODEL, OUTSIDE OF CHANGE")
|
||||
|
||||
# # If there is a change and it's related to status, look for canceled
|
||||
# if change and "status" in form.changed_data:
|
||||
# print("********* DO WE COME INTO THE CHANGE SECTION")
|
||||
# if obj.status == DomainInvitation.DomainInvitationStatus.CANCELED:
|
||||
# # Call the transition method to change the status
|
||||
# obj.cancel_invitation()
|
||||
# messages.success(request, f"Invitation for {obj.email} has been canceled.")
|
||||
# return super().save_model(request, obj, form, change)
|
||||
|
||||
# # if invited/retrieved dont alow manual changes
|
||||
# if obj.status not in [DomainInvitation.DomainInvitationStatus.INVITED, DomainInvitation.DomainInvitationStatus.RETRIEVED]:
|
||||
# messages.error(request, "You cannot manually set the status to anything other than 'invited' or 'retrieved'.")
|
||||
# return
|
||||
|
||||
if not change:
|
||||
domain = obj.domain
|
||||
domain_org = getattr(domain.domain_info, "portfolio", None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue