diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 51fad1c58..65f287adc 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1319,33 +1319,32 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin): change_form_template = "django/admin/domain_information_change_form.html" - superuser_only_fields = [ "portfolio", ] # DEVELOPER's NOTE: - # Normally, to exclude a field from an Admin form, we could simply utilize + # Normally, to exclude a field from an Admin form, we could simply utilize # Django's "exclude" feature. However, it causes a "missing key" error if we # go that route for this particular form. The error gets thrown by our # custom fieldset.html code and is due to the fact that "exclude" removes - # fields from base_fields but not fieldsets. Rather than reworking our + # fields from base_fields but not fieldsets. Rather than reworking our # custom frontend, it seems more straightforward (and easier to read) to simply # modify the fieldsets list so that it excludes any fields we want to remove # based on permissions (eg. superuser_only_fields) or other conditions. def get_fieldsets(self, request, obj=None): fieldsets = super().get_fieldsets(request, obj) - + # Create a modified version of fieldsets without the 'isbn' field if not request.user.has_perm("registrar.full_access_permission"): modified_fieldsets = [] for name, data in fieldsets: - fields = data.get('fields', []) + fields = data.get("fields", []) fields = tuple(field for field in fields if field not in self.superuser_only_fields) - modified_fieldsets.append((name, {'fields': fields})) + modified_fieldsets.append((name, {"fields": fields})) return modified_fieldsets return fieldsets - + def get_readonly_fields(self, request, obj=None): """Set the read-only state on form elements. We have 1 conditions that determine which fields are read-only: @@ -1625,48 +1624,27 @@ def custom_election_board(self, obj): ] # DEVELOPER's NOTE: - # Normally, to exclude a field from an Admin form, we could simply utilize + # Normally, to exclude a field from an Admin form, we could simply utilize # Django's "exclude" feature. However, it causes a "missing key" error if we # go that route for this particular form. The error gets thrown by our # custom fieldset.html code and is due to the fact that "exclude" removes - # fields from base_fields but not fieldsets. Rather than reworking our + # fields from base_fields but not fieldsets. Rather than reworking our # custom frontend, it seems more straightforward (and easier to read) to simply # modify the fieldsets list so that it excludes any fields we want to remove # based on permissions (eg. superuser_only_fields) or other conditions. def get_fieldsets(self, request, obj=None): fieldsets = super().get_fieldsets(request, obj) - + # Create a modified version of fieldsets without the 'isbn' field if not request.user.has_perm("registrar.full_access_permission"): modified_fieldsets = [] for name, data in fieldsets: - fields = data.get('fields', []) + fields = data.get("fields", []) fields = tuple(field for field in fields if field not in self.superuser_only_fields) - modified_fieldsets.append((name, {'fields': fields})) + modified_fieldsets.append((name, {"fields": fields})) return modified_fieldsets return fieldsets - # Fields only superusers can view - # exclude = ['address_line1', ] - # widgets = {'portfolio': forms.HiddenInput()} - - - # def get_form(self, request, obj, **kwargs): - # if request.user.has_perm("registrar.full_access_permission"): - # self.exclude = self.superuser_only_fields - # # self.fieldsets[1][1]['fields'][0].append('portfolio') - # # self.fieldsets[1][1]['fields'].pop('status') - # form = super(DomainRequestAdmin, self).get_form(request, obj, **kwargs) - # return form - - - # if not request.user.has_perm("registrar.full_access_permission"): - - # for fieldset in self.fieldsets: - # for field in fieldset[0]["fields"]: - # if field== - - # Table ordering # NOTE: This impacts the select2 dropdowns (combobox) # Currentl, there's only one for requests on DomainInfo @@ -1925,7 +1903,6 @@ def change_view(self, request, object_id, form_url="", extra_context=None): return super().change_view(request, object_id, form_url, extra_context) def process_log_entry(self, log_entry): - """Process a log entry and return filtered entry dictionary if applicable.""" changes = log_entry.changes status_changed = "status" in changes @@ -1981,8 +1958,7 @@ def process_log_entry(self, log_entry): return entry return None - - + class TransitionDomainAdmin(ListHeaderAdmin): """Custom transition domain admin class.""" @@ -2638,7 +2614,6 @@ class PortfolioAdmin(ListHeaderAdmin): # "requestor", # ] - def save_model(self, request, obj, form, change): if obj.creator is not None: diff --git a/src/registrar/models/portfolio.py b/src/registrar/models/portfolio.py index 9fefacc31..0ea036bb7 100644 --- a/src/registrar/models/portfolio.py +++ b/src/registrar/models/portfolio.py @@ -99,4 +99,4 @@ class Portfolio(TimeStampedModel): ) def __str__(self) -> str: - return f"{self.organization_name}" \ No newline at end of file + return f"{self.organization_name}"