Permalink
Browse files

Don't execute some signals when loading fixtures.

  • Loading branch information...
1 parent bc193c9 commit a12774be93f4e1310a410461d725f7f0f576c438 @glogiotatidis glogiotatidis committed Nov 10, 2012
Showing with 10 additions and 9 deletions.
  1. +1 −1 apps/groups/models.py
  2. +1 −1 apps/phonebook/models.py
  3. +7 −6 apps/users/models.py
  4. +1 −1 fixtures-dev/initial_data.json
View
@@ -83,7 +83,7 @@ class Language(GroupBase):
@receiver(models.signals.pre_save, sender=Group)
def _create_url_slug(sender, instance, raw, using, **kwargs):
"""Create a Group's URL slug when it's first saved."""
- if not instance.pk:
+ if not instance.pk and not raw:
instance.url = slugify(instance.name.lower())
View
@@ -71,7 +71,7 @@ class Meta:
@receiver(models.signals.pre_save, sender=Invite)
def generate_code(sender, instance, raw, using, **kwargs):
- if instance.code:
+ if instance.code or raw:
return
# 10 tries for uniqueness
View
@@ -271,26 +271,27 @@ def search(cls, query, vouched=None, photo=None):
@receiver(models.signals.post_save, sender=User,
dispatch_uid='create_user_profile_sig')
-def create_user_profile(sender, instance, created, **kwargs):
- up, created = UserProfile.objects.get_or_create(user=instance)
- if created:
- up.save()
+def create_user_profile(sender, instance, created, raw, **kwargs):
+ if created and not raw:
+ up, created = UserProfile.objects.get_or_create(user=instance)
@receiver(models.signals.pre_save, sender=UserProfile,
dispatch_uid='auto_vouch_sig')
def auto_vouch(sender, instance, raw, using, **kwargs):
"""Auto vouch mozilla.com users."""
- if not instance.id:
+ if not instance.id and not raw:
email = instance.user.email
if any(email.endswith('@' + x) for x in settings.AUTO_VOUCH_DOMAINS):
instance.vouch(None, commit=False)
@receiver(models.signals.post_save, sender=UserProfile,
dispatch_uid='add_to_staff_group_sig')
-def add_to_staff_group(sender, instance, created, **kwargs):
+def add_to_staff_group(sender, instance, created, raw, **kwargs):
"""Keep users in the staff group if they're autovouchable."""
+ if raw:
+ return
email = instance.user.email
staff, created = Group.objects.get_or_create(name='staff', system=True)
if any(email.endswith('@' + x) for x in
@@ -65,7 +65,7 @@
"groups": [],
"user_permissions": [],
"password": "!",
- "email": "text@example.com",
+ "email": "test@example.com",
"date_joined": "2012-11-06T08:09:34"
}
}

0 comments on commit a12774b

Please sign in to comment.