From f843c337e34d7f780846cbdf0b55ea340188d196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sat, 28 Oct 2017 17:28:04 +0200 Subject: [PATCH 1/3] =?UTF-8?q?cof.{settings,asgi}=20->=20gestioCOF.{?= =?UTF-8?q?=E2=80=A6}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- gestioCOF/asgi.py | 2 +- provisioning/bootstrap.sh | 8 ++++---- provisioning/cron.dev | 2 +- provisioning/daphne.service | 4 ++-- provisioning/worker.service | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 01f4ead2..4feb4e58 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,11 @@ Vous pouvez maintenant installer les dépendances Python depuis le fichier pip install -U pip pip install -r requirements-devel.txt -Pour terminer, copier le fichier `cof/settings/secret_example.py` vers -`cof/settings/secret.py`. Sous Linux ou Mac, préférez plutôt un lien symbolique -pour profiter de façon transparente des mises à jour du fichier: +Pour terminer, copier le fichier `gestioCOF/settings/secret_example.py` vers +`gestioCOF/settings/secret.py`. Sous Linux ou Mac, préférez plutôt un lien +symbolique pour profiter de façon transparente des mises à jour du fichier: - ln -s secret_example.py cof/settings/secret.py + ln -s secret_example.py gestioCOF/settings/secret.py #### Fin d'installation diff --git a/gestioCOF/asgi.py b/gestioCOF/asgi.py index a34621c7..5d271a25 100644 --- a/gestioCOF/asgi.py +++ b/gestioCOF/asgi.py @@ -2,6 +2,6 @@ import os from channels.asgi import get_channel_layer if "DJANGO_SETTINGS_MODULE" not in os.environ: - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cof.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gestioCOF.settings.local") channel_layer = get_channel_layer() diff --git a/provisioning/bootstrap.sh b/provisioning/bootstrap.sh index 69bbcf4c..7b19c475 100644 --- a/provisioning/bootstrap.sh +++ b/provisioning/bootstrap.sh @@ -41,11 +41,11 @@ sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -r /vagrant/requirements-devel.tx # Préparation de Django cd /vagrant -ln -s -f secret_example.py cof/settings/secret.py +ln -s -f secret_example.py gestioCOF/settings/secret.py sudo -H -u ubuntu \ - DJANGO_SETTINGS_MODULE='cof.settings.dev' \ + DJANGO_SETTINGS_MODULE='gestioCOF.settings.dev' \ bash -c ". ~/venv/bin/activate && bash provisioning/prepare_django.sh" -/home/ubuntu/venv/bin/python manage.py collectstatic --noinput --settings cof.settings.dev +/home/ubuntu/venv/bin/python manage.py collectstatic --noinput --settings gestioCOF.settings.dev # Installation du cron pour les mails de rappels sudo -H -u ubuntu crontab provisioning/cron.dev @@ -61,7 +61,7 @@ systemctl start worker.service # Mise en place du .bash_profile pour tout configurer lors du `vagrant ssh` cat >> ~ubuntu/.bashrc < Date: Sat, 28 Oct 2017 17:30:37 +0200 Subject: [PATCH 2/3] Fix postgres sequences When manually assigning a value to AutoField, sequences must be updated manually. https://docs.djangoproject.com/en/1.11/ref/databases/#manually-specifying-values-of-auto-incrementing-primary-keys --- cof/migrations/0014_move_profile.py | 6 ++++++ cof/migrations/0016_move_event.py | 7 +++++++ utils/__init__.py | 0 utils/models.py | 17 +++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 utils/__init__.py create mode 100644 utils/models.py diff --git a/cof/migrations/0014_move_profile.py b/cof/migrations/0014_move_profile.py index 344b512c..52e537eb 100644 --- a/cof/migrations/0014_move_profile.py +++ b/cof/migrations/0014_move_profile.py @@ -4,11 +4,15 @@ from __future__ import unicode_literals from django.db import migrations, models from django.db.models import F +from utils.models import sqlsequencereset + def profiles_to_gestion(apps, schema_editor): OldProfile = apps.get_model('cof', 'CofProfile') NewProfile = apps.get_model('gestion', 'Profile') + connection = schema_editor.connection + # New profiles are massively imported from the old profiles. # IDs are kept identical to ease the migration of models which were # referencing the CofProfile model. @@ -30,6 +34,8 @@ def profiles_to_gestion(apps, schema_editor): NewProfile.objects.bulk_create(new_profiles) + sqlsequencereset([NewProfile], conn=connection) + OldProfile.objects.all().update(profile_id=F('id')) diff --git a/cof/migrations/0016_move_event.py b/cof/migrations/0016_move_event.py index 60e1bbf5..033bf3a7 100644 --- a/cof/migrations/0016_move_event.py +++ b/cof/migrations/0016_move_event.py @@ -3,6 +3,8 @@ from __future__ import unicode_literals from django.db import migrations +from utils.models import sqlsequencereset + def event_to_gestion(apps, schema_editor): # Fetching the models that have be moved from cof to gestion @@ -11,6 +13,8 @@ def event_to_gestion(apps, schema_editor): Location = apps.get_model('gestion', 'Location') Association = apps.get_model('gestion', 'Association') + connection = schema_editor.connection + # The old Event.location field becomes a table: we need to create an entry # in this table for each value of the old `location` field. locations = set() # A set to prevent duplicate entries @@ -31,6 +35,8 @@ def event_to_gestion(apps, schema_editor): for event in new_events ]) + sqlsequencereset([NewEvent], conn=connection) + # Do not forget to link all the existing event to the COF association cof_assoc = Association.objects.get(name="COF") cof_assoc.events.add(*NewEvent.objects.all()) @@ -57,6 +63,7 @@ def event_to_gestion(apps, schema_editor): ToModel(**values) for values in FromModel.objects.values() ]) + sqlsequencereset([ToModel], conn=connection) class Migration(migrations.Migration): diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/utils/models.py b/utils/models.py new file mode 100644 index 00000000..9ae0a581 --- /dev/null +++ b/utils/models.py @@ -0,0 +1,17 @@ +from django.core.management.color import no_style +from django.db import connection + + +def sqlsequencereset(models, conn=connection): + """ + Update sequences of fields of `models`. + + This function should be called after manually assigning a value to an + `AutoField`. + https://docs.djangoproject.com/en/1.11/ref/databases/#manually-specifying-values-of-auto-incrementing-primary-keys + """ + sequence_sql = conn.ops.sequence_reset_sql(no_style(), models) + if sequence_sql: + with conn.cursor() as cursor: + for line in sequence_sql: + cursor.execute(line) From 09a88f768df07db86b78615da391d3bc72a2410e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sat, 28 Oct 2017 18:08:40 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Fix=20username=20conflicts=20with=20test=20?= =?UTF-8?q?suite=20and=20the=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …check_supportBDS_migrations script. --- cof/management/commands/check_olddata.py | 6 +++--- cof/migrations/0008_py3.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cof/management/commands/check_olddata.py b/cof/management/commands/check_olddata.py index 8fdac0e4..dc1ccd47 100644 --- a/cof/management/commands/check_olddata.py +++ b/cof/management/commands/check_olddata.py @@ -31,21 +31,21 @@ class Command(BaseCommand): def check_users(self): self.stdout.write("* Utilisateurs... ", ending='') - self.u1 = User.objects.get(username='user1') + self.u1 = User.objects.get(username='cbds_user1') assert self.u1.profile.login_clipper == 'user1' assert self.g_staff in self.u1.groups.all() assert self.g_members in self.u1.groups.all() assert self.u1.has_perm('cof.buro') assert self.u1.has_perm('cof.member') - self.u2 = User.objects.get(username='user2') + self.u2 = User.objects.get(username='cbds_user2') assert self.u2.profile.login_clipper == 'user2' assert self.g_staff not in self.u2.groups.all() assert self.g_members in self.u2.groups.all() assert not self.u2.has_perm('cof.buro') assert self.u2.has_perm('cof.member') - self.u3 = User.objects.get(username='user3') + self.u3 = User.objects.get(username='cbds_user3') assert self.u3.profile.login_clipper == 'user3' assert self.g_staff not in self.u3.groups.all() assert self.g_members not in self.u3.groups.all() diff --git a/cof/migrations/0008_py3.py b/cof/migrations/0008_py3.py index 99aa2f9f..b758e996 100644 --- a/cof/migrations/0008_py3.py +++ b/cof/migrations/0008_py3.py @@ -34,13 +34,13 @@ def load_olddata(apps, schema_editor): ) # Setup users. - u1 = load_user(apps, 'user1', is_cof=True) + u1 = load_user(apps, 'cbds_user1', is_cof=True) u1.profile.is_buro = True u1.profile.save() - u2 = load_user(apps, 'user2', is_cof=True) + u2 = load_user(apps, 'cbds_user2', is_cof=True) - u3 = load_user(apps, 'user3') + u3 = load_user(apps, 'cbds_user3') # Setup clubs. Club = apps.get_model('cof', 'Club')