Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoByte committed Jun 20, 2024
1 parent df719f2 commit 7c2c9a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
49 changes: 12 additions & 37 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1981,8 +1958,7 @@ def process_log_entry(self, log_entry):
return entry

return None




class TransitionDomainAdmin(ListHeaderAdmin):
"""Custom transition domain admin class."""
Expand Down Expand Up @@ -2638,7 +2614,6 @@ class PortfolioAdmin(ListHeaderAdmin):
# "requestor",
# ]


def save_model(self, request, obj, form, change):

if obj.creator is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/models/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ class Portfolio(TimeStampedModel):
)

def __str__(self) -> str:
return f"{self.organization_name}"
return f"{self.organization_name}"

0 comments on commit 7c2c9a1

Please sign in to comment.