Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Hide path to the image in ProductImageForm

michalff5ffcbc4898
diff --git a/saleor/dashboard/product/widgets.py b/saleor/dashboard/product/widgets.py
index 1122a8d2f0..280869e6ae 100644
--- a/saleor/dashboard/product/widgets.py
+++ b/saleor/dashboard/product/widgets.py
@@ -4,6 +4,7 @@ from versatileimagefield.widgets import (ClearableFileInputWithImagePreview,
class ImagePreviewFileInput(ClearableFileInputWithImagePreview):
+ template_name = 'dashboard/product/product_image/versatile_image.html'
template_with_initial_and_imagepreview = """
<div class="sizedimage-mod preview">
<div class="image-wrap outer">
@@ -17,6 +18,18 @@ class ImagePreviewFileInput(ClearableFileInputWithImagePreview):
</div>
</div>"""
+ def get_context(self, name, value, attrs):
+ context = super(ImagePreviewFileInput, self).get_context(
+ name, value, attrs)
+ value = context['widget']['value']
+ if value:
+ value.display_value = self.get_filename_from_path(str(value))
+ return context
+
+ def get_filename_from_path(self, path):
+ filename = path.split('/')[-1]
+ return filename if filename else path
+
class ImagePreviewWidget(SizedImageCenterpointWidgetMixIn, MultiWidget):
def __init__(self, attrs=None):
diff --git a/templates/dashboard/product/product_image/versatile_image.html b/templates/dashboard/product/product_image/versatile_image.html
new file mode 100644
index 0000000000..552d861e4b
--- /dev/null
+++ b/templates/dashboard/product/product_image/versatile_image.html
@@ -0,0 +1,36 @@
+{% load i18n %}
+{% if widget.is_initial %}
+<div class="sizedimage-mod initial">
+ <label class="versatileimagefield-label">{{ widget.initial_text }}</label>
+ <a href="{{ widget.value.url }}">{{ widget.value.display_value }}</a>
+</div>
+{% if not widget.required %}
+<div class="sizedimage-mod clear">
+ <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}" />
+ <label class="versatileimagefield-label" for="{{ widget.checkbox_id }}">
+ {{ widget.clear_checkbox_label }}:
+ </label>
+</div>
+{% endif %}
+{% endif %}
+<div class="sizedimage-mod preview">
+ <label class="versatileimagefield-label">{% trans "Primary Point of Interest" %}</label>
+ <div class="image-wrap outer">
+ <div class="point-stage" id="{{ widget.point_stage_id }}"
+ data-image_preview_id="{{ widget.image_preview_id }}">
+ <div class="ppoi-point" id="{{ widget.ppoi_id }}"></div>
+ </div>
+ {% if widget.value %}
+ <div class="image-wrap inner">
+ <img src="{{ widget.sized_url }}" id="{{ widget.image_preview_id }}"
+ data-hidden_field_id="{{ widget.hidden_field_id }}"
+ data-point_stage_id="{{ widget.point_stage_id }}"
+ data-ppoi_id="{{ widget.ppoi_id }}" class="sizedimage-preview" />
+ </div>
+ {% endif %}
+ </div>
+</div>
+<div class="sizedimage-mod new-upload">
+ <label class="versatileimagefield-label">{{ widget.input_text }}</label>
+ <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "versatileimagefield/forms/widgets/attrs.html" %} />
+</div>