Browse Source

Implementando a autenticação do usuário para acessar o diagnóstico, como também filtrar os registros a partir do status e se as mesmas são do servidor logado.

diagnosticos
Gilson Filho 13 years ago
parent
commit
9f655546c3
  1. 2
      sigi/apps/diagnosticos/admin.py
  2. 10
      sigi/apps/diagnosticos/urls.py
  3. 11
      sigi/apps/diagnosticos/views.py
  4. 1
      sigi/apps/servidores/admin.py
  5. 3
      sigi/settings.py
  6. 4
      sigi/templates/diagnosticos/diagnosticos_list.html
  7. 44
      sigi/templates/diagnosticos/diagnosticos_login.html

2
sigi/apps/diagnosticos/admin.py

@ -56,7 +56,7 @@ class DiagnosticoAdmin(BaseEntityAdmin):
date_hierarchy = 'data_questionario' date_hierarchy = 'data_questionario'
actions = [alterar_status_publicacao, alterar_status_draft] actions = [alterar_status_publicacao, alterar_status_draft]
inlines = (EquipeInline, AnexosInline) inlines = (EquipeInline, AnexosInline)
list_display = ('casa_legislativa', 'data_questionario', 'status') list_display = ('casa_legislativa', 'data_questionario', 'responsavel', 'status')
raw_id_fields = ('casa_legislativa', 'responsavel') raw_id_fields = ('casa_legislativa', 'responsavel')
eav_fieldsets = [ eav_fieldsets = [

10
sigi/apps/diagnosticos/urls.py

@ -1,10 +1,20 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
from django.conf.urls.defaults import patterns, url from django.conf.urls.defaults import patterns, url
LOGOUT_REDIRECT_URL = '/mobile/diagnosticos/login'
urlpatterns = patterns('', urlpatterns = patterns('',
# Lista de Diagnósticos # Lista de Diagnósticos
url(r'^$', 'sigi.apps.diagnosticos.views.lista', name='lista_diagnosticos'), url(r'^$', 'sigi.apps.diagnosticos.views.lista', name='lista_diagnosticos'),
# Login do Diagnóstico
url(r'^login/$', 'django.contrib.auth.views.login', {'template_name':
'diagnosticos/diagnosticos_login.html'}, name='login'),
# Logout do Diagnóstico
url(r'^logout/$', 'django.contrib.auth.views.logout',
{'next_page': LOGOUT_REDIRECT_URL}, name='logout'),
# Lista de Categorias # Lista de Categorias
url(r'^(?P<id_diagnostico>\d+)/categorias/$', 'sigi.apps.diagnosticos.views.categorias', name='lista_categorias'), url(r'^(?P<id_diagnostico>\d+)/categorias/$', 'sigi.apps.diagnosticos.views.categorias', name='lista_categorias'),

11
sigi/apps/diagnosticos/views.py

@ -14,7 +14,8 @@ def lista(request):
# TODO Implementar pesquisa de diagnosticos, em que esses registros # TODO Implementar pesquisa de diagnosticos, em que esses registros
# devem ser criado pelo servidor logado. # devem ser criado pelo servidor logado.
diagnosticos = Diagnostico.objects.filter(status=False) diagnosticos = Diagnostico.objects.filter(status=False).filter(
responsavel=request.user.get_profile())
context = RequestContext(request, {'diagnosticos': diagnosticos}) context = RequestContext(request, {'diagnosticos': diagnosticos})
return render_to_response('diagnosticos/diagnosticos_list.html', context) return render_to_response('diagnosticos/diagnosticos_list.html', context)
@ -44,11 +45,13 @@ def categoria_detalhes(request, id_diagnostico, id_categoria):
return render_to_response('mobile/404.html', {}) return render_to_response('mobile/404.html', {})
if request.POST: if request.POST:
form = DiagnosticoMobileForm(request.POST, instance=diagnostico, category=id_categoria) form = DiagnosticoMobileForm(request.POST,
instance=diagnostico, category=id_categoria)
if form.is_valid(): if form.is_valid():
form.save() form.save()
else: else:
form = DiagnosticoMobileForm(instance=diagnostico, category=id_categoria) form = DiagnosticoMobileForm(instance=diagnostico,
category=id_categoria)
context = RequestContext(request, {'form': form, 'categoria': categoria, context = RequestContext(request, {'form': form, 'categoria': categoria,
'diagnostico': diagnostico}) 'diagnostico': diagnostico})

1
sigi/apps/servidores/admin.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.forms import UserCreationForm
from django.contrib.contenttypes import generic from django.contrib.contenttypes import generic
from sigi.apps.servidores.models import Servidor, Funcao, Licenca, Ferias from sigi.apps.servidores.models import Servidor, Funcao, Licenca, Ferias
from sigi.apps.contatos.models import Endereco, Telefone from sigi.apps.contatos.models import Endereco, Telefone

3
sigi/settings.py

@ -98,6 +98,9 @@ AUTH_LDAP_MIRROR_GROUPS = True
AUTH_LDAP_CACHE_GROUPS = True AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600 AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
# Django Auth Configurations
AUTH_PROFILE_MODULE = 'servidores.Servidor'
# Keep ModelBackend around for per-user permissions and maybe a local superuser. # Keep ModelBackend around for per-user permissions and maybe a local superuser.
AUTHENTICATION_BACKENDS = ( AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend', 'django_auth_ldap.backend.LDAPBackend',

4
sigi/templates/diagnosticos/diagnosticos_list.html

@ -2,7 +2,7 @@
{% block cabecalho %} {% block cabecalho %}
<h1>Diagnósticos</h1> <h1>Diagnósticos</h1>
<a href="#" data-icon="delete" data-theme="e" class="ui-btn-right">Sair</a> <a href="{% url logout %}" data-icon="delete" data-theme="e" class="ui-btn-right">Sair</a>
{% endblock cabecalho %} {% endblock cabecalho %}
{% block corpo %} {% block corpo %}
@ -13,7 +13,7 @@
<a href="{% url lista_categorias diagnostico.id %}"> <a href="{% url lista_categorias diagnostico.id %}">
<h4>{{ diagnostico.casa_legislativa.nome }}</h4> <h4>{{ diagnostico.casa_legislativa.nome }}</h4>
<p><strong>Data:</strong> {{ diagnostico.data_questionario|date:"d/m/Y" }}</p> <p><strong>Data:</strong> {{ diagnostico.data_questionario|date:"d/m/Y" }}</p>
<p><strong>Responsável:</strong> Nenhum Ainda</p> <p><strong>Responsável:</strong> {{ diagnostico.responsavel.nome_completo }}</p>
</a> </a>
</li> </li>
{% endfor %} {% endfor %}

44
sigi/templates/diagnosticos/diagnosticos_login.html

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html lang="pt-BR">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SIGI - Login de Acesso</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>
<div data-role="header" data-theme="d">
<img src="{{ MEDIA_URL }}images/logointerlegis_mobile.png" alt="Interlegis"/>
</div> <!-- header -->
{% if form.errors %}
<div data-role="header" data-theme="b">
<h2>Erro ao logar</h2>
<ul>
{% for field in form %}
{% if field.errors %}
<li>{{ field.errors|striptags }}</li>
{% endif %}
{% endfor %}
</ul>
<p>Verifique se seu login e senha foram preenchidos corretamente.</p>
</div> <!-- error messages -->
{% endif %}
<div data-role="content">
<form action="{% url django.contrib.auth.views.login %}" method="POST">
<div data-role="fieldcontain" class="ui-hide-label ui-body">
<label for="username">Usuário:</label>
<input type="text" name="username" id="id_username" placeholder="Usuário">
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="password">Senha de Acesso:</label>
<input type="password" name="password" id="id_password" placeholder="Senha de Acesso">
</div>
<input type="hidden" name="next" value="/mobile/diagnosticos" />
<button type="submit">Entrar</button>
</form>
</div>
</body>
</html>
Loading…
Cancel
Save