-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve db population in development
- Loading branch information
Showing
2 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,9 @@ RADIS_SITE_NAME=radis.test | |
ADMIN_EMAIL=[email protected] | ||
ADMIN_FIRST_NAME=Wilhelm | ||
ADMIN_LAST_NAME=Roentgen | ||
ADMIN_PASSWORD=mysecret | ||
ADMIN_USERNAME=admin | ||
ADMIN_PASSWORD=mysecret | ||
ADMIN_AUTH_TOKEN = "f2e7412ca332a85e37f3fce88c6a1904fe35ad63" | ||
BASE_URL=https://localhost | ||
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 | ||
DJANGO_CSRF_TRUSTED_ORIGINS= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
|
||
USER_COUNT = 20 | ||
GROUP_COUNT = 3 | ||
ADMIN_AUTH_TOKEN = "f2e7412ca332a85e37f3fce88c6a1904fe35ad63" | ||
PACS_ITEMS = [ | ||
{"pacs_aet": "gepacs", "pacs_name": "GE PACS"}, | ||
{"pacs_aet": "synapse", "pacs_name": "Synapse"}, | ||
|
@@ -46,26 +45,35 @@ def feed_reports(): | |
feed_report(report) | ||
|
||
|
||
def create_users() -> list[User]: | ||
def create_admin() -> User: | ||
if "ADMIN_USERNAME" not in environ or "ADMIN_PASSWORD" not in environ: | ||
print("Cave! No admin credentials found in environment. Using default ones.") | ||
|
||
admin_data = { | ||
"username": environ.get("ADMIN_USERNAME", "admin"), | ||
"first_name": environ.get("ADMIN_FIRST_NAME", "Wilhelm"), | ||
"last_name": environ.get("ADMIN_LAST_NAME", "Röntgen"), | ||
"email": environ.get("ADMIN_EMAIL", "[email protected]"), | ||
"password": environ.get("ADMIN_PASSWORD", "mysecret"), | ||
} | ||
admin = AdminUserFactory.create(**admin_data) | ||
|
||
TokenFactory.create( | ||
token_hashed=hash_token(ADMIN_AUTH_TOKEN), | ||
fraction=ADMIN_AUTH_TOKEN[:FRACTION_LENGTH], | ||
owner=admin, | ||
expires=None, | ||
admin = AdminUserFactory.create( | ||
username=environ.get("ADMIN_USERNAME", "admin"), | ||
first_name=environ.get("ADMIN_FIRST_NAME", "Wilhelm"), | ||
last_name=environ.get("ADMIN_LAST_NAME", "Röntgen"), | ||
email=environ.get("ADMIN_EMAIL", "[email protected]"), | ||
password=environ.get("ADMIN_PASSWORD", "mysecret"), | ||
) | ||
|
||
if "ADMIN_AUTH_TOKEN" not in environ: | ||
print("No admin auth token in environment. Skipping auth token creation.") | ||
else: | ||
auth_token = environ["ADMIN_AUTH_TOKEN"] | ||
TokenFactory.create( | ||
token_hashed=hash_token(auth_token), | ||
fraction=auth_token[:FRACTION_LENGTH], | ||
owner=admin, | ||
expires=None, | ||
) | ||
|
||
return admin | ||
|
||
|
||
def create_users() -> list[User]: | ||
admin = create_admin() | ||
|
||
users = [admin] | ||
|
||
urgent_permissions = Permission.objects.filter( | ||
|