Browse Source

Sistema de avisos

pull/159/head
Sesostris Vieira 2 years ago
parent
commit
a239d841bf
  1. 18
      sigi/apps/home/templates/home/openmap.html
  2. 12
      sigi/apps/utils/admin.py
  3. 2
      sigi/apps/utils/apps.py
  4. 53
      sigi/apps/utils/middleware.py
  5. 30
      sigi/apps/utils/migrations/0001_initial.py
  6. 0
      sigi/apps/utils/migrations/__init__.py
  7. 28
      sigi/apps/utils/models.py
  8. 90
      sigi/apps/utils/templates/sigialerts/alert_snippet.html
  9. 2
      sigi/menu_conf.yaml
  10. 1
      sigi/settings.py

18
sigi/apps/home/templates/home/openmap.html

@ -50,20 +50,6 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div id="aviso" class="modal">
<div class="modal-content">
<h5>{% trans "Solicite seu ACT ao Interlegis!" %}</h5>
<p>{% trans "Para utilizar os produtos e serviços do Interlgis / Senado Federal, é necessário formalizar um Acordo de Cooperação Técnica - ACT" %}</p>
<p>{% trans "O ACT é o instrumento público que permite que as Casas Legislativas utilizem, sem nenhum custo, os produtos e serviços do Programa Interlegis / Senado Federal, como o domínio .LEG.br, Portal Modelo, Sistema de Automação do Processo Legislativo (SAPL), e-mail legislativo e e-Democracia." %}</p>
<p>{% trans "Agora ficou muito mais fácil solicitar o ACT! Basta clicar no link 'Solicitar convênio', preencher os formulários e aguardar a conclusão do Processo Administrativo." %}</p>
<p>{% trans "Junte-se à maior comunidade brasileira do legislativo, modernize sua Casa e propicie que o cidadão acompanhe e participe das atividades polícitas de sua Câmara!" %}</p>
</div>
<div class="modal-footer">
<a href="{% url 'ocorrencias-seleciona-casa' %}" class="modal-close waves-effect btn-flat">{% trans "Quero conveniar minha Casa!" %}</a>
<a href="#!" class="modal-close waves-effect btn-flat right">{% trans "Close" %}</a>
</div>
</div>
<div id="map"> <div id="map">
<!-- open street map --> <!-- open street map -->
</div> </div>
@ -80,10 +66,6 @@
var options = { color: 'blue', fillColor: 'red', fillOpacity: 0.4, radius: 500 }; var options = { color: 'blue', fillColor: 'red', fillOpacity: 0.4, radius: 500 };
var unfiltred_options = { color: 'red', fillColor: 'red', fillOpacity: 0, radius: 1000 }; var unfiltred_options = { color: 'red', fillColor: 'red', fillOpacity: 0, radius: 1000 };
$(document).ready(function () { $(document).ready(function () {
var aviso = M.Modal.init($('#aviso'));
aviso[0].open();
$("input[type=checkbox]").change(filtra); $("input[type=checkbox]").change(filtra);
mymap = L.map('map', { zoomSnap: 0.01 }).setView(map_center, 4.5); mymap = L.map('map', { zoomSnap: 0.01 }).setView(map_center, 4.5);

12
sigi/apps/utils/admin.py

@ -0,0 +1,12 @@
from django.contrib import admin
from sigi.apps.utils.models import SigiAlert
from tinymce.models import HTMLField
from tinymce.widgets import AdminTinyMCE
@admin.register(SigiAlert)
class SigiAlertAdmin(admin.ModelAdmin):
list_display = ("titulo", "caminho", "destinatarios")
search_fields = ("titulo", "caminho")
formfield_overrides = {HTMLField: {"widget": AdminTinyMCE}}
list_filter = ("destinatarios",)

2
sigi/apps/utils/apps.py

@ -4,4 +4,4 @@ from django.utils.translation import gettext_lazy as _
class UtilsConfig(AppConfig): class UtilsConfig(AppConfig):
name = "sigi.apps.utils" name = "sigi.apps.utils"
verbose_name = _("utiliátios SIGI") verbose_name = _("utilitários SIGI")

53
sigi/apps/utils/middleware.py

@ -0,0 +1,53 @@
from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from sigi.apps.utils.models import SigiAlert
from django.template.loader import render_to_string
class SigiAlertsMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
if response.streaming:
return response
if (
request.method == "GET"
and response.status_code == 200
and "Content-Type" in response.headers
and "html" in response.headers["Content-Type"]
and b"</body>" in response.content
):
if hasattr(request, "user"):
user = request.user
else:
user = AnonymousUser()
destinos = ["A"]
if user.is_anonymous or not user.is_authenticated:
destinos.append("N")
if user.is_staff:
destinos.append("S")
if user.is_superuser:
destinos.append("D")
alertas = SigiAlert.objects.filter(
Q(caminho=request.path_info)
& Q(destinatarios__in=destinos)
# & Q(Q(grupos__icontains=user.groups.all()) | Q(grupo__isnull=True))
)
if len(alertas) > 0:
avisos = {}
context = {"alertas": alertas}
snippet = render_to_string(
"sigialerts/alert_snippet.html",
request=request,
context=context,
)
snippet += "</body>"
response.content = response.content.replace(
b"</body>", snippet.encode("utf-8")
)
return response

30
sigi/apps/utils/migrations/0001_initial.py

@ -0,0 +1,30 @@
# Generated by Django 4.0.6 on 2022-07-12 20:41
from django.db import migrations, models
import tinymce.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='SigiAlert',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('caminho', models.CharField(max_length=200, verbose_name='caminho da tela')),
('destinatarios', models.CharField(choices=[('A', 'Todo e qualquer usuário'), ('N', 'Usuários anônimos / não autenticados'), ('S', 'Membros da equipe Interlegis'), ('D', 'Administradores do sistema')], max_length=1, verbose_name='destinatários')),
('titulo', models.CharField(max_length=60, verbose_name='título')),
('mensagem', tinymce.models.HTMLField(verbose_name='mensagem')),
],
options={
'verbose_name': 'alerta SIGI',
'verbose_name_plural': 'alertas SIGI',
'ordering': ('caminho', 'destinatarios'),
},
),
]

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

28
sigi/apps/utils/models.py

@ -0,0 +1,28 @@
from pyexpat import model
from django.db import models
from django.contrib.auth.models import Group
from django.utils.translation import gettext as _
from tinymce.models import HTMLField
class SigiAlert(models.Model):
DESTINATARIOS_CHOICES = (
("A", _("Todo e qualquer usuário")),
("N", _("Usuários anônimos / não autenticados")),
("S", _("Membros da equipe Interlegis")),
("D", _("Administradores do sistema")),
)
caminho = models.CharField(_("caminho da tela"), max_length=200)
destinatarios = models.CharField(
_("destinatários"), max_length=1, choices=DESTINATARIOS_CHOICES
)
titulo = models.CharField(_("título"), max_length=60)
mensagem = HTMLField(_("mensagem"))
class Meta:
ordering = ("caminho", "destinatarios")
verbose_name = _("alerta SIGI")
verbose_name_plural = _("alertas SIGI")
def __str__(self):
return self.titulo

90
sigi/apps/utils/templates/sigialerts/alert_snippet.html

@ -0,0 +1,90 @@
{% load i18n %}
<style>
.carrossel {
width: 100%;
height: 100%;
min-height: 300px;
}
.carrossel .carrossel-item {
width: 100%;
height: 100%;
min-height: 300px;
}
.carrossel .carrossel-controls {
display: block;
text-align: center;
}
.carrossel .carrossel-controls .carrossel-control {
background-color: var(--body-quiet-color);
cursor: pointer;
height: 18px;
width: 18px;
margin: 0 6px;
padding: 2px;
border-radius: 50%;
display: inline-block;
font-size: 10px;
color: white;
}
.carrossel .carrossel-controls .carrossel-control.active {
background-color: var(--main-bg-color);
font-weight: 400;
}
</style>
<div class="fixed-action-btn left">
<a id="botao-info" class="btn-floating btn-medium modal-trigger green" href="#modal-info">
<i class="large material-icons">info</i>
</a>
</div>
<div id="discovery-info" class="tap-target" data-target="botao-info">
<div class="tap-target-content">
<h5>{% trans "Novidades!" %}</h5>
<p>
{% blocktranslate count counter=alertas.count|default:0 %}
Existe um aviso para você. Clique no botão para visualizar
{% plural %}
Existem {{ counter }} avisos para você. Clique no botão para visualizar
{% endblocktranslate %}
</p>
</div>
</div>
<div id="modal-info" class="modal">
<div class="modal-content">
<div class="carrossel">
{% for alerta in alertas %}
<div id="{{ alerta.titulo|slugify }}" class="carrossel-item">
<h5>{{ alerta.titulo }}</h5>
{{ alerta.mensagem|safe }}
</div>
{% endfor %}
{% if alertas.count > 1 %}
<div class="carrossel-controls">
{% for alerta in alertas %}
<div class="carrossel-control" title="{{ alerta.titulo }}" href="#{{ alerta.titulo|slugify }}">{{ forloop.counter }}</div>
{% endfor %}
</div>
{% endif %}
</div>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect btn-flat right">{% trans "Close" %}</a>
</div>
</div>
<script>
$(document).ready(function () {
M.Modal.init($("#modal-info"));
var discovery = M.TapTarget.init($("#discovery-info"));
discovery[0].open();
$(".carrossel-item").hide();
$(".carrossel-item").first().fadeIn();
$(".carrossel-control").first().addClass("active")
$(".carrossel-control").on("click", function() {
var $this = $(this);
$(".carrossel-control").removeClass("active");
$this.addClass("active");
$(".carrossel-item").hide();
$($this.attr("href")).fadeIn();
})
});
</script>

2
sigi/menu_conf.yaml

@ -8,6 +8,8 @@ admin_menu:
view_name: admin:auth_group_changelist view_name: admin:auth_group_changelist
- title: Importar Gescon - title: Importar Gescon
view_name: importar-gescon view_name: importar-gescon
- title: Avisos do sistema
view_name: admin:utils_sigialert_changelist
main_menu: main_menu:
- title: Municípios - title: Municípios

1
sigi/settings.py

@ -70,6 +70,7 @@ MIDDLEWARE = [
"django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware", "django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware",
"sigi.apps.utils.middleware.SigiAlertsMiddleware",
] ]
if DEBUG: if DEBUG:

Loading…
Cancel
Save