mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Fix populate to work with Postgres
This commit is contained in:
parent
e29e94711a
commit
67114f51e1
@ -50,13 +50,10 @@ class Club(models.Model):
|
|||||||
self.check_loop()
|
self.check_loop()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
super(Club, self).save()
|
if self.id is None:
|
||||||
try:
|
|
||||||
MetaGroup(name=self.unix_name+settings.SITH_BOARD_SUFFIX).save()
|
MetaGroup(name=self.unix_name+settings.SITH_BOARD_SUFFIX).save()
|
||||||
MetaGroup(name=self.unix_name+settings.SITH_MEMBER_SUFFIX).save()
|
MetaGroup(name=self.unix_name+settings.SITH_MEMBER_SUFFIX).save()
|
||||||
except IntegrityError as e:
|
super(Club, self).save()
|
||||||
# Groups already exists
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import connection
|
||||||
|
|
||||||
|
|
||||||
from core.models import Group, User, Page, PageRev
|
from core.models import Group, User, Page, PageRev
|
||||||
@ -19,15 +21,21 @@ class Command(BaseCommand):
|
|||||||
parser.add_argument('--prod', action="store_true")
|
parser.add_argument('--prod', action="store_true")
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
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__))))
|
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",
|
root = User(username='root', last_name="", first_name="Bibou",
|
||||||
email="ae.info@utbm.fr",
|
email="ae.info@utbm.fr",
|
||||||
date_of_birth="1942-06-12",
|
date_of_birth="1942-06-12",
|
||||||
is_superuser=True, is_staff=True)
|
is_superuser=True, is_staff=True)
|
||||||
root.set_password("plop")
|
root.set_password("plop")
|
||||||
root.save()
|
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'],
|
ae = Club(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'])
|
||||||
ae.save()
|
ae.save()
|
||||||
|
@ -13,10 +13,10 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||||
try:
|
try:
|
||||||
os.unlink(os.path.join(root_path, 'db.sqlite3'))
|
|
||||||
os.mkdir(os.path.join(root_path)+'/data')
|
os.mkdir(os.path.join(root_path)+'/data')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
call_command('flush')
|
||||||
call_command('migrate')
|
call_command('migrate')
|
||||||
if options['prod']:
|
if options['prod']:
|
||||||
call_command('populate', '--prod')
|
call_command('populate', '--prod')
|
||||||
|
Loading…
Reference in New Issue
Block a user