mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
Make chooser_select_format into a class-based view
This commit is contained in:
parent
21d172200c
commit
e173ca9f22
@ -46,7 +46,7 @@ urlpatterns = [
|
||||
path("chooser/upload/", chooser.ImageUploadView.as_view(), name="chooser_upload"),
|
||||
path(
|
||||
"chooser/<int:image_id>/select_format/",
|
||||
chooser.chooser_select_format,
|
||||
chooser.ImageSelectFormatView.as_view(),
|
||||
name="chooser_select_format",
|
||||
),
|
||||
]
|
||||
|
@ -278,10 +278,20 @@ class ImageUploadView(
|
||||
pass
|
||||
|
||||
|
||||
def chooser_select_format(request, image_id):
|
||||
class ImageSelectFormatView(View):
|
||||
def get(self, request, image_id):
|
||||
image = get_object_or_404(get_image_model(), id=image_id)
|
||||
initial = {"alt_text": image.default_alt_text}
|
||||
initial.update(request.GET.dict())
|
||||
# If you edit an existing image, and there is no alt text, ensure that
|
||||
# "image is decorative" is ticked when you open the form
|
||||
initial["image_is_decorative"] = initial["alt_text"] == ""
|
||||
form = ImageInsertionForm(initial=initial, prefix="image-chooser-insertion")
|
||||
return self.render_select_format_response(image, form)
|
||||
|
||||
def post(self, request, image_id):
|
||||
image = get_object_or_404(get_image_model(), id=image_id)
|
||||
|
||||
if request.method == "POST":
|
||||
form = ImageInsertionForm(
|
||||
request.POST,
|
||||
initial={"alt_text": image.default_alt_text},
|
||||
@ -316,15 +326,11 @@ def chooser_select_format(request, image_id):
|
||||
json_data={"step": "chosen", "result": image_data},
|
||||
)
|
||||
else:
|
||||
initial = {"alt_text": image.default_alt_text}
|
||||
initial.update(request.GET.dict())
|
||||
# If you edit an existing image, and there is no alt text, ensure that
|
||||
# "image is decorative" is ticked when you open the form
|
||||
initial["image_is_decorative"] = initial["alt_text"] == ""
|
||||
form = ImageInsertionForm(initial=initial, prefix="image-chooser-insertion")
|
||||
return self.render_select_format_response(image, form)
|
||||
|
||||
def render_select_format_response(self, image, form):
|
||||
return render_modal_workflow(
|
||||
request,
|
||||
self.request,
|
||||
"wagtailimages/chooser/select_format.html",
|
||||
None,
|
||||
{"image": image, "form": form},
|
||||
|
Loading…
Reference in New Issue
Block a user