Commit 3edac263033e69917b8b957a07d93f2195b8167c
Exists in
master
and in
39 other branches
Merge branch 'master' of github.com:TracyWebTech/colab
Showing
1 changed file
with
30 additions
and
1 deletions
Show diff stats
src/proxy/models.py
@@ -4,7 +4,9 @@ import os | @@ -4,7 +4,9 @@ import os | ||
4 | import urllib2 | 4 | 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, connections |
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,30 @@ class TicketCollabCount(models.Model): | @@ -148,3 +150,30 @@ 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 | +@receiver(post_save, sender=User) | ||
156 | +def change_session_attribute_email(sender, instance, **kwargs): | ||
157 | + cursor = connections['trac'].cursor() | ||
158 | + | ||
159 | + cursor.execute(("UPDATE session_attribute SET value=%s " | ||
160 | + "WHERE name='email' AND sid=%s"), | ||
161 | + [instance.email, instance.username]) | ||
162 | + cursor.execute(("UPDATE session_attribute SET value=%s " | ||
163 | + "WHERE name='name' AND sid=%s"), | ||
164 | + [instance.get_full_name(), instance.username]) | ||
165 | + | ||
166 | + cursor.execute(("INSERT INTO session_attribute " | ||
167 | + "(sid, authenticated, name, value) " | ||
168 | + "SELECT %s, '1', 'email', %s WHERE NOT EXISTS " | ||
169 | + "(SELECT 1 FROM session_attribute WHERE sid=%s " | ||
170 | + "AND name='email')"), | ||
171 | + [instance.username, instance.email, instance.username]) | ||
172 | + | ||
173 | + cursor.execute(("INSERT INTO session_attribute " | ||
174 | + "(sid, authenticated, name, value) " | ||
175 | + "SELECT %s, '1', 'name', %s WHERE NOT EXISTS " | ||
176 | + "(SELECT 1 FROM session_attribute WHERE sid=%s " | ||
177 | + "AND name='name')"), | ||
178 | + [instance.username, instance.get_full_name(), | ||
179 | + instance.username]) |