From d97d81e9e0a0dd43059cfbda28555d0eddb2ada9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Sun, 17 Apr 2022 18:52:34 -0300 Subject: [PATCH] Melhorias na interface de changelist --- sigi/apps/convenios/admin.py | 6 +-- .../templates/convenios/importar_gescon.html | 36 ++++++++++--- sigi/apps/convenios/urls.py | 1 + sigi/apps/convenios/views.py | 31 ++++++----- sigi/apps/utils/templatetags/__init__.py | 0 sigi/apps/utils/templatetags/action_icons.py | 17 ++++++ sigi/menu_conf.yaml | 11 ++++ sigi/templates/admin/actions.html | 52 ++++++++----------- sigi/templates/admin/base_site.html | 34 ++++++------ sigi/templates/admin/change_list.html | 21 +++++--- sigi/templates/admin/search_form.html | 36 +++++++++++++ sigi/templates/material/admin/side_nav.html | 3 ++ 12 files changed, 171 insertions(+), 77 deletions(-) create mode 100644 sigi/apps/utils/templatetags/__init__.py create mode 100644 sigi/apps/utils/templatetags/action_icons.py create mode 100644 sigi/templates/admin/search_form.html diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 5800869..b2c34fd 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -94,7 +94,7 @@ class ConvenioAdmin(CartExportReportMixin, admin.ModelAdmin): 'report_convenios_camaras', 'report_convenios_assembleia', ] - + def get_queryset(self, request): queryset = super(ConvenioAdmin, self).get_queryset(request) print (queryset) @@ -222,8 +222,8 @@ class EquipamentoPrevistoAdmin(admin.ModelAdmin): @admin.register(Gescon) class GesconAdmin(admin.ModelAdmin): - list_display = ('url_gescon', 'email', 'ultima_importacao') - readonly_fields = ('ultima_importacao',) + list_display = ('url_gescon', 'email',) + exclude = ['ultima_importacao',] admin.site.register(Projeto) admin.site.register(StatusConvenio) diff --git a/sigi/apps/convenios/templates/convenios/importar_gescon.html b/sigi/apps/convenios/templates/convenios/importar_gescon.html index 49f068a..3e8c4d7 100644 --- a/sigi/apps/convenios/templates/convenios/importar_gescon.html +++ b/sigi/apps/convenios/templates/convenios/importar_gescon.html @@ -1,18 +1,42 @@ {% extends 'admin/base_site.html' %} {% load i18n %} -{% block content_title %}

{% trans 'Importar dados do Gescon' %}

{% endblock %} -{% block object-tools-items %} - - +{% block breadcrumbs %} + {% endblock %} + +{% block object-tools-items %}{% endblock %} + {% block content %} +
+

+ {% if gescon.ultima_importacao %} +
{{ gescon.ultima_importacao }}
+
{% else %} {% blocktrans %} -

Nenhuma importação anterior foi realizada!

-

Configure a conexão com o Gescon para realizar a primeira importação.

+
+

Nenhuma importação anterior foi realizada!

+

Configure a conexão com o Gescon para realizar a primeira importação.

