mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 11:04:20 +00:00
Fix email sending by setting password to all migrated users + refactor migrate.py
This commit is contained in:
parent
bea7b71f2c
commit
ce7230751e
110
migrate.py
110
migrate.py
@ -34,6 +34,8 @@ db = MySQLdb.connect(
|
|||||||
charset='utf8',
|
charset='utf8',
|
||||||
use_unicode=True)
|
use_unicode=True)
|
||||||
|
|
||||||
|
start = datetime.datetime.now()
|
||||||
|
|
||||||
def reset_index(*args):
|
def reset_index(*args):
|
||||||
sqlcmd = StringIO()
|
sqlcmd = StringIO()
|
||||||
call_command("sqlsequencereset", *args, stdout=sqlcmd)
|
call_command("sqlsequencereset", *args, stdout=sqlcmd)
|
||||||
@ -46,6 +48,7 @@ def to_unicode(s):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_core():
|
||||||
def migrate_users():
|
def migrate_users():
|
||||||
SEX = {'1': 'MAN', '2': 'WOMAN', None: 'MAN'}
|
SEX = {'1': 'MAN', '2': 'WOMAN', None: 'MAN'}
|
||||||
TSHIRT = {
|
TSHIRT = {
|
||||||
@ -136,6 +139,7 @@ def migrate_users():
|
|||||||
is_subscriber_viewable=bool(u['publique_utl']),
|
is_subscriber_viewable=bool(u['publique_utl']),
|
||||||
)
|
)
|
||||||
new.generate_username()
|
new.generate_username()
|
||||||
|
new.set_password(str(random.randrange(1000000, 10000000)))
|
||||||
new.save()
|
new.save()
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
if "Key (email)" in repr(e):
|
if "Key (email)" in repr(e):
|
||||||
@ -147,6 +151,8 @@ def migrate_users():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL for user %s: %s" % (u['id_utilisateur'], repr(e)))
|
print("FAIL for user %s: %s" % (u['id_utilisateur'], repr(e)))
|
||||||
c.close()
|
c.close()
|
||||||
|
print("Users migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_profile_pict():
|
def migrate_profile_pict():
|
||||||
PROFILE_ROOT = "/data/matmatronch/"
|
PROFILE_ROOT = "/data/matmatronch/"
|
||||||
@ -179,7 +185,14 @@ def migrate_profile_pict():
|
|||||||
user.save()
|
user.save()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(repr(e))
|
print(repr(e))
|
||||||
|
print("Profile pictures migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
|
migrate_users()
|
||||||
|
migrate_profile_pict()
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_club():
|
||||||
def migrate_clubs():
|
def migrate_clubs():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
@ -214,6 +227,8 @@ def migrate_clubs():
|
|||||||
club.parent = parent
|
club.parent = parent
|
||||||
club.save()
|
club.save()
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Clubs migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_club_memberships():
|
def migrate_club_memberships():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -241,6 +256,11 @@ def migrate_club_memberships():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL for club membership %s: %s" % (m['id_asso'], repr(e)))
|
print("FAIL for club membership %s: %s" % (m['id_asso'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Clubs memberships migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
|
migrate_clubs()
|
||||||
|
migrate_club_memberships()
|
||||||
|
|
||||||
def migrate_subscriptions():
|
def migrate_subscriptions():
|
||||||
LOCATION = {
|
LOCATION = {
|
||||||
@ -298,7 +318,10 @@ def migrate_subscriptions():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL for subscription %s: %s" % (r['id_cotisation'], repr(e)))
|
print("FAIL for subscription %s: %s" % (r['id_cotisation'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Subscriptions migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
|
def migrate_counter():
|
||||||
def update_customer_account():
|
def update_customer_account():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
@ -316,6 +339,8 @@ def update_customer_account():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to update customer account for %s: %s" % (r['id_cotisation'], repr(e)))
|
print("FAIL to update customer account for %s: %s" % (r['id_cotisation'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Customer accounts migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_counters():
|
def migrate_counters():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -340,6 +365,8 @@ def migrate_counters():
|
|||||||
eboutic = Counter.objects.filter(id=3).first()
|
eboutic = Counter.objects.filter(id=3).first()
|
||||||
eboutic.type = "EBOUTIC"
|
eboutic.type = "EBOUTIC"
|
||||||
eboutic.save()
|
eboutic.save()
|
||||||
|
print("Counters migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def reset_customer_amount():
|
def reset_customer_amount():
|
||||||
Refilling.objects.all().delete()
|
Refilling.objects.all().delete()
|
||||||
@ -407,6 +434,8 @@ def migrate_refillings():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate refilling %s for %s: %s" % (r['id_rechargement'], r['id_utilisateur'], repr(e)))
|
print("FAIL to migrate refilling %s for %s: %s" % (r['id_rechargement'], r['id_utilisateur'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Refillings migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_typeproducts():
|
def migrate_typeproducts():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -427,6 +456,8 @@ def migrate_typeproducts():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate product type %s: %s" % (r['nom_typeprod'], repr(e)))
|
print("FAIL to migrate product type %s: %s" % (r['nom_typeprod'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Product types migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_products():
|
def migrate_products():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -457,6 +488,8 @@ def migrate_products():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate product %s: %s" % (r['nom_prod'], repr(e)))
|
print("FAIL to migrate product %s: %s" % (r['nom_prod'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Product migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_product_pict():
|
def migrate_product_pict():
|
||||||
FILE_ROOT = "/data/files/"
|
FILE_ROOT = "/data/files/"
|
||||||
@ -477,6 +510,8 @@ def migrate_product_pict():
|
|||||||
prod.save()
|
prod.save()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(repr(e))
|
print(repr(e))
|
||||||
|
print("Product pictures migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_products_to_counter():
|
def migrate_products_to_counter():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -493,6 +528,8 @@ def migrate_products_to_counter():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to set product %s in counter %s: %s" % (product, counter, repr(e)))
|
print("FAIL to set product %s in counter %s: %s" % (product, counter, repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Product in counters migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_invoices():
|
def migrate_invoices():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -533,6 +570,8 @@ def migrate_invoices():
|
|||||||
if f.name == "date":
|
if f.name == "date":
|
||||||
f.auto_now = False
|
f.auto_now = False
|
||||||
i.validate()
|
i.validate()
|
||||||
|
print("Invoices migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_sellings():
|
def migrate_sellings():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -578,6 +617,8 @@ def migrate_sellings():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate selling %s: %s" % (r['id_facture'], repr(e)))
|
print("FAIL to migrate selling %s: %s" % (r['id_facture'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Sellings migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_permanencies():
|
def migrate_permanencies():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -601,9 +642,24 @@ def migrate_permanencies():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate permanency: %s" % (repr(e)))
|
print("FAIL to migrate permanency: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Permanencies migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
|
update_customer_account()
|
||||||
|
migrate_counters()
|
||||||
|
migrate_permanencies()
|
||||||
|
migrate_typeproducts()
|
||||||
|
migrate_products()
|
||||||
|
migrate_product_pict()
|
||||||
|
migrate_products_to_counter()
|
||||||
|
reset_customer_amount()
|
||||||
|
migrate_invoices()
|
||||||
|
migrate_refillings()
|
||||||
|
migrate_sellings()
|
||||||
|
|
||||||
### Accounting
|
### Accounting
|
||||||
|
|
||||||
|
def migrate_accounting():
|
||||||
def migrate_companies():
|
def migrate_companies():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
@ -629,6 +685,8 @@ def migrate_companies():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate company: %s" % (repr(e)))
|
print("FAIL to migrate company: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Companies migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_bank_accounts():
|
def migrate_bank_accounts():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -650,6 +708,8 @@ def migrate_bank_accounts():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate bank account: %s" % (repr(e)))
|
print("FAIL to migrate bank account: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Bank accounts migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_club_accounts():
|
def migrate_club_accounts():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -674,6 +734,8 @@ def migrate_club_accounts():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate club account: %s" % (repr(e)))
|
print("FAIL to migrate club account: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Club accounts migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_journals():
|
def migrate_journals():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -698,6 +760,8 @@ def migrate_journals():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate general journal: %s" % (repr(e)))
|
print("FAIL to migrate general journal: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("General journals migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_accounting_types():
|
def migrate_accounting_types():
|
||||||
MOVEMENT = {
|
MOVEMENT = {
|
||||||
@ -724,6 +788,8 @@ def migrate_accounting_types():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate accounting type: %s" % (repr(e)))
|
print("FAIL to migrate accounting type: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Accounting types migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_simpleaccounting_types():
|
def migrate_simpleaccounting_types():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -746,6 +812,8 @@ def migrate_simpleaccounting_types():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate simple type: %s" % (repr(e)))
|
print("FAIL to migrate simple type: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Simple accounting types migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def migrate_operations():
|
def migrate_operations():
|
||||||
MODE = {
|
MODE = {
|
||||||
@ -819,6 +887,8 @@ def migrate_operations():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate operation: %s" % (repr(e)))
|
print("FAIL to migrate operation: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Operations migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def make_operation_links():
|
def make_operation_links():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -838,32 +908,9 @@ def make_operation_links():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to link operations: %s" % (repr(e)))
|
print("FAIL to link operations: %s" % (repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
print("Operations links migrated at %s" % datetime.datetime.now())
|
||||||
|
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||||
|
|
||||||
def main():
|
|
||||||
start = datetime.datetime.now()
|
|
||||||
print("Start at %s" % start)
|
|
||||||
# Core
|
|
||||||
migrate_users()
|
|
||||||
migrate_profile_pict()
|
|
||||||
# Club
|
|
||||||
migrate_clubs()
|
|
||||||
migrate_club_memberships()
|
|
||||||
# Subscriptions
|
|
||||||
migrate_subscriptions()
|
|
||||||
# Counters
|
|
||||||
update_customer_account()
|
|
||||||
migrate_counters()
|
|
||||||
migrate_permanencies()
|
|
||||||
migrate_typeproducts()
|
|
||||||
migrate_products()
|
|
||||||
migrate_product_pict()
|
|
||||||
migrate_products_to_counter()
|
|
||||||
reset_customer_amount()
|
|
||||||
migrate_invoices()
|
|
||||||
reset_index('counter')
|
|
||||||
migrate_refillings()
|
|
||||||
migrate_sellings()
|
|
||||||
# Accounting
|
|
||||||
migrate_companies()
|
migrate_companies()
|
||||||
migrate_accounting_types()
|
migrate_accounting_types()
|
||||||
migrate_simpleaccounting_types()
|
migrate_simpleaccounting_types()
|
||||||
@ -872,6 +919,19 @@ def main():
|
|||||||
migrate_journals()
|
migrate_journals()
|
||||||
migrate_operations()
|
migrate_operations()
|
||||||
make_operation_links()
|
make_operation_links()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Start at %s" % start)
|
||||||
|
# Core
|
||||||
|
migrate_core()
|
||||||
|
# Club
|
||||||
|
migrate_club()
|
||||||
|
# Subscriptions
|
||||||
|
migrate_subscriptions()
|
||||||
|
# Counters
|
||||||
|
migrate_counter()
|
||||||
|
# Accounting
|
||||||
|
migrate_accounting()
|
||||||
reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter')
|
reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter')
|
||||||
end = datetime.datetime.now()
|
end = datetime.datetime.now()
|
||||||
print("End at %s" % end)
|
print("End at %s" % end)
|
||||||
|
Loading…
Reference in New Issue
Block a user