feat: Add preview widget in Image Field Form
This commit is contained in:
parent
fce719aca1
commit
9e77205fed
|
@ -20,3 +20,5 @@ MEDIA = getattr(settings, 'GAS_MEDIA', {
|
|||
})
|
||||
|
||||
EXTRA_MEDIA = getattr(settings, 'GAS_EXTRA_MEDIA', None)
|
||||
|
||||
IMAGE_PREVIEW_WIDTH = getattr(settings, 'IMAGE_PREVIEW_WIDTH', 240)
|
||||
|
|
|
@ -262,3 +262,7 @@ label {
|
|||
width: 20em;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
.preview {
|
||||
display: block;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}"><img src="{{ widget.value.url }}" width="{{ widget.attrs.IMAGE_PREVIEW_WIDTH }}" class="preview" /></a>{% if not widget.required %}
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"{% if widget.attrs.disabled %} disabled{% endif %}>
|
||||
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br>
|
||||
{{ widget.input_text }}:{% endif %}
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
|
|
@ -1,7 +1,8 @@
|
|||
from django import forms
|
||||
from django import template
|
||||
from django import forms, template
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from ..gas_settings import IMAGE_PREVIEW_WIDTH
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
|
@ -19,6 +20,10 @@ def base_form_field(field, css=None, container_class='', add_another_url=None, f
|
|||
elif isinstance(field.field, forms.DateField):
|
||||
field.field.widget.input_type = 'date'
|
||||
|
||||
if isinstance(field.field, forms.ImageField):
|
||||
field.field.widget.template_name = 'gas/tags/widgets/image_preview.html'
|
||||
field.field.widget.attrs['IMAGE_PREVIEW_WIDTH'] = IMAGE_PREVIEW_WIDTH
|
||||
|
||||
if isinstance(field.field, forms.SplitDateTimeField):
|
||||
field.field.widget.widgets[1].attrs['placeholder'] = '00:00:00'
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue