From 7740189858cb27618de8d842e2dd2860a3e54679 Mon Sep 17 00:00:00 2001 From: Luan Date: Tue, 17 Dec 2013 14:08:51 -0200 Subject: [PATCH] adding model and signal to user post_save - closes #104 --- src/proxy/models.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/proxy/models.py b/src/proxy/models.py index 4e091de7..be5ca54c 100644 --- a/src/proxy/models.py +++ b/src/proxy/models.py @@ -5,6 +5,8 @@ from django.conf import settings from django.db import models +from django.db.models.signals import post_save +from django.dispatch import receiver from accounts.models import User from hitcounter.models import HitCounterModelMixin @@ -148,3 +150,27 @@ class TicketCollabCount(models.Model): class Meta: managed = False db_table = 'ticket_collab_count_view' + + +class SessionAttribute(models.Model): + sid = models.TextField(primary_key=True) + authenticated = models.IntegerField() + name = models.TextField() + value = models.TextField(blank=True) + + class Meta: + managed = False + db_table = 'session_attribute' + + +@receiver(post_save, sender=User) +def change_session_attribute_email(sender, instance, **kwargs): + try: + session_attr = SessionAttribute.objects.get( + sid=instance.username, name='email' + ) + except SessionAttribute.DoesNotExist: + pass + else: + session_attr.value = instance.email + session_attr.save()