Commit eebc81b0 authored by Baptiste Jonglez's avatar Baptiste Jonglez
Browse files

Fix bulk import of the database (by disabling post_save signals in this case)

parent 67c59bed
......@@ -14,7 +14,8 @@ from django.dispatch import receiver
from coin.offers.models import OfferSubscription
from coin.members.models import Member
from coin.html2pdf import render_as_pdf
from coin.utils import private_files_storage, start_of_month, end_of_month
from coin.utils import private_files_storage, start_of_month, end_of_month, \
disable_for_loaddata
from coin.isp_database.context_processors import branding
def next_invoice_number():
......@@ -204,6 +205,7 @@ class Payment(models.Model):
@receiver(post_save, sender=Payment)
@disable_for_loaddata
def set_invoice_as_paid_if_needed(sender, instance, **kwargs):
"""
Lorsqu'un paiement est enregistré, vérifie si la facture est alors
......
......@@ -10,6 +10,7 @@ import re
import sys
from datetime import date, timedelta
from contextlib import contextmanager
from functools import wraps
from django.utils import translation
from django.core.mail import EmailMultiAlternatives
......@@ -149,6 +150,18 @@ def respects_language(fun):
return fun(*args, **kwargs)
return _inner
def disable_for_loaddata(signal_handler):
"""Decorator for post_save events that disables them when loading
data from fixtures."""
@wraps(signal_handler)
def wrapper(*args, **kwargs):
if kwargs['raw']:
return
signal_handler(*args, **kwargs)
return wrapper
if __name__ == '__main__':
# ldap_hash expects an unicode string
print(ldap_hash(sys.argv[1].decode("utf-8")))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment