mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Migrate clubs
This commit is contained in:
parent
2e9fa1a27d
commit
4ec328556e
19
club/migrations/0003_auto_20160813_1448.py
Normal file
19
club/migrations/0003_auto_20160813_1448.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('club', '0002_club_home'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='club',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(verbose_name='name', max_length=64),
|
||||||
|
),
|
||||||
|
]
|
19
club/migrations/0004_auto_20160813_1551.py
Normal file
19
club/migrations/0004_auto_20160813_1551.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('club', '0003_auto_20160813_1448'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='membership',
|
||||||
|
name='description',
|
||||||
|
field=models.CharField(verbose_name='description', blank=True, max_length=128),
|
||||||
|
),
|
||||||
|
]
|
@ -15,7 +15,7 @@ class Club(models.Model):
|
|||||||
"""
|
"""
|
||||||
The Club class, made as a tree to allow nice tidy organization
|
The Club class, made as a tree to allow nice tidy organization
|
||||||
"""
|
"""
|
||||||
name = models.CharField(_('name'), max_length=30)
|
name = models.CharField(_('name'), max_length=64)
|
||||||
parent = models.ForeignKey('Club', related_name='children', null=True, blank=True)
|
parent = models.ForeignKey('Club', related_name='children', null=True, blank=True)
|
||||||
unix_name = models.CharField(_('unix name'), max_length=30, unique=True,
|
unix_name = models.CharField(_('unix name'), max_length=30, unique=True,
|
||||||
validators=[
|
validators=[
|
||||||
@ -72,10 +72,10 @@ class Club(models.Model):
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
creation = False
|
creation = False
|
||||||
if self.id is None:
|
old = Club.objects.filter(id=self.id).first()
|
||||||
|
if not old:
|
||||||
creation = True
|
creation = True
|
||||||
else:
|
else:
|
||||||
old = Club.objects.filter(id=self.id).first()
|
|
||||||
if old.unix_name != self.unix_name:
|
if old.unix_name != self.unix_name:
|
||||||
self._change_unixname(self.unix_name)
|
self._change_unixname(self.unix_name)
|
||||||
super(Club, self).save(*args, **kwargs)
|
super(Club, self).save(*args, **kwargs)
|
||||||
@ -148,7 +148,7 @@ class Membership(models.Model):
|
|||||||
end_date = models.DateField(_('end date'), null=True, blank=True)
|
end_date = models.DateField(_('end date'), null=True, blank=True)
|
||||||
role = models.IntegerField(_('role'), choices=sorted(settings.SITH_CLUB_ROLES.items()),
|
role = models.IntegerField(_('role'), choices=sorted(settings.SITH_CLUB_ROLES.items()),
|
||||||
default=sorted(settings.SITH_CLUB_ROLES.items())[0][0])
|
default=sorted(settings.SITH_CLUB_ROLES.items())[0][0])
|
||||||
description = models.CharField(_('description'), max_length=30, null=False, blank=True)
|
description = models.CharField(_('description'), max_length=128, null=False, blank=True)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
sub = Subscriber.objects.filter(pk=self.user.pk).first()
|
sub = Subscriber.objects.filter(pk=self.user.pk).first()
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<h3>{{ club.name }}</h3>
|
<h3>{{ club.name }}</h3>
|
||||||
<p>{{ club.address }}</p>
|
<p>{{ club.address }}</p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for m in club.members.all() %}
|
{% for m in club.members.filter(end_date=None).all() %}
|
||||||
<li>{{ m }}</li>
|
<li>{{ m }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
{% if object.club_account %}
|
{% if object.club_account %}
|
||||||
<li>Accouting: <a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object }}</a></li>
|
<li>Accouting: <a href="{{ url('accounting:club_details', c_account_id=object.club_account.id) }}">{{ object }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if object.unix_name == settings.SITH_LAUNDERETTE_MANAGER['unix_name'] %}
|
||||||
|
<li><a href="{{ url('launderette:launderette_list') }}">{% trans %}Launderette{% endtrans %}</a></li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ class Command(BaseCommand):
|
|||||||
home_root.save()
|
home_root.save()
|
||||||
club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root)
|
club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root)
|
||||||
club_root.save()
|
club_root.save()
|
||||||
main_club = Club(name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'],
|
main_club = Club(id=1, name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'],
|
||||||
address=settings.SITH_MAIN_CLUB['address'])
|
address=settings.SITH_MAIN_CLUB['address'])
|
||||||
main_club.save()
|
main_club.save()
|
||||||
bar_club = Club(name=settings.SITH_BAR_MANAGER['name'], unix_name=settings.SITH_BAR_MANAGER['unix_name'],
|
bar_club = Club(id=2, name=settings.SITH_BAR_MANAGER['name'], unix_name=settings.SITH_BAR_MANAGER['unix_name'],
|
||||||
address=settings.SITH_BAR_MANAGER['address'])
|
address=settings.SITH_BAR_MANAGER['address'])
|
||||||
bar_club.save()
|
bar_club.save()
|
||||||
launderette_club = Club(name=settings.SITH_LAUNDERETTE_MANAGER['name'],
|
launderette_club = Club(id=84, name=settings.SITH_LAUNDERETTE_MANAGER['name'],
|
||||||
unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name'],
|
unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name'],
|
||||||
address=settings.SITH_LAUNDERETTE_MANAGER['address'])
|
address=settings.SITH_LAUNDERETTE_MANAGER['address'])
|
||||||
launderette_club.save()
|
launderette_club.save()
|
||||||
|
346
migrate.py
346
migrate.py
@ -2,15 +2,20 @@ import MySQLdb
|
|||||||
import os
|
import os
|
||||||
import django
|
import django
|
||||||
import random
|
import random
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
os.environ["DJANGO_SETTINGS_MODULE"] = "sith.settings"
|
os.environ["DJANGO_SETTINGS_MODULE"] = "sith.settings"
|
||||||
|
os.environ['DJANGO_COLORS'] = 'nocolor'
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
from core.models import User, SithFile
|
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.management import call_command
|
||||||
|
from django.db import connection
|
||||||
|
|
||||||
PROFILE_ROOT = "/data/matmatronch/"
|
|
||||||
|
from core.models import User, SithFile
|
||||||
|
from club.models import Club, Membership
|
||||||
|
|
||||||
db = MySQLdb.connect(
|
db = MySQLdb.connect(
|
||||||
host="ae-db",
|
host="ae-db",
|
||||||
@ -19,144 +24,225 @@ db = MySQLdb.connect(
|
|||||||
db="ae2-taiste",
|
db="ae2-taiste",
|
||||||
charset='utf8',
|
charset='utf8',
|
||||||
use_unicode=True)
|
use_unicode=True)
|
||||||
c = db.cursor(MySQLdb.cursors.DictCursor)
|
|
||||||
c.execute("""
|
|
||||||
SELECT *
|
|
||||||
FROM utilisateurs utl
|
|
||||||
JOIN utl_etu ue
|
|
||||||
ON ue.id_utilisateur = utl.id_utilisateur
|
|
||||||
JOIN utl_etu_utbm ueu
|
|
||||||
ON ueu.id_utilisateur = utl.id_utilisateur
|
|
||||||
JOIN utl_extra uxtra
|
|
||||||
ON uxtra.id_utilisateur = utl.id_utilisateur
|
|
||||||
JOIN loc_ville ville
|
|
||||||
ON utl.id_ville = ville.id_ville
|
|
||||||
WHERE utl.id_utilisateur > 9000
|
|
||||||
""")
|
|
||||||
User.objects.filter(id__gt=0).delete()
|
|
||||||
print("Users deleted")
|
|
||||||
# guy = c.fetchone()
|
|
||||||
# for k,v in sorted(guy.items()):
|
|
||||||
# print("%40s | %40s" % (k, v))
|
|
||||||
|
|
||||||
SEX = {'1': 'MAN', '2': 'WOMAN', None: 'MAN'}
|
def reset_index(*args):
|
||||||
TSHIRT = {
|
sqlcmd = StringIO()
|
||||||
None: '-',
|
call_command("sqlsequencereset", *args, stdout=sqlcmd)
|
||||||
'': '-',
|
cursor = connection.cursor()
|
||||||
'NULL': '-',
|
cursor.execute(sqlcmd.getvalue())
|
||||||
'XS': 'XS',
|
|
||||||
'S': 'S',
|
|
||||||
'M': 'M',
|
|
||||||
'L': 'L',
|
|
||||||
'XL': 'XL',
|
|
||||||
'XXL': 'XXL',
|
|
||||||
'XXXL': 'XXXL',
|
|
||||||
}
|
|
||||||
ROLE = {
|
|
||||||
'doc': 'DOCTOR',
|
|
||||||
'etu': 'STUDENT',
|
|
||||||
'anc': 'FORMER STUDENT',
|
|
||||||
'ens': 'TEACHER',
|
|
||||||
'adm': 'ADMINISTRATIVE',
|
|
||||||
'srv': 'SERVICE',
|
|
||||||
'per': 'AGENT',
|
|
||||||
None: '',
|
|
||||||
}
|
|
||||||
DEPARTMENTS = {
|
|
||||||
'tc': 'TC',
|
|
||||||
'gi': 'GI',
|
|
||||||
'gesc': 'GESC',
|
|
||||||
'na': 'NA',
|
|
||||||
'mc': 'MC',
|
|
||||||
'imap': 'IMAP',
|
|
||||||
'huma': 'HUMA',
|
|
||||||
'edim': 'EDIM',
|
|
||||||
'ee': 'EE',
|
|
||||||
'imsi': 'IMSI',
|
|
||||||
'truc': 'NA',
|
|
||||||
None: 'NA',
|
|
||||||
}
|
|
||||||
|
|
||||||
def to_unicode(s):
|
def to_unicode(s):
|
||||||
if s:
|
if s:
|
||||||
return bytes(s, 'cp1252', errors="replace").decode('utf-8', errors='replace')
|
return bytes(s, 'cp1252', errors="replace").decode('utf-8', errors='replace')
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def get_random_free_email():
|
|
||||||
id = random.randrange(4000)
|
def migrate_users():
|
||||||
email = "no_email_%s@git.an" % random.randrange(4000, 40000)
|
SEX = {'1': 'MAN', '2': 'WOMAN', None: 'MAN'}
|
||||||
while User.objects.filter(email=email).exists():
|
TSHIRT = {
|
||||||
|
None: '-',
|
||||||
|
'': '-',
|
||||||
|
'NULL': '-',
|
||||||
|
'XS': 'XS',
|
||||||
|
'S': 'S',
|
||||||
|
'M': 'M',
|
||||||
|
'L': 'L',
|
||||||
|
'XL': 'XL',
|
||||||
|
'XXL': 'XXL',
|
||||||
|
'XXXL': 'XXXL',
|
||||||
|
}
|
||||||
|
ROLE = {
|
||||||
|
'doc': 'DOCTOR',
|
||||||
|
'etu': 'STUDENT',
|
||||||
|
'anc': 'FORMER STUDENT',
|
||||||
|
'ens': 'TEACHER',
|
||||||
|
'adm': 'ADMINISTRATIVE',
|
||||||
|
'srv': 'SERVICE',
|
||||||
|
'per': 'AGENT',
|
||||||
|
None: '',
|
||||||
|
}
|
||||||
|
DEPARTMENTS = {
|
||||||
|
'tc': 'TC',
|
||||||
|
'gi': 'GI',
|
||||||
|
'gesc': 'GESC',
|
||||||
|
'na': 'NA',
|
||||||
|
'mc': 'MC',
|
||||||
|
'imap': 'IMAP',
|
||||||
|
'huma': 'HUMA',
|
||||||
|
'edim': 'EDIM',
|
||||||
|
'ee': 'EE',
|
||||||
|
'imsi': 'IMSI',
|
||||||
|
'truc': 'NA',
|
||||||
|
None: 'NA',
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_random_free_email():
|
||||||
|
id = random.randrange(4000)
|
||||||
email = "no_email_%s@git.an" % random.randrange(4000, 40000)
|
email = "no_email_%s@git.an" % random.randrange(4000, 40000)
|
||||||
return email
|
while User.objects.filter(email=email).exists():
|
||||||
|
email = "no_email_%s@git.an" % random.randrange(4000, 40000)
|
||||||
|
return email
|
||||||
|
|
||||||
for u in c.fetchall():
|
c = db.cursor(MySQLdb.cursors.DictCursor)
|
||||||
try:
|
c.execute("""
|
||||||
new = User(
|
SELECT *
|
||||||
id=u['id_utilisateur'],
|
FROM utilisateurs utl
|
||||||
last_name=to_unicode(u['nom_utl']) or "Bou",
|
JOIN utl_etu ue
|
||||||
first_name=to_unicode(u['prenom_utl']) or "Bi",
|
ON ue.id_utilisateur = utl.id_utilisateur
|
||||||
email=u['email_utl'],
|
JOIN utl_etu_utbm ueu
|
||||||
second_email=u['email_utbm'] or "",
|
ON ueu.id_utilisateur = utl.id_utilisateur
|
||||||
date_of_birth=u['date_naissance_utl'],
|
JOIN utl_extra uxtra
|
||||||
last_update=u['date_maj_utl'],
|
ON uxtra.id_utilisateur = utl.id_utilisateur
|
||||||
nick_name=to_unicode(u['surnom_utbm']),
|
JOIN loc_ville ville
|
||||||
sex=SEX[u['sexe_utl']],
|
ON utl.id_ville = ville.id_ville
|
||||||
tshirt_size=TSHIRT[u['taille_tshirt_utl']],
|
-- WHERE utl.id_utilisateur > 9000
|
||||||
role=ROLE[u['role_utbm']],
|
""")
|
||||||
department=DEPARTMENTS[u['departement_utbm']],
|
User.objects.filter(id__gt=0).delete()
|
||||||
dpt_option=to_unicode(u['filiere_utbm']),
|
print("Users deleted")
|
||||||
semester=u['semestre_utbm'] or 0,
|
|
||||||
quote=to_unicode(u['citation']),
|
|
||||||
school=to_unicode(u['nom_ecole_etudiant']),
|
|
||||||
promo=u['promo_utbm'] or 0,
|
|
||||||
forum_signature=to_unicode(u['signature_utl']),
|
|
||||||
address=(to_unicode(u['addresse_utl']) + ", " + to_unicode(u['cpostal_ville']) + " " + to_unicode(u['nom_ville'])),
|
|
||||||
parent_address=(to_unicode(u['adresse_parents']) + ", " + to_unicode(u['cpostal_parents']) + " " + to_unicode(u['ville_parents'])),
|
|
||||||
phone=u['tel_portable_utl'] or "",
|
|
||||||
parent_phone=u['tel_parents'] or "",
|
|
||||||
)
|
|
||||||
new.generate_username()
|
|
||||||
new.save()
|
|
||||||
except IntegrityError as e:
|
|
||||||
if "Key (email)" in repr(e):
|
|
||||||
new.email = get_random_free_email()
|
|
||||||
new.save()
|
|
||||||
print("New email generated")
|
|
||||||
else:
|
|
||||||
print("FAIL for user %s: %s" % (u['id_utilisateur'], repr(e)))
|
|
||||||
except Exception as e:
|
|
||||||
print("FAIL for user %s: %s" % (u['id_utilisateur'], repr(e)))
|
|
||||||
c.close()
|
|
||||||
|
|
||||||
from os import listdir
|
for u in c.fetchall():
|
||||||
from django.core.files import File
|
|
||||||
|
|
||||||
profile = SithFile.objects.filter(parent=None, name="profiles").first()
|
|
||||||
for filename in listdir(PROFILE_ROOT):
|
|
||||||
if filename.split('.')[-2] != "mini":
|
|
||||||
try:
|
try:
|
||||||
uid = filename.split('.')[0].split('-')[0]
|
new = User(
|
||||||
user = User.objects.filter(id=int(uid)).first()
|
id=u['id_utilisateur'],
|
||||||
if user:
|
last_name=to_unicode(u['nom_utl']) or "Bou",
|
||||||
f = File(open(PROFILE_ROOT + '/' + filename, 'rb'))
|
first_name=to_unicode(u['prenom_utl']) or "Bi",
|
||||||
t = filename.split('.')[1]
|
email=u['email_utl'],
|
||||||
new_file = SithFile(parent=profile, name=filename,
|
second_email=u['email_utbm'] or "",
|
||||||
file=f, owner=user, is_folder=False, mime_type="image/jpeg", size=f.size)
|
date_of_birth=u['date_naissance_utl'],
|
||||||
if t == "identity":
|
last_update=u['date_maj_utl'],
|
||||||
new_file.save()
|
nick_name=to_unicode(u['surnom_utbm']),
|
||||||
user.profile_pict = new_file
|
sex=SEX[u['sexe_utl']],
|
||||||
user.save()
|
tshirt_size=TSHIRT[u['taille_tshirt_utl']],
|
||||||
elif t == "blouse":
|
role=ROLE[u['role_utbm']],
|
||||||
new_file.save()
|
department=DEPARTMENTS[u['departement_utbm']],
|
||||||
user.scrub_pict = new_file
|
dpt_option=to_unicode(u['filiere_utbm']),
|
||||||
user.save()
|
semester=u['semestre_utbm'] or 0,
|
||||||
else:
|
quote=to_unicode(u['citation']),
|
||||||
new_file.save()
|
school=to_unicode(u['nom_ecole_etudiant']),
|
||||||
user.avatar_pict = new_file
|
promo=u['promo_utbm'] or 0,
|
||||||
user.save()
|
forum_signature=to_unicode(u['signature_utl']),
|
||||||
|
address=(to_unicode(u['addresse_utl']) + ", " + to_unicode(u['cpostal_ville']) + " " + to_unicode(u['nom_ville'])),
|
||||||
|
parent_address=(to_unicode(u['adresse_parents']) + ", " + to_unicode(u['cpostal_parents']) + " " + to_unicode(u['ville_parents'])),
|
||||||
|
phone=u['tel_portable_utl'] or "",
|
||||||
|
parent_phone=u['tel_parents'] or "",
|
||||||
|
)
|
||||||
|
new.generate_username()
|
||||||
|
new.save()
|
||||||
|
except IntegrityError as e:
|
||||||
|
if "Key (email)" in repr(e):
|
||||||
|
new.email = get_random_free_email()
|
||||||
|
new.save()
|
||||||
|
print("New email generated")
|
||||||
|
else:
|
||||||
|
print("FAIL for user %s: %s" % (u['id_utilisateur'], repr(e)))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(repr(e))
|
print("FAIL for user %s: %s" % (u['id_utilisateur'], repr(e)))
|
||||||
|
c.close()
|
||||||
|
reset_index('core')
|
||||||
|
|
||||||
# profile_pict = models.OneToOneField('SithFile', related_name='profile_of', verbose_name=_("profile"), null=True, blank=True)
|
def migrate_profile_pict():
|
||||||
# avatar_pict = models.OneToOneField('SithFile', related_name='avatar_of', verbose_name=_("avatar"), null=True, blank=True)
|
PROFILE_ROOT = "/data/matmatronch/"
|
||||||
# scrub_pict = models.OneToOneField('SithFile', related_name='scrub_of', verbose_name=_("scrub"), null=True, blank=True)
|
|
||||||
|
from os import listdir
|
||||||
|
from django.core.files import File
|
||||||
|
|
||||||
|
profile = SithFile.objects.filter(parent=None, name="profiles").first()
|
||||||
|
profile.children.all().delete()
|
||||||
|
print("Profiles pictures deleted")
|
||||||
|
for filename in listdir(PROFILE_ROOT):
|
||||||
|
if filename.split('.')[-2] != "mini":
|
||||||
|
try:
|
||||||
|
uid = filename.split('.')[0].split('-')[0]
|
||||||
|
user = User.objects.filter(id=int(uid)).first()
|
||||||
|
if user:
|
||||||
|
f = File(open(PROFILE_ROOT + '/' + filename, 'rb'))
|
||||||
|
f.name = f.name.split('/')[-1]
|
||||||
|
t = filename.split('.')[1]
|
||||||
|
new_file = SithFile(parent=profile, name=filename,
|
||||||
|
file=f, owner=user, is_folder=False, mime_type="image/jpeg", size=f.size)
|
||||||
|
if t == "identity":
|
||||||
|
new_file.save()
|
||||||
|
user.profile_pict = new_file
|
||||||
|
user.save()
|
||||||
|
elif t == "blouse":
|
||||||
|
new_file.save()
|
||||||
|
user.scrub_pict = new_file
|
||||||
|
user.save()
|
||||||
|
else:
|
||||||
|
new_file.save()
|
||||||
|
user.avatar_pict = new_file
|
||||||
|
user.save()
|
||||||
|
except Exception as e:
|
||||||
|
print(repr(e))
|
||||||
|
|
||||||
|
def migrate_clubs():
|
||||||
|
cur = db.cursor(MySQLdb.cursors.DictCursor)
|
||||||
|
cur.execute("""
|
||||||
|
SELECT *
|
||||||
|
FROM asso asso
|
||||||
|
WHERE nom_unix_asso <> "ae"
|
||||||
|
AND nom_unix_asso <> "bdf"
|
||||||
|
AND nom_unix_asso <> "laverie"
|
||||||
|
""")
|
||||||
|
# club = cur.fetchone()
|
||||||
|
# for k,v in club.items():
|
||||||
|
# print("%40s | %40s" % (k, v))
|
||||||
|
|
||||||
|
for c in cur.fetchall():
|
||||||
|
try:
|
||||||
|
new = Club(
|
||||||
|
id=c['id_asso'],
|
||||||
|
name=to_unicode(c['nom_asso']),
|
||||||
|
unix_name=to_unicode(c['nom_unix_asso']),
|
||||||
|
address=to_unicode(c['adresse_postale']),
|
||||||
|
)
|
||||||
|
new.save()
|
||||||
|
except Exception as e:
|
||||||
|
print("FAIL for club %s: %s" % (c['nom_unix_asso'], repr(e)))
|
||||||
|
cur.execute("""
|
||||||
|
SELECT *
|
||||||
|
FROM asso
|
||||||
|
""")
|
||||||
|
for c in cur.fetchall():
|
||||||
|
club = Club.objects.filter(id=c['id_asso']).first()
|
||||||
|
parent = Club.objects.filter(id=c['id_asso_parent']).first()
|
||||||
|
club.parent = parent
|
||||||
|
club.save()
|
||||||
|
cur.close()
|
||||||
|
|
||||||
|
def migrate_club_memberships():
|
||||||
|
cur = db.cursor(MySQLdb.cursors.DictCursor)
|
||||||
|
cur.execute("""
|
||||||
|
SELECT *
|
||||||
|
FROM asso_membre
|
||||||
|
""")
|
||||||
|
|
||||||
|
Membership.objects.all().delete()
|
||||||
|
print("Memberships deleted")
|
||||||
|
for m in cur.fetchall():
|
||||||
|
try:
|
||||||
|
club = Club.objects.filter(id=m['id_asso']).first()
|
||||||
|
user = User.objects.filter(id=m['id_utilisateur']).first()
|
||||||
|
if club and user:
|
||||||
|
new = Membership(
|
||||||
|
club=club,
|
||||||
|
user=user,
|
||||||
|
start_date=m['date_debut'],
|
||||||
|
end_date=m['date_fin'],
|
||||||
|
role=m['role'],
|
||||||
|
description=to_unicode(m['desc_role']),
|
||||||
|
)
|
||||||
|
new.save()
|
||||||
|
except Exception as e:
|
||||||
|
print("FAIL for club membership %s: %s" % (m['id_asso'], repr(e)))
|
||||||
|
cur.close()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# migrate_users()
|
||||||
|
# migrate_profile_pict()
|
||||||
|
# migrate_clubs()
|
||||||
|
migrate_club_memberships()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user