Fix populate to work with Postgres

This commit is contained in:
Skia 2016-07-14 17:50:02 +02:00
parent e29e94711a
commit 67114f51e1
3 changed files with 13 additions and 8 deletions

View File

@ -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

View File

@ -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()

View File

@ -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')