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.