mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 22:23:23 +00:00
Mailing migrations
This commit is contained in:
parent
76efb91e40
commit
72d968e9a5
38
migrate.py
38
migrate.py
@ -46,7 +46,7 @@ from django.core.files import File
|
||||
|
||||
from core.models import User, SithFile
|
||||
from core.utils import doku_to_markdown, bbcode_to_markdown
|
||||
from club.models import Club, Membership
|
||||
from club.models import Club, Membership, Mailing, MailingSubscription
|
||||
from counter.models import Customer, Counter, Selling, Refilling, Product, ProductType, Permanency, Eticket
|
||||
from subscription.models import Subscription
|
||||
from eboutic.models import Invoice, InvoiceItem
|
||||
@ -1332,6 +1332,37 @@ def migrate_forum():
|
||||
print("Forum migrated at %s" % datetime.datetime.now())
|
||||
print("Running time: %s" % (datetime.datetime.now()-start))
|
||||
|
||||
|
||||
def migrate_mailings():
|
||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||
mailing_db = cur.execute("""
|
||||
SELECT * FROM mailing
|
||||
""")
|
||||
mailing_sub_db = cur.execute("""
|
||||
SELECT * FROM mailing_membres
|
||||
""")
|
||||
|
||||
for mailing in mailing_db:
|
||||
club = Club.objects.filter(id=mailing['id_asso_parent'])
|
||||
if club.exists():
|
||||
print(mailing)
|
||||
club = club.first()
|
||||
if mailing['nom']:
|
||||
mailing['nom'] = '.' + mailing['nom']
|
||||
Mailing(id=mailing['id_mailing'], club=club, email=str(club.unix_name + mailing['nom'] + '@utbm.fr')).save()
|
||||
print("-------------------")
|
||||
for mailing_sub in mailing_sub_db:
|
||||
mailing = Mailing.objects.filter(id=mailing_sub['id_mailing'])
|
||||
if mailing.exists():
|
||||
print(mailing_sub)
|
||||
mailing = mailing.first()
|
||||
if mailing_sub['id_user'] and User.objects.filter(id=mailing_sub['id_user']).exists():
|
||||
user = User.objects.get(id=mailing_sub['id_user'])
|
||||
MailingSubscription(mailing=mailing, user=user, email=user.email).save()
|
||||
elif mailing_sub['email']:
|
||||
MailingSubscription(mailing=mailing, email=mailing_sub['email']).save()
|
||||
|
||||
|
||||
def main():
|
||||
print("Start at %s" % start)
|
||||
# Core
|
||||
@ -1351,11 +1382,12 @@ def main():
|
||||
# migrate_sas()
|
||||
# reset_index('core', 'sas')
|
||||
# reset_sas_moderators()
|
||||
migrate_forum()
|
||||
reset_index('forum')
|
||||
# migrate_forum()
|
||||
# reset_index('forum')
|
||||
end = datetime.datetime.now()
|
||||
print("End at %s" % end)
|
||||
print("Running time: %s" % (end - start))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user