mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2024-12-27 01:42:24 +00:00
flush before import and nice output
This commit is contained in:
parent
c295cfe7db
commit
44b27e3ab3
@ -1,6 +1,7 @@
|
||||
#!/usr/env/bin python3
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management import call_command
|
||||
from django.utils import timezone
|
||||
import psycopg2 as pg
|
||||
import psycopg2.extras as pge
|
||||
@ -187,30 +188,38 @@ class Command(BaseCommand):
|
||||
Command for importing the database of NK15.
|
||||
Need to be run by a user with a registered role in postgres for the database nk15.
|
||||
"""
|
||||
def print_success(self,to_print):
|
||||
return self.stdout.write(self.style.SUCCESS(to_print))
|
||||
|
||||
def add_arguments(self,parser):
|
||||
parser.add_argument('-s', '--special', action = 'store_true')
|
||||
parser.add_argument('-c', '--comptes', action = 'store_true')
|
||||
parser.add_argument('-b', '--boutons', action = 'store_true')
|
||||
parser.add_argument('-t', '--transactions', action = 'store_true')
|
||||
parser.add_argument('-a', '--aliases', action = 'store_true')
|
||||
|
||||
parser.add_argument('-s', '--special', action = 'store_true', help="create Minimum instance (special note and clubs)")
|
||||
parser.add_argument('-c', '--comptes', action = 'store_true', help="import accounts")
|
||||
parser.add_argument('-b', '--boutons', action = 'store_true', help="import boutons")
|
||||
parser.add_argument('-t', '--transactions', action = 'store_true',help="import transaction")
|
||||
parser.add_argument('-a', '--aliases', action = 'store_true',help="import aliases")
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
#reset database.
|
||||
call_command("flush")
|
||||
self.print_success("flush nk20 database")
|
||||
# connecting to nk15 database
|
||||
conn = pg.connect(database="nk15",user="nk15_user")
|
||||
cur = conn.cursor(cursor_factory = pge.DictCursor)
|
||||
|
||||
if kwargs["special"]:
|
||||
map_idbde = import_special(cur)
|
||||
print("Minimal setup created")
|
||||
self.print_success("Minimal setup created")
|
||||
|
||||
if kwargs["comptes"]:
|
||||
map_idbde = import_comptes(cur,map_idbde)
|
||||
print("comptes table imported")
|
||||
self.print_success("comptes table imported")
|
||||
|
||||
if kwargs["boutons"]:
|
||||
import_boutons(cur,map_idbde)
|
||||
print("boutons table imported")
|
||||
self.print_success("boutons table imported")
|
||||
if kwargs["transactions"]:
|
||||
import_transaction(cur)
|
||||
import_transaction(cur,map_idbde)
|
||||
self.print_success("transaction imported")
|
||||
if kwargs["aliases"]:
|
||||
import_aliases(cur,map_idbde)
|
||||
print("aliases imported")
|
||||
self.print_success("aliases imported")
|
||||
|
Loading…
Reference in New Issue
Block a user