Browse Source

Melhorias na interface de changelist

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
d97d81e9e0
  1. 4
      sigi/apps/convenios/admin.py
  2. 36
      sigi/apps/convenios/templates/convenios/importar_gescon.html
  3. 1
      sigi/apps/convenios/urls.py
  4. 31
      sigi/apps/convenios/views.py
  5. 0
      sigi/apps/utils/templatetags/__init__.py
  6. 17
      sigi/apps/utils/templatetags/action_icons.py
  7. 11
      sigi/menu_conf.yaml
  8. 22
      sigi/templates/admin/actions.html
  9. 21
      sigi/templates/admin/change_list.html
  10. 36
      sigi/templates/admin/search_form.html
  11. 3
      sigi/templates/material/admin/side_nav.html

4
sigi/apps/convenios/admin.py

@ -222,8 +222,8 @@ class EquipamentoPrevistoAdmin(admin.ModelAdmin):
@admin.register(Gescon) @admin.register(Gescon)
class GesconAdmin(admin.ModelAdmin): class GesconAdmin(admin.ModelAdmin):
list_display = ('url_gescon', 'email', 'ultima_importacao') list_display = ('url_gescon', 'email',)
readonly_fields = ('ultima_importacao',) exclude = ['ultima_importacao',]
admin.site.register(Projeto) admin.site.register(Projeto)
admin.site.register(StatusConvenio) admin.site.register(StatusConvenio)

36
sigi/apps/convenios/templates/convenios/importar_gescon.html

@ -1,18 +1,42 @@
{% extends 'admin/base_site.html' %} {% extends 'admin/base_site.html' %}
{% load i18n %} {% load i18n %}
{% block content_title %}<h1>{% trans 'Importar dados do Gescon' %}</h1>{% endblock %} {% block breadcrumbs %}
{% block object-tools-items %} <div class="breadcrumbs">
<li class="nav-item"><a class="nav-link active" href="{% url 'importar-gescon' %}?action=importar">Importar</a></li> <h6>{% trans 'Importar dados do Gescon' %}</h6>
<li class="nav-item"><a class="nav-link" href="{% url 'admin:convenios_gescon_change' gescon.id %}">Configurações</a></li> </div>
{% endblock %} {% endblock %}
{% block object-tools-items %}{% endblock %}
{% block content %} {% block content %}
<div class="module filtered" id="changelist">
<p class="paginator"></p>
<ul class="pagination">
<li class="active">
<a href="{% url 'importar-gescon' %}?action=importar">
<i class="material-icons left">cloud_download</i>
{% trans "Importar" %}
</a>
</li>
<li class="active">
<a href="{% url 'admin:convenios_gescon_change' gescon.id %}">
<i class="material-icons left">perm_data_setting</i>
{% trans "Configurações" %}
</a>
</li>
</ul>
{% if gescon.ultima_importacao %} {% if gescon.ultima_importacao %}
<blockquote>
<pre><code>{{ gescon.ultima_importacao }}</code></pre> <pre><code>{{ gescon.ultima_importacao }}</code></pre>
</blockquote>
{% else %} {% else %}
{% blocktrans %} {% blocktrans %}
<p class="alert alert-danger"><strong>Nenhuma importação anterior foi realizada!</strong></p> <blockquote>
<p class="">Configure a conexão com o Gescon para realizar a primeira importação.</p> <p><strong>Nenhuma importação anterior foi realizada!</strong></p>
<p>Configure a conexão com o Gescon para realizar a primeira importação.</p>
</blockquote>
{% endblocktrans %} {% endblocktrans %}
{% endif %} {% endif %}
</div>
{% endblock %} {% endblock %}

1
sigi/apps/convenios/urls.py

@ -3,6 +3,7 @@ from sigi.apps.convenios import views
urlpatterns = [ urlpatterns = [
path('reportsRegiao/<str:regiao>/', views.report_regiao, name='convenios-report_regiao_pdf'), path('reportsRegiao/<str:regiao>/', views.report_regiao, name='convenios-report_regiao_pdf'),
path('importar/', views.importar_gescon, name='importar-gescon'),
] ]
# urlpatterns = patterns( # urlpatterns = patterns(

31
sigi/apps/convenios/views.py

@ -2,7 +2,8 @@ import csv
import datetime import datetime
# from django.contrib import messages # 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.conf import settings
# from django.core.paginator import Paginator, InvalidPage, EmptyPage # from django.core.paginator import Paginator, InvalidPage, EmptyPage
# from django.http import HttpResponse, HttpResponseRedirect # from django.http import HttpResponse, HttpResponseRedirect
@ -129,6 +130,22 @@ def casas_estado_to_tabela(casas, convenios, regiao):
"sumario": sumario, "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 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})
""" """

0
sigi/apps/utils/templatetags/__init__.py

17
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"

11
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: main_menu:
- title: Municípios - title: Municípios
icon: location_city icon: location_city

22
sigi/templates/admin/actions.html

@ -1,23 +1,21 @@
{% load i18n %} {% load i18n action_icons %}
<div class="actions"> <div class="actions">
{% block actions %} {% block actions %}
<div class="card-content">
{% block actions-form %} {% block actions-form %}
<input type="hidden" form="changelist-form" name="index" value="{{ action_index|default:0 }}"/>
{% for field in action_form %} {% for field in action_form %}
{% if field.label %}
<label class="label">{{ field.label }}
{% endif %}
{% if field.field.widget.choices %} {% if field.field.widget.choices %}
<select form="changelist-form" name="action" required tabindex="-1">
{% for option in field.field.widget.choices %} {% for option in field.field.widget.choices %}
<option value="{{ option.0 }}">{{ option.1 }}</option> {% if option.0 != "" %}
<button type="submit" form="changelist-form" class="waves-effect waves-light btn action-button" title="{{ option.1 }}" name="action" value="{{ option.0 }}">
<i class="material-icons">{% action_icon option.0 %}</i>
</button>
{% endif %}
{% endfor %} {% endfor %}
</select>
{% else %} {% else %}
<input type="hidden" name="{{ field.name }}" value="{{ field.value }}" class="select-across" form="changelist-form"/> <input type="hidden" name="{{ field.name }}" value="{{ field.value }}" class="select-across" form="changelist-form"/>
{% endif %} {% endif %}
{% if field.label %}</label>{% endif %}
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
{% block actions-submit %} {% block actions-submit %}
@ -33,12 +31,6 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
</div>
<div class="card-action">
<div class="right-align">
<button type="submit" form="changelist-form" class="waves-effect waves-light btn action-button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button>
</div>
</div>
{% endblock %} {% endblock %}
{% endblock %} {% endblock %}
</div> </div>

21
sigi/templates/admin/change_list.html

@ -8,6 +8,18 @@
<link rel="stylesheet" type="text/css" href="{% static 'css/changelists.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'css/changelists.css' %}">
{% endblock %} {% endblock %}
{% block breadcrumbs %}
{% block search %}{% search_form cl %}{% endblock %}
<form id="changelist-form" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
<div class="breadcrumbs">
<div id="changelist-form">
{% if action_form and actions_on_top and cl.show_admin_actions %}
{% admin_actions %}
{% endif %}
</div>
</div>
{% endblock %}
{% block content %} {% block content %}
<div id="content-main" class="list-content"> <div id="content-main" class="list-content">
{% block object-tools %} {% block object-tools %}
@ -44,7 +56,6 @@
{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %} {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
<form id="changelist-form" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
{% if cl.formset %} {% if cl.formset %}
<div>{{ cl.formset.management_form }}</div> <div>{{ cl.formset.management_form }}</div>
{% endif %} {% endif %}
@ -54,17 +65,10 @@
{% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %} {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %}
{% endblock %} {% endblock %}
{% block pagination %}{% pagination cl %}{% endblock %} {% block pagination %}{% pagination cl %}{% endblock %}
</form>
</div> </div>
{% block side_wrapper %} {% block side_wrapper %}
<div id="float-filter" class="float-filter hide"> <div id="float-filter" class="float-filter hide">
<div id="side-wrapper" class="side-wrapper"> <div id="side-wrapper" class="side-wrapper">
<div id="changelist-form" class="card">
{% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %}
</div>
<div class="card">
{% block search %}{% search_form cl %}{% endblock %}
</div>
<div class="card"> <div class="card">
{% block filters %} {% block filters %}
{{ block.super }} {{ block.super }}
@ -78,6 +82,7 @@
{% endblock %} {% endblock %}
{% block footer %} {% block footer %}
</form>
{{ block.super }} {{ block.super }}
<script> <script>
$(document).ready(function(){ $(document).ready(function(){

36
sigi/templates/admin/search_form.html

@ -0,0 +1,36 @@
{% load i18n static %}
{% block extrastyle %}
<link href="{% static 'material/admin/css/search_form.min.css' %}" rel="stylesheet">
{% endblock %}
{% if cl.search_fields %}
<form id="changelist-search" method="get">
<div class="input-field col s6">
<input id="icon_prefix" class="validate" type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}">
<label for="icon_prefix">{% trans 'Search' %} {{ cl.opts.verbose_name }}</label>
<button class="search-cta" type="submit"><i class="material-icons" aria-hidden="true">search</i></button>
{% if show_result_count %}
<span class="small quiet">
{% blocktrans count counter=cl.result_count %}{{ counter }}
result{% plural %}{{ counter }} results
{% endblocktrans %}
(<a href="?{% if cl.is_popup %}_popup=1{% endif %}">
{% if cl.show_full_result_count %}
{% blocktrans with full_result_count=cl.full_result_count %}
{{ full_result_count }} total
{% endblocktrans %}
{% else %}
{% trans "Show all" %}
{% endif %}
</a>)
</span>
{% endif %}
{% for pair in cl.params.items %}
{% if pair.0 != search_var %}
<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}">
{% endif %}
{% endfor %}
</div>
</form>
{% endif %}

3
sigi/templates/material/admin/side_nav.html

@ -16,6 +16,9 @@
</div> </div>
</div> </div>
</li> </li>
{% if user.is_superuser %}
{% show_menu 'admin_menu' %}
{% endif %}
{% show_menu 'main_menu' %} {% show_menu 'main_menu' %}
</ul> </ul>
</div> </div>

Loading…
Cancel
Save