From 8ce7fa2c691dfe49b346be7efac98d042f92004c Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 23 Jun 2016 14:35:46 -0300 Subject: [PATCH] =?UTF-8?q?Passa=20PK=20usu=C3=A1rio=20ap=C3=B3s=20logar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/context_processors.py | 22 ++++++++++++++++++++++ sigi/settings/base.py | 1 + 2 files changed, 23 insertions(+) create mode 100644 sigi/context_processors.py diff --git a/sigi/context_processors.py b/sigi/context_processors.py new file mode 100644 index 0000000..34bd01b --- /dev/null +++ b/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 diff --git a/sigi/settings/base.py b/sigi/settings/base.py index 2a29ab1..12556c6 100644 --- a/sigi/settings/base.py +++ b/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.