Browse Source

Ajustes genéricos de viasualização

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
85aebec10a
  1. 27
      sigi/apps/utils/templatetags/file_image.py
  2. 3
      sigi/static/css/materialize-adjusts.css
  3. BIN
      sigi/static/img/icons/csv.jpg
  4. BIN
      sigi/static/img/icons/doc.jpg
  5. BIN
      sigi/static/img/icons/docx.jpg
  6. BIN
      sigi/static/img/icons/json.jpg
  7. BIN
      sigi/static/img/icons/odp.jpg
  8. BIN
      sigi/static/img/icons/ods.jpg
  9. BIN
      sigi/static/img/icons/odt.jpg
  10. BIN
      sigi/static/img/icons/pdf.jpg
  11. BIN
      sigi/static/img/icons/unknown.jpg
  12. BIN
      sigi/static/img/icons/xls.jpg
  13. BIN
      sigi/static/img/icons/xlsx.jpg
  14. 3
      sigi/static/js/materialize-inits.js
  15. 6
      sigi/templates/admin/base_site.html
  16. 20
      sigi/templates/admin/widgets/clearable_file_input.html
  17. 11
      sigi/templates/django/forms/material_form.html
  18. 12
      sigi/templates/django/forms/widgets/clearable_file_input.html

27
sigi/apps/utils/templatetags/file_image.py

@ -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)

3
sigi/static/css/materialize-adjusts.css

@ -0,0 +1,3 @@
.file-field input[type="file"] {
left: 65px;
}

BIN
sigi/static/img/icons/csv.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
sigi/static/img/icons/doc.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
sigi/static/img/icons/docx.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
sigi/static/img/icons/json.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

BIN
sigi/static/img/icons/odp.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
sigi/static/img/icons/ods.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
sigi/static/img/icons/odt.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
sigi/static/img/icons/pdf.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
sigi/static/img/icons/unknown.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
sigi/static/img/icons/xls.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
sigi/static/img/icons/xlsx.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

3
sigi/static/js/materialize-inits.js

@ -0,0 +1,3 @@
$(document).ready(function () {
M.Materialbox.init($('.materialboxed'));
})

6
sigi/templates/admin/base_site.html

@ -4,6 +4,7 @@
{% block theme %} {% block theme %}
<link rel="stylesheet" type="text/css" href="{% static 'material/admin/css/base_site-green.min.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'material/admin/css/base_site-green.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'material/admin/css/base_site-theme.min.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'material/admin/css/base_site-theme.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/materialize-adjusts.css' %}">
{% endblock %} {% endblock %}
{% block breadcrumbs %}{% endblock %} {% block breadcrumbs %}{% endblock %}
@ -29,3 +30,8 @@
<i class="material-icons" aria-hidden="true">exit_to_app</i> <i class="material-icons" aria-hidden="true">exit_to_app</i>
</a> </a>
{% endblock %} {% endblock %}
{% block footer %}
{{ block.super }}
<script src="{% static 'js/materialize-inits.js' %}"></script>
{% endblock %}

20
sigi/templates/admin/widgets/clearable_file_input.html

@ -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 %}

11
sigi/templates/django/forms/material_form.html

@ -3,12 +3,21 @@
<p>{% for field in hidden_fields %}{{ field }}{% endfor %}</p> <p>{% for field in hidden_fields %}{{ field }}{% endfor %}</p>
{% endif %} {% endif %}
{% for field, errors in fields %} {% for field, errors in fields %}
<div{% with classes=field.css_classes %} class="{% if field.widget_type != 'clearablefile' %}input-field {% endif %}{{ classes }}" {% endwith %}> <div{% with classes=field.css_classes %} class="input-field {{ classes }}" {% endwith %}>
<small class="error"> <small class="error">
{{ errors }} {{ errors }}
</small> </small>
{% if field.widget_type == 'checkbox' %}
<p>
<label>
{{ field }}
<span>{{ field.label }}</span>
</label>
</p>
{% else %}
{% if field.label %}{{ field.label_tag }}{% endif %} {% if field.label %}{{ field.label_tag }}{% endif %}
{{ field }} {{ field }}
{% endif %}
{% if field.help_text %} {% if field.help_text %}
<small class="helptext">{{ field.help_text|safe }}</small> <small class="helptext">{{ field.help_text|safe }}</small>
{% endif %} {% endif %}

12
sigi/templates/django/forms/widgets/clearable_file_input.html

@ -1,9 +1,8 @@
{% load i18n %} {% load i18n file_image %}
<div class="file-field input-field"> <div class="file-field">
{% if widget.is_initial %} {% if widget.is_initial %}
<div class="left" style="padding: 5px;"> <div class="left" style="padding: 5px;">
<a href="{{ widget.value.url }}"> <img src="{{ widget.value|file_image }}" alt="{{ widget.value }}" height="60" width="60" {% if widget.value|is_image %} class="materialboxed"{% endif %}/>
<img src="{{ widget.value.url }}" alt="{{ widget.value }}" height="60" width="60"/>
</a> </a>
</div> </div>
{% endif %} {% endif %}
@ -16,12 +15,13 @@
</div> </div>
</div> </div>
{% if widget.is_initial %} {% if widget.is_initial %}
{% if not widget.required %} <em class="right">{% trans "Download" %}: <a href="{{ widget.value.url }}">{{ widget.value.url }}</a></em>
<p> <p>
{% if not widget.required %}
<label> <label>
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}" {% if widget.attrs.disabled %}disabled{% endif %}> <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}" {% if widget.attrs.disabled %}disabled{% endif %}>
<span>{{ widget.clear_checkbox_label }}</span> <span>{{ widget.clear_checkbox_label }}</span>
</label> </label>
{% endif %}
</p> </p>
{% endif %} {% endif %}
{% endif %}

Loading…
Cancel
Save