Commit 7740189858cb27618de8d842e2dd2860a3e54679
1 parent
f21f3dd5
Exists in
master
and in
39 other branches
adding model and signal to user post_save - closes #104
Showing
1 changed file
with
26 additions
and
0 deletions
Show diff stats
src/proxy/models.py
@@ -5,6 +5,8 @@ import urllib2 | @@ -5,6 +5,8 @@ import urllib2 | ||
5 | 5 | ||
6 | from django.conf import settings | 6 | from django.conf import settings |
7 | from django.db import models | 7 | from django.db import models |
8 | +from django.db.models.signals import post_save | ||
9 | +from django.dispatch import receiver | ||
8 | 10 | ||
9 | from accounts.models import User | 11 | from accounts.models import User |
10 | from hitcounter.models import HitCounterModelMixin | 12 | from hitcounter.models import HitCounterModelMixin |
@@ -148,3 +150,27 @@ class TicketCollabCount(models.Model): | @@ -148,3 +150,27 @@ class TicketCollabCount(models.Model): | ||
148 | class Meta: | 150 | class Meta: |
149 | managed = False | 151 | managed = False |
150 | db_table = 'ticket_collab_count_view' | 152 | db_table = 'ticket_collab_count_view' |
153 | + | ||
154 | + | ||
155 | +class SessionAttribute(models.Model): | ||
156 | + sid = models.TextField(primary_key=True) | ||
157 | + authenticated = models.IntegerField() | ||
158 | + name = models.TextField() | ||
159 | + value = models.TextField(blank=True) | ||
160 | + | ||
161 | + class Meta: | ||
162 | + managed = False | ||
163 | + db_table = 'session_attribute' | ||
164 | + | ||
165 | + | ||
166 | +@receiver(post_save, sender=User) | ||
167 | +def change_session_attribute_email(sender, instance, **kwargs): | ||
168 | + try: | ||
169 | + session_attr = SessionAttribute.objects.get( | ||
170 | + sid=instance.username, name='email' | ||
171 | + ) | ||
172 | + except SessionAttribute.DoesNotExist: | ||
173 | + pass | ||
174 | + else: | ||
175 | + session_attr.value = instance.email | ||
176 | + session_attr.save() |