feat: Add preview widget in Image Field Form #4
|
@ -20,3 +20,5 @@ MEDIA = getattr(settings, 'GAS_MEDIA', {
|
||||||
})
|
})
|
||||||
|
|
||||||
EXTRA_MEDIA = getattr(settings, 'GAS_EXTRA_MEDIA', None)
|
EXTRA_MEDIA = getattr(settings, 'GAS_EXTRA_MEDIA', None)
|
||||||
|
|
||||||
|
IMAGE_PREVIEW_WIDTH = getattr(settings, 'IMAGE_PREVIEW_WIDTH', 240)
|
||||||
|
|
|
@ -262,3 +262,7 @@ label {
|
||||||
width: 20em;
|
width: 20em;
|
||||||
padding: 1em;
|
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 forms, template
|
||||||
from django import template
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
|
from ..gas_settings import IMAGE_PREVIEW_WIDTH
|
||||||
|
|
||||||
register = template.Library()
|
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):
|
elif isinstance(field.field, forms.DateField):
|
||||||
field.field.widget.input_type = 'date'
|
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):
|
if isinstance(field.field, forms.SplitDateTimeField):
|
||||||
field.field.widget.widgets[1].attrs['placeholder'] = '00:00:00'
|
field.field.widget.widgets[1].attrs['placeholder'] = '00:00:00'
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue