Browse Source

Melhorias na interface de changelist

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
d97d81e9e0
  1. 6
      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. 52
      sigi/templates/admin/actions.html
  9. 34
      sigi/templates/admin/base_site.html
  10. 21
      sigi/templates/admin/change_list.html
  11. 36
      sigi/templates/admin/search_form.html
  12. 3
      sigi/templates/material/admin/side_nav.html

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

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

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

1
sigi/apps/convenios/urls.py

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

31
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})
"""

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

52
sigi/templates/admin/actions.html

@ -1,44 +1,36 @@
{% load i18n %}
{% load i18n action_icons %}
<div class="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 %}
{% if field.label %}
<label class="label">{{ field.label }}
{% if field.field.widget.choices %}
{% for option in field.field.widget.choices %}
{% 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 %}
{% else %}
<input type="hidden" name="{{ field.name }}" value="{{ field.value }}" class="select-across" form="changelist-form"/>
{% endif %}
{% if field.field.widget.choices %}
<select form="changelist-form" name="action" required tabindex="-1">
{% for option in field.field.widget.choices %}
<option value="{{ option.0 }}">{{ option.1 }}</option>
{% endfor %}
</select>
{% else %}
<input type="hidden" name="{{ field.name }}" value="{{ field.value }}" class="select-across" form="changelist-form"/>
{% endif %}
{% if field.label %}</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 %}
<span class="action-counter" data-actions-icnt="{{ cl.result_list|length }}">{{ selection_note }}</span>
{% if cl.result_count != cl.result_list|length %}
<span class="all">{{ selection_note_all }}</span>
<span class="question">
<span class="all">{{ selection_note_all }}</span>
<span class="question">
<a href="#" title="{% trans "Click here to select the objects across all pages" %}">{% blocktrans with cl.result_count as total_count %}Select all {{ total_count }} {{ module_name }}{% endblocktrans %}</a>
</span>
<span class="clear"><a href="#">{% trans "Clear selection" %}</a></span>
</span>
<span class="clear"><a href="#">{% trans "Clear selection" %}</a></span>
{% endif %}
{% endif %}
{% endif %}
{% 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 %}
</div>

34
sigi/templates/admin/base_site.html

@ -7,23 +7,23 @@
{% endblock %}
{% block userlinks %}
{% block welcome-msg %}{% endblock %}
{% if site_url %}
<a href="{{ site_url }}">{% trans 'Mapa' %}</a>
{% block welcome-msg %}{% endblock %}
{% if site_url %}
<a href="{{ site_url }}">{% trans 'Mapa' %}</a>
{% endif %}
{% if user.is_active and user.is_staff %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}
<a href="{{ docsroot }}">{% trans 'Documentation' %}</a>
{% endif %}
{% if user.is_active and user.is_staff %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}
<a href="{{ docsroot }}">{% trans 'Documentation' %}</a>
{% endif %}
{% endif %}
{% if user.has_usable_password %}
<a href="{% url 'admin:password_change' %}">
{% trans 'Change password' %}
</a>
{% endif %}
<a href="{% url 'admin:logout' %}">
{% trans 'Log out' %}
<i class="material-icons" aria-hidden="true">exit_to_app</i>
{% endif %}
{% if user.has_usable_password %}
<a href="{% url 'admin:password_change' %}">
{% trans 'Change password' %}
</a>
{% endif %}
<a href="{% url 'admin:logout' %}">
{% trans 'Log out' %}
<i class="material-icons" aria-hidden="true">exit_to_app</i>
</a>
{% endblock %}

21
sigi/templates/admin/change_list.html

@ -8,6 +8,18 @@
<link rel="stylesheet" type="text/css" href="{% static 'css/changelists.css' %}">
{% 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 %}
<div id="content-main" class="list-content">
{% block object-tools %}
@ -44,7 +56,6 @@
{% 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 %}
<div>{{ cl.formset.management_form }}</div>
{% 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 %}
</form>
</div>
{% block side_wrapper %}
<div id="float-filter" class="float-filter hide">
<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">
{% block filters %}
{{ block.super }}
@ -78,6 +82,7 @@
{% endblock %}
{% block footer %}
</form>
{{ block.super }}
<script>
$(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>
</li>
{% if user.is_superuser %}
{% show_menu 'admin_menu' %}
{% endif %}
{% show_menu 'main_menu' %}
</ul>
</div>

Loading…
Cancel
Save