@ -0,0 +1,27 @@ |
|||||
|
import pathlib |
||||
|
from django import template |
||||
|
from django.conf import settings |
||||
|
from django.db import models |
||||
|
from django.templatetags.static import static |
||||
|
|
||||
|
register = template.Library() |
||||
|
|
||||
|
ICONS_FOLDER = settings.STATIC_ROOT / "img/icons/" |
||||
|
|
||||
|
|
||||
|
@register.filter |
||||
|
def file_image(value): |
||||
|
if not isinstance(value, models.fields.files.FieldFile): |
||||
|
return value |
||||
|
if is_image(value): |
||||
|
return value.url or static("img/icons/unknown.jpg") |
||||
|
sufixo = pathlib.Path(value.name).suffix[1:] |
||||
|
if (ICONS_FOLDER / f"{sufixo}.jpg").exists(): |
||||
|
return static(f"img/icons/{sufixo}.jpg") |
||||
|
else: |
||||
|
return static("img/icons/unknown.jpg") |
||||
|
|
||||
|
|
||||
|
@register.filter |
||||
|
def is_image(value): |
||||
|
return isinstance(value, models.fields.files.ImageFieldFile) |
@ -0,0 +1,3 @@ |
|||||
|
.file-field input[type="file"] { |
||||
|
left: 65px; |
||||
|
} |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 9.6 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 14 KiB |
@ -0,0 +1,3 @@ |
|||||
|
$(document).ready(function () { |
||||
|
M.Materialbox.init($('.materialboxed')); |
||||
|
}) |
@ -1,19 +1 @@ |
|||||
<a href="{{ widget.value.url }}"><img src="{{ widget.value.url }}" /></a> |
{% extends "django/forms/widgets/clearable_file_input.html" %} |
||||
{% if widget.is_initial %} |
|
||||
<p class="file-upload"> |
|
||||
{{ widget.initial_text }}: |
|
||||
<a href="{{ widget.value.url }}">{{ widget.value }}</a> |
|
||||
{% if not widget.required %} |
|
||||
<span class="clearable-file-input"> |
|
||||
<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> |
|
||||
</span> |
|
||||
{% endif %} |
|
||||
<br> |
|
||||
{{ widget.input_text }}: |
|
||||
{% endif %} |
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}" {% include "django/forms/widgets/attrs.html" %}> |
|
||||
{% if widget.is_initial %} |
|
||||
</p> |
|
||||
{% endif %} |
|