Browse Source

Novas funcionalidades listview de municípios. Gertiq #168126

pull/169/head
Sesóstris Vieira 1 year ago
parent
commit
b945d4bc73
  1. 1
      requirements/requirements.txt
  2. 5
      sigi/apps/casas/admin.py
  3. 29
      sigi/apps/contatos/admin.py
  4. 10
      sigi/apps/convenios/admin.py
  5. 5
      sigi/apps/eventos/admin.py
  6. 12
      sigi/apps/utils/__init__.py
  7. 15
      sigi/apps/utils/mixins.py
  8. 1
      sigi/settings.py
  9. 12
      sigi/static/material/admin/js/filters.js
  10. 10
      sigi/templates/admin/change_list.html
  11. 9
      sigi/templates/django-admin-autocomplete-filter/autocomplete-filter.html

1
requirements/requirements.txt

@ -15,6 +15,7 @@ uritemplate==4.1.1
weasyprint==58.0
XlsxWriter==3.1.2
Django==4.2.7
django-admin-autocomplete-filter==0.7.1
django-auth-ldap==4.3.0
django-debug-toolbar==4.1.0
django-environ==0.10.0

5
sigi/apps/casas/admin.py

@ -24,7 +24,7 @@ from sigi.apps.parlamentares.models import Parlamentar
from sigi.apps.servicos.models import Servico
from sigi.apps.servicos.filters import ServicoAtivoFilter
from sigi.apps.servidores.models import Servidor
from sigi.apps.utils import asciify_q_param
from sigi.apps.utils.mixins import AsciifyQParameter
from sigi.apps.utils.mixins import (
ReturnMixin,
CartExportReportMixin,
@ -329,7 +329,7 @@ class FuncionarioAdmin(ReturnMixin, admin.ModelAdmin):
@admin.register(Orgao)
class OrgaoAdmin(CartExportReportMixin, admin.ModelAdmin):
class OrgaoAdmin(AsciifyQParameter, CartExportReportMixin, admin.ModelAdmin):
form = OrgaoForm
resource_classes = [OrgaoExportResourseGeral, OrgaoExportResourceContato]
inlines = (
@ -446,7 +446,6 @@ class OrgaoAdmin(CartExportReportMixin, admin.ModelAdmin):
]
def get_queryset(self, request):
asciify_q_param(request)
queryset = super().get_queryset(request)
return queryset.prefetch_related("gerentes_interlegis", "convenio_set")

29
sigi/apps/contatos/admin.py

@ -1,6 +1,6 @@
from admin_auto_filters.filters import AutocompleteFilter
from django.contrib import admin
from django.utils.translation import gettext as _
from sigi.apps.utils.filters import RangeFilter
from sigi.apps.contatos.models import (
UnidadeFederativa,
@ -11,7 +11,7 @@ from sigi.apps.contatos.models import (
Contato,
)
from sigi.apps.parlamentares.models import Senador
from sigi.apps.utils import queryset_ascii
from sigi.apps.utils.mixins import AsciifyQParameter
from sigi.apps.utils.mixins import (
ReturnMixin,
CartExportMixin,
@ -19,6 +19,11 @@ from sigi.apps.utils.mixins import (
)
class MicrorregiaoFilter(AutocompleteFilter):
title = _("Microrregião")
field_name = "microrregiao"
class UnidadeFederativaResource(LabeledResourse):
class Meta:
model = UnidadeFederativa
@ -75,7 +80,9 @@ class SenadorInline(admin.StackedInline):
@admin.register(UnidadeFederativa)
class UnidadeFederativaAdmin(CartExportMixin, admin.ModelAdmin):
class UnidadeFederativaAdmin(
AsciifyQParameter, CartExportMixin, admin.ModelAdmin
):
actions = None
resource_classes = [UnidadeFederativaResource]
list_display = ("codigo_ibge", "nome", "sigla", "regiao", "populacao")
@ -85,12 +92,11 @@ class UnidadeFederativaAdmin(CartExportMixin, admin.ModelAdmin):
("populacao", RangeFilter),
)
search_fields = ("search_text", "codigo_ibge", "sigla", "regiao")
get_queryset = queryset_ascii
inlines = (SenadorInline, MesorregiaoInline)
@admin.register(Mesorregiao)
class MesorregiaoAdmin(admin.ModelAdmin):
class MesorregiaoAdmin(AsciifyQParameter, admin.ModelAdmin):
actions = None
list_display = ("codigo_ibge", "uf", "nome")
list_display_links = ("codigo_ibge", "nome")
@ -102,17 +108,16 @@ class MesorregiaoAdmin(admin.ModelAdmin):
"uf__sigla",
)
autocomplete_fields = ("uf",)
get_queryset = queryset_ascii
inlines = (MicrorregiaoInline,)
@admin.register(Microrregiao)
class MicrorregiaoAdmin(admin.ModelAdmin):
class MicrorregiaoAdmin(AsciifyQParameter, admin.ModelAdmin):
search_fields = ("search_text",)
@admin.register(Municipio)
class MunicipioAdmin(CartExportMixin, admin.ModelAdmin):
class MunicipioAdmin(AsciifyQParameter, CartExportMixin, admin.ModelAdmin):
actions = None
resource_classes = [MunicipioResource]
list_display = (
@ -120,6 +125,8 @@ class MunicipioAdmin(CartExportMixin, admin.ModelAdmin):
"codigo_tse",
"nome",
"uf",
"get_regiao",
"microrregiao",
"is_capital",
"populacao",
"is_polo",
@ -136,8 +143,8 @@ class MunicipioAdmin(CartExportMixin, admin.ModelAdmin):
("populacao", RangeFilter),
"uf__regiao",
"uf",
MicrorregiaoFilter,
)
get_queryset = queryset_ascii
fieldsets = (
(
None,
@ -169,6 +176,10 @@ class MunicipioAdmin(CartExportMixin, admin.ModelAdmin):
autocomplete_fields = ("uf", "microrregiao")
search_fields = ("search_text", "codigo_ibge", "codigo_tse", "uf__sigla")
@admin.display(description=_("Região"), ordering="uf__regiao")
def get_regiao(self, obj):
return obj.uf.get_regiao_display()
@admin.register(Telefone)
class TelefoneAdmin(admin.ModelAdmin):

10
sigi/apps/convenios/admin.py

@ -17,7 +17,7 @@ from sigi.apps.convenios.models import (
Tramitacao,
Gescon,
)
from sigi.apps.utils import queryset_ascii, asciify_q_param
from sigi.apps.utils.mixins import AsciifyQParameter
from sigi.apps.servidores.models import Servidor
from sigi.apps.casas.admin import ConveniosInline, GerentesInterlegisFilter
from sigi.apps.utils.mixins import (
@ -114,7 +114,9 @@ class ProjetoAdmin(admin.ModelAdmin):
@admin.register(Convenio)
class ConvenioAdmin(ReturnMixin, CartExportReportMixin, admin.ModelAdmin):
class ConvenioAdmin(
AsciifyQParameter, ReturnMixin, CartExportReportMixin, admin.ModelAdmin
):
fieldsets = (
(
None,
@ -286,10 +288,6 @@ class ConvenioAdmin(ReturnMixin, CartExportReportMixin, admin.ModelAdmin):
del actions["delete_selected"]
return actions
def get_queryset(self, request):
asciify_q_param(request)
return super().get_queryset(request)
@admin.register(EquipamentoPrevisto)
class EquipamentoPrevistoAdmin(admin.ModelAdmin):

5
sigi/apps/eventos/admin.py

@ -57,6 +57,7 @@ from sigi.apps.servidores.models import Servidor
from sigi.apps.utils import abreviatura
from sigi.apps.utils.filters import DateRangeFilter
from sigi.apps.utils.mixins import (
AsciifyQParameter,
CartExportMixin,
CartExportReportMixin,
LabeledResourse,
@ -381,7 +382,7 @@ class TipoEventoAdmin(admin.ModelAdmin):
@admin.register(Solicitacao)
class SolicitacaoAdmin(CartExportMixin, admin.ModelAdmin):
class SolicitacaoAdmin(AsciifyQParameter, CartExportMixin, admin.ModelAdmin):
resource_class = SolicitacaoResource
list_display = (
"casa",
@ -851,7 +852,7 @@ class ModeloDeclaracaoAdmin(admin.ModelAdmin):
@admin.register(Evento)
class EventoAdmin(CartExportReportMixin, admin.ModelAdmin):
class EventoAdmin(AsciifyQParameter, CartExportReportMixin, admin.ModelAdmin):
form = EventoAdminForm
resource_class = EventoResource
fieldsets = (

12
sigi/apps/utils/__init__.py

@ -39,18 +39,6 @@ def to_ascii(txt, codif="utf-8"):
)
def asciify_q_param(request):
if "q" in request.GET:
request.GET._mutable = True
request.GET["q"] = to_ascii(request.GET["q"])
request.GET._mutable = False
def queryset_ascii(self, request):
asciify_q_param(request)
return django_admin.ModelAdmin.get_queryset(self, request)
def field_label(name, model):
name = name.split("__")
try:

15
sigi/apps/utils/mixins.py

@ -16,7 +16,7 @@ from import_export.admin import ImportMixin, ExportMixin
from import_export.fields import Field
from import_export.forms import ExportForm
from import_export.signals import post_export
from sigi.apps.utils import field_label
from sigi.apps.utils import field_label, to_ascii
class ValueField(Field):
@ -100,7 +100,7 @@ class CartExportMixin(ExportMixin):
qs = super().get_queryset(request)
if self._cart_viewing_name in request.session:
ids = request.session.get(self._cart_session_name, [])
qs = qs.filter(id__in=ids)
qs = qs.filter(pk__in=ids)
return qs
def get_actions(self, request):
@ -307,3 +307,14 @@ class ReturnMixin:
if self._return_path:
return HttpResponseRedirect(self._return_path)
return response
class AsciifyQParameter:
def asciify_q_param(self, request):
if "q" in request.GET:
request.GET._mutable = True
request.GET["q"] = to_ascii(request.GET["q"])
request.GET._mutable = False
def get_queryset(self, request):
self.asciify_q_param(request)
return super().get_queryset(request)

1
sigi/settings.py

@ -60,6 +60,7 @@ INSTALLED_APPS = [
"rest_framework",
"material",
"material.admin",
"admin_auto_filters",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",

12
sigi/static/material/admin/js/filters.js

@ -3,6 +3,7 @@ $("#apply-filters").on("click", function () {
var retorno = decodeURIComponent(window.location.search).replace("?", "").split("&");
var remove = [];
var filters = $(".admin_filter");
var dal_filters = $("[id$=dal-filter]")
for (i = 0; i < filters.length; i++) {
var element = $(filters[i]);
var filter;
@ -20,6 +21,17 @@ $("#apply-filters").on("click", function () {
remove = remove.concat(retorno.filter(x => !filter.includes(x)));
query = query.concat(filter.filter(x => !retorno.includes(x)));
}
for (i = 0; i < dal_filters.length; i++) {
var element = $(dal_filters[i]);
var filter = [];
if (element.val() != "") {
filter = [element.serialize()];
}
remove = remove.concat(retorno.filter(x => x.includes(element.attr("name"))));
query = query.concat(filter);
}
query = query.concat(retorno.filter(x => !remove.includes(x)));
query = query.filter(x => x != "");
window.location.href = "?" + (query.join("&"));

10
sigi/templates/admin/change_list.html

@ -100,15 +100,7 @@
$(document).ready(function(){
$('.fixed-action-btn').floatingActionButton();
M.Tooltip.init($('.tooltipped'), {});
document.addEventListener('DOMContentLoaded', function() {
M.Modal.init($(".modal"), {});
});
// Or with jQuery
$(document).ready(function(){
$('.modal').modal();
});
M.Modal.init($(".modal"), {dismissible: false});
});
</script>
{% endblock footer %}

9
sigi/templates/django-admin-autocomplete-filter/autocomplete-filter.html

@ -0,0 +1,9 @@
{% load i18n %}
<div class="col s12">
<label>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</label>
<div class="related-wrapper">
{{ spec.rendered_widget }}
{{ spec.field }}
</div>
</div>
Loading…
Cancel
Save