Reputation: 15
I'm trying to redirect the user to a custom HTML page after saving a BaseSiteSetting
model in Wagtail 4.1.1
I'm not sure how to accomplish this, the BaseSiteSetting
inherits from Django models.Model
which means it's possible to override the save()
function but how would I do the actual redirect without having access to the request?
Another acceptable solution would be to add an extra button in the CMS by overriding the default BaseSiteSetting HTML template
but I can't seem to get that working either, except for ModelAdmin templates. I've opened a StackOverflow question about that here.
My view of the custom HTML page:
def sync(request):
return render(request, "import.html", {"WS_PROTOCOL": settings.WS_PROTOCOL})
My BaseSiteSetting model:
@register_setting
class AnonymousSuccessStoryImportSetting(BaseSiteSetting):
"""
Setting for importing anonymous success stories.
"""
file = models.FileField(
upload_to="success_story_imports/%Y/%m/%d/",
validators=[validate_file_extension],
help_text="Upload a CSV file, then click 'Save' afterwards",
blank=True,
null=True,
)
date = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name = "Importer"
I've looked around for possible solutions and found some wagtail hooks but these only apply to the Wagtail Page model, for example, after_publish_page
.
It's unfortunate that there's no hook for standard Django models.
Upvotes: 0
Views: 214
Reputation: 1306
It looks to me like BaseSiteSettings is one of the models that has not been converted to use class-based views. So I think you need to monkey patch this edit method to change the 'after save' redirect here: https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/views.py#L121
Upvotes: 1