Commit 67114f51 authored by Skia's avatar Skia

Fix populate to work with Postgres

parent e29e9471
......@@ -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
......
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()
......
......@@ -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')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment