Browse Source

Passa PK usuário após logar

pull/6/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
committed by Luciano Almeida
parent
commit
8ce7fa2c69
  1. 22
      sigi/context_processors.py
  2. 1
      sigi/settings/base.py

22
sigi/context_processors.py

@ -0,0 +1,22 @@
from django.core.exceptions import ObjectDoesNotExist
from sigi.apps.usuarios.models import Usuario
def recupera_usuario(request):
pk = request.user.pk
if pk:
try:
usuario = Usuario.objects.get(user_id=pk)
except ObjectDoesNotExist:
return 0
else:
return usuario.pk
else:
return 0
def usuario_context(request):
context = {'usuario_pk': recupera_usuario(request)}
return context

1
sigi/settings/base.py

@ -32,6 +32,7 @@ SITE_ID = 1
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + [
'django.core.context_processors.request',
'sigi.context_processors.usuario_context'
]
# List of callables that know how to import templates from various sources.

Loading…
Cancel
Save