|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
from django.conf import settings
|
|
2
|
2
|
from django.db.models import get_model
|
|
3
|
3
|
from django.db.models.signals import post_save
|
|
|
4
|
+from django.db import connection
|
|
4
|
5
|
from django.contrib.auth.models import User
|
|
5
|
6
|
|
|
6
|
7
|
|
|
|
@@ -14,9 +15,17 @@ def migrate_alerts_to_user(sender, instance, created, **kwargs):
|
|
14
|
15
|
Transfer any active alerts linked to a user's email address to the newly
|
|
15
|
16
|
registered user.
|
|
16
|
17
|
"""
|
|
17
|
|
- if created:
|
|
18
|
|
- ProductAlert = get_model('customer', 'ProductAlert')
|
|
19
|
|
- alerts = ProductAlert.objects.filter(email=instance.email, status=ProductAlert.ACTIVE)
|
|
|
18
|
+ if not created:
|
|
|
19
|
+ return
|
|
|
20
|
+ ProductAlert = get_model('customer', 'ProductAlert')
|
|
|
21
|
+
|
|
|
22
|
+ # This signal will be raised when creating a superuser as part of syncdb,
|
|
|
23
|
+ # at which point only a subset of tables will be created. Thus, we test if
|
|
|
24
|
+ # the alert table exists before trying to exercise the ORM.
|
|
|
25
|
+ table = ProductAlert._meta.db_table
|
|
|
26
|
+ if table in connection.introspection.table_names():
|
|
|
27
|
+ alerts = ProductAlert.objects.filter(
|
|
|
28
|
+ email=instance.email, status=ProductAlert.ACTIVE)
|
|
20
|
29
|
alerts.update(user=instance, key=None, email=None)
|
|
21
|
30
|
|
|
22
|
31
|
|