summaryrefslogtreecommitdiffstats
path: root/databaseReset.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-04-06 00:49:09 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2021-04-06 00:49:09 +0100
commitd1cd72c5f88c581b8e446f3c92c0eb093500c60e (patch)
tree0b40a627ee461f1d03ca4b1a94e0c09d67b55e32 /databaseReset.py
parent6d6bec35f271b5ff072a884fbfc31f5b9cb36642 (diff)
downloadtroggle-d1cd72c5f88c581b8e446f3c92c0eb093500c60e.tar.gz
troggle-d1cd72c5f88c581b8e446f3c92c0eb093500c60e.tar.bz2
troggle-d1cd72c5f88c581b8e446f3c92c0eb093500c60e.zip
New user login/logoff system using standard Dj
Diffstat (limited to 'databaseReset.py')
-rw-r--r--databaseReset.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/databaseReset.py b/databaseReset.py
index 1d66706..9151a43 100644
--- a/databaseReset.py
+++ b/databaseReset.py
@@ -6,7 +6,6 @@ import json
import resource
import settings
-import credentials
""" Command-line utility for loading cave data files into troggle's database.
The command line options select which combination of classes of data will be imported,
@@ -56,9 +55,13 @@ if os.geteuid() == 0:
exit()
expouser=settings.EXPOUSER
-expouserpass=credentials.EXPOUSERPASS
+expouserpass=settings.EXPOUSERPASS
expouseremail=settings.EXPOUSER_EMAIL
+expoadminuser=settings.EXPOADMINUSER
+expoadminuserpass=settings.EXPOADMINUSERPASS
+expoadminuseremail=settings.EXPOADMINUSER_EMAIL
+
def reinit_db():
"""Rebuild database from scratch. Deletes the file first if sqlite is used,
otherwise it drops the database and creates it.
@@ -109,9 +112,28 @@ def reinit_db():
print("users in db already: ",len(User.objects.all()))
with transaction.atomic():
try:
- print(" - Setting up admin user on: " + django.db.connections.databases['default']['NAME'])
+ print(" - Setting up expo user on: " + django.db.connections.databases['default']['NAME'])
print(" - user: {} ({:.5}...) <{}> ".format(expouser, expouserpass, expouseremail))
user = User.objects.create_user(expouser, expouseremail, expouserpass)
+ user.is_staff = False
+ user.is_superuser = False
+ user.save()
+ except:
+ print(" ! INTEGRITY ERROR user on: " + settings.DATABASES['default']['NAME'])
+ print(django.db.connections.databases['default']['NAME'])
+ print(" ! You probably have not got a clean db when you thought you had.\n")
+ print(" ! Also you are probably NOT running an in-memory db now.\n")
+ print("users in db: ",len(User.objects.all()))
+ print("tables in db: ",len(connection.introspection.table_names()))
+ memdumpsql(fn='integrityfail.sql')
+ django.db.connections.databases['default']['NAME'] = ':memory:'
+ #raise
+
+ with transaction.atomic():
+ try:
+ print(" - Setting up expoadmin user on: " + django.db.connections.databases['default']['NAME'])
+ print(" - user: {} ({:.5}...) <{}> ".format(expoadminuser, expoadminuserpass, expoadminuseremail))
+ user = User.objects.create_user(expoadminuser, expoadminuseremail, expoadminuserpass)
user.is_staff = True
user.is_superuser = True
user.save()