From 67114f51e1440de99a9bbcbbd230c9598c250817 Mon Sep 17 00:00:00 2001 From: Skia Date: Thu, 14 Jul 2016 17:50:02 +0200 Subject: [PATCH] Fix populate to work with Postgres --- club/models.py | 7 ++----- core/management/commands/populate.py | 12 ++++++++++-- core/management/commands/setup.py | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/club/models.py b/club/models.py index 99d783de..3a0bd2e8 100644 --- a/club/models.py +++ b/club/models.py @@ -50,13 +50,10 @@ class Club(models.Model): self.check_loop() def save(self): - super(Club, self).save() - try: + if self.id is None: MetaGroup(name=self.unix_name+settings.SITH_BOARD_SUFFIX).save() MetaGroup(name=self.unix_name+settings.SITH_MEMBER_SUFFIX).save() - except IntegrityError as e: - # Groups already exists - pass + super(Club, self).save() def __str__(self): return self.name diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index dde1e372..f1b6c0a8 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -1,9 +1,11 @@ import os from datetime import date +from io import StringIO from django.core.management.base import BaseCommand, CommandError from django.core.management import call_command from django.conf import settings +from django.db import connection from core.models import Group, User, Page, PageRev @@ -19,15 +21,21 @@ class Command(BaseCommand): parser.add_argument('--prod', action="store_true") def handle(self, *args, **options): + os.environ['DJANGO_COLORS'] = 'nocolor' root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + for g in settings.SITH_GROUPS.values(): + Group(id=g['id'], name=g['name']).save() + sqlcmd = StringIO() + call_command("sqlsequencereset", "core", "auth", stdout=sqlcmd) + cursor = connection.cursor() + print(sqlcmd.getvalue()) + cursor.execute(sqlcmd.getvalue()) root = User(username='root', last_name="", first_name="Bibou", email="ae.info@utbm.fr", date_of_birth="1942-06-12", is_superuser=True, is_staff=True) root.set_password("plop") root.save() - for g in settings.SITH_GROUPS.values(): - Group(id=g['id'], name=g['name']).save() ae = Club(name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'], address=settings.SITH_MAIN_CLUB['address']) ae.save() diff --git a/core/management/commands/setup.py b/core/management/commands/setup.py index 19b45313..6f4a3e13 100755 --- a/core/management/commands/setup.py +++ b/core/management/commands/setup.py @@ -13,10 +13,10 @@ class Command(BaseCommand): def handle(self, *args, **options): root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) try: - os.unlink(os.path.join(root_path, 'db.sqlite3')) os.mkdir(os.path.join(root_path)+'/data') except Exception as e: print(e) + call_command('flush') call_command('migrate') if options['prod']: call_command('populate', '--prod')