+
{% endblocktrans %} {% endif %} +
{% endblock %} \ No newline at end of file diff --git a/sigi/apps/convenios/urls.py b/sigi/apps/convenios/urls.py index fe7369f..cfb8f55 100644 --- a/sigi/apps/convenios/urls.py +++ b/sigi/apps/convenios/urls.py @@ -3,6 +3,7 @@ from sigi.apps.convenios import views urlpatterns = [ path('reportsRegiao//', views.report_regiao, name='convenios-report_regiao_pdf'), + path('importar/', views.importar_gescon, name='importar-gescon'), ] # urlpatterns = patterns( diff --git a/sigi/apps/convenios/views.py b/sigi/apps/convenios/views.py index 4f03c46..817e43c 100644 --- a/sigi/apps/convenios/views.py +++ b/sigi/apps/convenios/views.py @@ -2,7 +2,8 @@ import csv import datetime # from django.contrib import messages -# from django.http.response import HttpResponseForbidden +from django.contrib import admin +from django.http.response import HttpResponseForbidden # from django.conf import settings # from django.core.paginator import Paginator, InvalidPage, EmptyPage # from django.http import HttpResponse, HttpResponseRedirect @@ -129,6 +130,22 @@ def casas_estado_to_tabela(casas, convenios, regiao): "sumario": sumario, } +@login_required +def importar_gescon(request): + if not request.user.is_superuser: + return HttpResponseForbidden() + + context = admin.site.each_context(request) + + action = request.GET.get('action', "") + gescon = Gescon.load() + + if action == 'importar': + gescon.importa_contratos() + + context['gescon'] = gescon + + return render(request, "convenios/importar_gescon.html", context) @@ -381,16 +398,4 @@ def export_csv(request): return response -@login_required -def importar_gescon(request): - if not request.user.is_superuser: - return HttpResponseForbidden() - - action = request.GET.get('action', "") - gescon = Gescon.load() - - if action == 'importar': - gescon.importa_contratos() - - return render(request, "convenios/importar_gescon.html", {'gescon': gescon}) """ \ No newline at end of file diff --git a/sigi/apps/utils/templatetags/__init__.py b/sigi/apps/utils/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/utils/templatetags/action_icons.py b/sigi/apps/utils/templatetags/action_icons.py new file mode 100644 index 0000000..5d46a3e --- /dev/null +++ b/sigi/apps/utils/templatetags/action_icons.py @@ -0,0 +1,17 @@ +from django import template + +register = template.Library() + +ACTION_LIST = { + 'delete_selected': 'delete_forever', + 'add_to_cart': 'add_shopping_cart', + 'remove_from_cart': 'remove_shopping_cart', + 'calcular_data_uso': 'functions', +} + +@register.simple_tag +def action_icon(action_name): + if action_name in ACTION_LIST: + return ACTION_LIST[action_name] + else: + return "play_arrow" diff --git a/sigi/menu_conf.yaml b/sigi/menu_conf.yaml index 4a2b1e4..6fba376 100644 --- a/sigi/menu_conf.yaml +++ b/sigi/menu_conf.yaml @@ -1,3 +1,14 @@ +admin_menu: + - title: Superusuários + icon: settings + children: + - title: Usuários + view_name: admin:auth_user_changelist + - title: Grupos + view_name: admin:auth_group_changelist + - title: Importar Gescon + view_name: importar-gescon + main_menu: - title: Municípios icon: location_city diff --git a/sigi/templates/admin/actions.html b/sigi/templates/admin/actions.html index 922dc31..df6ee7a 100644 --- a/sigi/templates/admin/actions.html +++ b/sigi/templates/admin/actions.html @@ -1,44 +1,36 @@ -{% load i18n %} +{% load i18n action_icons %}
{% block actions %} -
- {% block actions-form %} + {% block actions-form %} + {% for field in action_form %} - {% if field.label %} - {% endif %} {% endfor %} - {% endblock %} - {% block actions-submit %} - {% block actions-counter %} - {% if actions_selection_counter %} + {% endblock %} + {% block actions-submit %} + {% block actions-counter %} + {% if actions_selection_counter %} {{ selection_note }} {% if cl.result_count != cl.result_list|length %} - {{ selection_note_all }} - + {{ selection_note_all }} + {% blocktrans with cl.result_count as total_count %}Select all {{ total_count }} {{ module_name }}{% endblocktrans %} - - {% trans "Clear selection" %} + + {% trans "Clear selection" %} {% endif %} - {% endif %} + {% endif %} {% endblock %} -
-
-
- -
-
{% endblock %} {% endblock %}
\ No newline at end of file diff --git a/sigi/templates/admin/base_site.html b/sigi/templates/admin/base_site.html index cef458d..4d46193 100644 --- a/sigi/templates/admin/base_site.html +++ b/sigi/templates/admin/base_site.html @@ -7,23 +7,23 @@ {% endblock %} {% block userlinks %} - {% block welcome-msg %}{% endblock %} - {% if site_url %} - {% trans 'Mapa' %} + {% block welcome-msg %}{% endblock %} + {% if site_url %} + {% trans 'Mapa' %} + {% endif %} + {% if user.is_active and user.is_staff %} + {% url 'django-admindocs-docroot' as docsroot %} + {% if docsroot %} + {% trans 'Documentation' %} {% endif %} - {% if user.is_active and user.is_staff %} - {% url 'django-admindocs-docroot' as docsroot %} - {% if docsroot %} - {% trans 'Documentation' %} - {% endif %} - {% endif %} - {% if user.has_usable_password %} - - {% trans 'Change password' %} - - {% endif %} - - {% trans 'Log out' %} - + {% endif %} + {% if user.has_usable_password %} + + {% trans 'Change password' %} + {% endif %} + + {% trans 'Log out' %} + + {% endblock %} \ No newline at end of file diff --git a/sigi/templates/admin/change_list.html b/sigi/templates/admin/change_list.html index 6a0cdca..ae3b77f 100644 --- a/sigi/templates/admin/change_list.html +++ b/sigi/templates/admin/change_list.html @@ -8,6 +8,18 @@ {% endblock %} +{% block breadcrumbs %} + {% block search %}{% search_form cl %}{% endblock %} +
{% csrf_token %} + +{% endblock %} + {% block content %}
{% block object-tools %} @@ -44,7 +56,6 @@ {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} - {% csrf_token %} {% if cl.formset %}
{{ cl.formset.management_form }}
{% endif %} @@ -54,17 +65,10 @@ {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %} {% endblock %} {% block pagination %}{% pagination cl %}{% endblock %} -
{% block side_wrapper %}
-
- {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %} -
-
- {% block search %}{% search_form cl %}{% endblock %} -
{% block filters %} {{ block.super }} @@ -78,6 +82,7 @@ {% endblock %} {% block footer %} + {{ block.super }}