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
156
migrate.py
156
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,7 +48,8 @@ def to_unicode(s):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def migrate_users():
|
def migrate_core():
|
||||||
|
def migrate_users():
|
||||||
SEX = {'1': 'MAN', '2': 'WOMAN', None: 'MAN'}
|
SEX = {'1': 'MAN', '2': 'WOMAN', None: 'MAN'}
|
||||||
TSHIRT = {
|
TSHIRT = {
|
||||||
None: '-',
|
None: '-',
|
||||||
@ -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,8 +151,10 @@ 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/"
|
||||||
|
|
||||||
profile = SithFile.objects.filter(parent=None, name="profiles").first()
|
profile = SithFile.objects.filter(parent=None, name="profiles").first()
|
||||||
@ -179,8 +185,15 @@ 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))
|
||||||
|
|
||||||
def migrate_clubs():
|
migrate_users()
|
||||||
|
migrate_profile_pict()
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_club():
|
||||||
|
def migrate_clubs():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -214,8 +227,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -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,8 +318,11 @@ 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 update_customer_account():
|
def migrate_counter():
|
||||||
|
def update_customer_account():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -316,8 +339,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -340,8 +365,10 @@ 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()
|
||||||
Selling.objects.all().delete()
|
Selling.objects.all().delete()
|
||||||
Invoice.objects.all().delete()
|
Invoice.objects.all().delete()
|
||||||
@ -350,7 +377,7 @@ def reset_customer_amount():
|
|||||||
c.save()
|
c.save()
|
||||||
print("Customer amount reset")
|
print("Customer amount reset")
|
||||||
|
|
||||||
def migrate_refillings():
|
def migrate_refillings():
|
||||||
BANK = {
|
BANK = {
|
||||||
0: "OTHER",
|
0: "OTHER",
|
||||||
1: "SOCIETE-GENERALE",
|
1: "SOCIETE-GENERALE",
|
||||||
@ -407,8 +434,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -427,8 +456,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -457,8 +488,10 @@ 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/"
|
||||||
|
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
@ -477,8 +510,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -493,8 +528,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -533,8 +570,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -578,8 +617,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -601,10 +642,25 @@ 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_companies():
|
def migrate_accounting():
|
||||||
|
def migrate_companies():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -629,8 +685,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -650,8 +708,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -674,8 +734,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -698,8 +760,10 @@ 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 = {
|
||||||
-1: "DEBIT",
|
-1: "DEBIT",
|
||||||
0: "NEUTRAL",
|
0: "NEUTRAL",
|
||||||
@ -724,8 +788,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -746,8 +812,10 @@ 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 = {
|
||||||
1: "CHECK",
|
1: "CHECK",
|
||||||
2: "CASH",
|
2: "CASH",
|
||||||
@ -819,8 +887,10 @@ 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)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -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