Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edit not available in in-app messages Admin section #4613

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 9 additions & 12 deletions kobo/apps/help/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@ class InAppMessageAdmin(MarkdownxModelAdminBase):
)
readonly_fields = ['uid', 'last_editor']

def get_form(self, *args, **kwargs):
def get_fieldsets(self, request, obj=None):
"""
Allows us to add warning messages to the top of the form without
manually maintaining a list of model fields in this class. An
approximation of a model-level `help_text`
"""

# Get the auto-generated form, which will contain the appropriate list
# of fields, from the superclass
form = super().get_form(*args, **kwargs)

# Next, build `fieldsets` using our warning messages and that list of
# fields. From the Django documentation:
# fieldsets is a list of two-tuples…in the format (name,
Expand All @@ -35,13 +30,15 @@ def get_form(self, *args, **kwargs):
# about the fieldset, including a list of fields to be displayed in
# it.
# The name is effectively a heading. To use multiple headings as
# for warnings, a second field set must be set with with the list
# for warnings, a second field set must be set with the list
# of fields set to an empty string.
# https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets
self.fieldsets = [
(self.new_message_warning, {'fields': ''}),
]
return form
# https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets

fieldsets = super().get_fieldsets(request, obj)
# Only display messages on edit.
if obj:
fieldsets.insert(0, (self.new_message_warning, {'fields': ''}))
return fieldsets

def save_model(self, request, obj, form, change):
obj.last_editor = request.user
Expand Down