Skip to content

Commit 2eb8d3f

Browse files
committed
Fixes and tweaks
1 parent 2547543 commit 2eb8d3f

File tree

8 files changed

+104
-58
lines changed

8 files changed

+104
-58
lines changed

.env.example.dev

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Type hints based on parameter naming #####
2+
#
3+
# booleans: [<app_name>_] VERB_...
4+
# [<app_name>_] ALLOW_... | ENABLE_... | FAIL_... | HAS_...
5+
# | INCLUDE_... | IS_... | RUN_... | USE_... | ..._DEBUG
6+
#
7+
# numbers: [<app_name>_] ..._QUANTITY-NOUN
8+
# [<app_name>_] ..._COUNT | ..._NUMBER | ..._RATE | ..._TOTAL
9+
#
10+
# strings: Everything else
11+
112
# api deployment
213
ENVIRONMENT=development
314
API_PORT=8030

.env.example.prod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Type hints based on parameter naming #####
2+
#
3+
# booleans: [<app_name>_] VERB_...
4+
# [<app_name>_] ALLOW_... | ENABLE_... | FAIL_... | HAS_...
5+
# | INCLUDE_... | IS_... | RUN_... | USE_... | ..._DEBUG
6+
#
7+
# numbers: [<app_name>_] ..._QUANTITY-NOUN
8+
# [<app_name>_] ..._COUNT | ..._NUMBER | ..._RATE | ..._TOTAL
9+
#
10+
# strings: Everything else
11+
112
# api deployment
213
ENVIRONMENT=production
314
API_PORT=8030

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ docker-compose up
292292
You should be able to access the local environment site and admin at the following URLs:
293293
294294
- <http://localhost:8030/api/v1/>
295-
- <http://localhost:8030/admin/>
295+
- <http://localhost:8030/>
296296
297297
If you have problems starting the project, first check out
298298
the [FAQ](https://github.com/code4romania/seismic-risc/wiki/FAQ) and if that doesn't work, ask someone from the

backend/seismic_site/urls.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@
2727
i18n_patterns(
2828
# URL patterns which accept a language prefix
2929
path(
30-
"admin/password_reset/",
30+
"password_reset/",
3131
auth_views.PasswordResetView.as_view(),
3232
name="admin_password_reset",
3333
),
3434
path(
35-
"admin/password_reset/done/",
35+
"password_reset/done/",
3636
auth_views.PasswordResetDoneView.as_view(),
3737
name="password_reset_done",
3838
),
3939
path(
40-
"admin/reset/<uidb64>/<token>/",
40+
"reset/<uidb64>/<token>/",
4141
auth_views.PasswordResetConfirmView.as_view(),
4242
name="password_reset_confirm",
4343
),
4444
path(
45-
"admin/reset/done/",
45+
"reset/done/",
4646
auth_views.PasswordResetCompleteView.as_view(),
4747
name="password_reset_complete",
4848
),
49-
path("admin/", admin.site.urls),
49+
path("", admin.site.urls),
5050
)
5151
+ [
5252
# URL patterns which do not use a language prefix

backend/utils/management/commands/_private/__init__.py

Whitespace-only changes.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import logging
2+
3+
from django.contrib.auth import get_user_model
4+
from django.core.management.base import BaseCommand
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
class CommonCreateUserCommand(BaseCommand):
10+
def add_arguments(self, parser):
11+
parser.add_argument(
12+
"--username",
13+
type=str,
14+
help="Username of the superuser (default: email)",
15+
required=False,
16+
)
17+
parser.add_argument(
18+
"--first_name",
19+
type=str,
20+
help="First name of the superuser",
21+
required=False,
22+
)
23+
parser.add_argument(
24+
"--last_name",
25+
type=str,
26+
help="Last name of the superuser",
27+
required=False,
28+
)
29+
30+
@classmethod
31+
def _create_user(
32+
cls,
33+
admin_email: str,
34+
password: str,
35+
is_superuser: bool,
36+
is_staff: bool,
37+
username: str = None,
38+
first_name: str = "Admin",
39+
last_name: str = "Admin",
40+
):
41+
if not password:
42+
raise ValueError("Password is required. Please set the proper variables.")
43+
44+
user_model = get_user_model()
45+
46+
if user_model.objects.filter(email=admin_email).exists():
47+
logger.warning("Super admin already exists")
48+
return None
49+
50+
user = user_model(
51+
email=admin_email,
52+
username=username or admin_email,
53+
first_name=first_name,
54+
last_name=last_name,
55+
is_active=True,
56+
is_superuser=is_superuser,
57+
is_staff=is_staff,
58+
)
59+
user.set_password(password)
60+
61+
user.save()
62+
63+
logger.info("Super admin created successfully")
64+
65+
return user
Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,27 @@
11
import logging
22

3-
import environ
4-
from django.contrib.auth import get_user_model
5-
from django.core.management.base import BaseCommand
3+
from django.conf import settings
4+
5+
from ._private.seed_user import CommonCreateUserCommand
66

77
logger = logging.getLogger(__name__)
88

99

10-
class Command(BaseCommand):
10+
class Command(CommonCreateUserCommand):
1111
help = "Command to create a superuser"
1212

13-
def add_arguments(self, parser):
14-
parser.add_argument(
15-
"--email",
16-
type=str,
17-
help="Email of the superuser",
18-
required=True,
19-
)
20-
parser.add_argument(
21-
"--username",
22-
type=str,
23-
help="Username of the superuser (default: email)",
24-
required=False,
25-
)
26-
parser.add_argument(
27-
"--first_name",
28-
type=str,
29-
help="First name of the superuser",
30-
required=False,
31-
)
32-
parser.add_argument(
33-
"--last_name",
34-
type=str,
35-
help="Last name of the superuser",
36-
required=False,
37-
)
38-
3913
def handle(self, *args, **kwargs):
40-
user_model = get_user_model()
41-
env = environ.Env()
42-
43-
admin_email = kwargs.get("email")
44-
admin_username = kwargs.get("username") or admin_email
45-
admin_first_name = kwargs.get("first_name") or ""
46-
admin_last_name = kwargs.get("last_name") or ""
47-
48-
if user_model.objects.filter(email=admin_email).exists():
49-
logger.info("Super admin already exists")
50-
return 0
14+
kwargs["last_name"] = "Super"
15+
kwargs["first_name"] = "User"
5116

52-
superuser = user_model(
53-
email=admin_email,
54-
username=admin_username,
55-
first_name=admin_first_name,
56-
last_name=admin_last_name,
57-
is_active=True,
17+
self._create_user(
18+
admin_email=settings.DJANGO_ADMIN_EMAIL,
19+
password=settings.DJANGO_ADMIN_PASSWORD,
5820
is_superuser=True,
5921
is_staff=True,
22+
first_name=kwargs.get("first_name", ""),
23+
last_name=kwargs.get("last_name", ""),
6024
)
61-
superuser.set_password(env.str("DJANGO_ADMIN_PASSWORD"))
62-
63-
superuser.save()
64-
6525
logger.info("Super admin created successfully")
6626

6727
return 0

docker/s6-rc.d/init/init.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ if is_enabled "${RUN_CREATE_SUPER_USER:-False}"; then
4848
echo "Running the superuser seed script"
4949

5050
python3 manage.py seed_superuser \
51-
--email "${DJANGO_ADMIN_EMAIL}" \
5251
--first_name "${DJANGO_ADMIN_FIRST_NAME}" \
5352
--last_name "${DJANGO_ADMIN_LAST_NAME}"
5453
fi

0 commit comments

Comments
 (0)