Skip to content

Commit e09f322

Browse files
Intermediate commit
1 parent e0d509c commit e09f322

File tree

183 files changed

+40784
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+40784
-12
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from django.contrib.auth import get_user_model
2+
from django.core.management.base import BaseCommand
3+
4+
from account.models import Profile
5+
6+
User = get_user_model()
7+
8+
9+
class Command(BaseCommand):
10+
help = 'Create a superuser with default credentials ([email protected] / admin) and activated status and profile'
11+
12+
def handle(self, *args, **options):
13+
14+
username = 'admin'
15+
password = 'admin'
16+
first_name = 'Admin'
17+
last_name = 'User'
18+
19+
# Check if user already exists
20+
if User.objects.filter(email=email).exists():
21+
self.stdout.write(
22+
self.style.ERROR(f'User with email "{email}" already exists.')
23+
)
24+
return
25+
26+
if User.objects.filter(username=username).exists():
27+
self.stdout.write(
28+
self.style.ERROR(f'User with username "{username}" already exists.')
29+
)
30+
return
31+
32+
try:
33+
# Create superuser
34+
user = User.objects.create_superuser(
35+
email=email,
36+
username=username,
37+
password=password,
38+
first_name=first_name,
39+
last_name=last_name,
40+
is_active=True # Ensure user is activated
41+
)
42+
43+
# Create profile for the user
44+
profile, created = Profile.objects.get_or_create(
45+
user=user,
46+
defaults={'balance': 0.0}
47+
)
48+
49+
self.stdout.write(
50+
self.style.SUCCESS(
51+
f'Successfully created superuser "{username}" with email "{email}"'
52+
)
53+
)
54+
self.stdout.write(
55+
self.style.SUCCESS(f'User is active: {user.is_active}')
56+
)
57+
self.stdout.write(
58+
self.style.SUCCESS(f'Profile created: {created}')
59+
)
60+
61+
except Exception as e:
62+
self.stdout.write(
63+
self.style.ERROR(f'Error creating superuser: {str(e)}')
64+
)

config/nginx/default.conf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# upstream for Uvicorn
2+
upstream uvicorn_app {
3+
server web:8000;
4+
}
5+
6+
server {
7+
listen 80;
8+
server_name www.ecommerce.com ecommerce.com;
9+
error_log stderr warn;
10+
access_log /dev/stdout main;
11+
12+
# Static files - must come before the general / location
13+
location /static/ {
14+
alias /code/staticfiles/;
15+
expires 30d;
16+
add_header Cache-Control "public, immutable";
17+
try_files $uri $uri/ =404;
18+
}
19+
20+
# Media files
21+
location /media/ {
22+
alias /code/media/;
23+
expires 30d;
24+
add_header Cache-Control "public";
25+
try_files $uri $uri/ =404;
26+
}
27+
28+
# All other requests go to Django
29+
location / {
30+
proxy_pass http://uvicorn_app;
31+
proxy_set_header Host $host;
32+
proxy_set_header X-Real-IP $remote_addr;
33+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
34+
proxy_set_header X-Forwarded-Proto $scheme;
35+
36+
# WebSocket support
37+
proxy_http_version 1.1;
38+
proxy_set_header Upgrade $http_upgrade;
39+
proxy_set_header Connection "upgrade";
40+
}
41+
}

config/nginx/default.conf.template

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ server {
99
error_log stderr warn;
1010
access_log /dev/stdout main;
1111

12+
# Static files - must come before the general / location
13+
location /static/ {
14+
alias /code/staticfiles/;
15+
expires 30d;
16+
add_header Cache-Control "public, immutable";
17+
try_files $uri $uri/ =404;
18+
}
19+
20+
# Media files
21+
location /media/ {
22+
alias /code/media/;
23+
expires 30d;
24+
add_header Cache-Control "public";
25+
try_files $uri $uri/ =404;
26+
}
27+
28+
# All other requests go to Django
1229
location / {
1330
proxy_pass http://uvicorn_app;
1431
proxy_set_header Host $host;
@@ -21,12 +38,4 @@ server {
2138
proxy_set_header Upgrade $http_upgrade;
2239
proxy_set_header Connection "upgrade";
2340
}
24-
25-
location /static/ {
26-
alias /code/static/;
27-
}
28-
29-
location /media/ {
30-
alias /code/media/;
31-
}
3241
}

create_dirs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
os.makedirs('P:/0_Programming/ecommerce_api/account/management/commands', exist_ok=True)
4+
os.makedirs('P:/0_Programming/ecommerce_api/shop/management/commands', exist_ok=True)

docker-compose.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ services:
4343
build: .
4444
container_name: backend
4545
command: [ "./wait-for-it.sh", "database:5432", "--",
46-
"sh", "-c", "python manage.py migrate && uvicorn ecommerce_api.asgi:application --host 0.0.0.0 --port 8000 --reload" ]
46+
"sh", "-c", "python manage.py migrate && python manage.py collectstatic --noinput && ls -l /code/staticfiles/ && uvicorn ecommerce_api.asgi:application --host 0.0.0.0 --port 8000 --reload" ]
4747
restart: always
4848
volumes:
4949
- .:/code
50+
- static_volume:/code/staticfiles
51+
- media_volume:/code/media
5052
ports:
5153
- "8000:8000"
5254
env_file:
@@ -61,7 +63,7 @@ services:
6163
container_name: nginx
6264
restart: always
6365
volumes:
64-
- ./config/nginx:/etc/nginx/templates
66+
- ./config/nginx/default.conf:/etc/nginx/conf.d/default.conf
6567
- .:/code
6668
ports:
6769
- "80:80"
@@ -70,4 +72,6 @@ services:
7072
- web
7173

7274
volumes:
73-
database:
75+
database:
76+
static_volume:
77+
media_volume:

ecommerce_api/settings/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# SECURITY WARNING: don't run with debug turned on in production!
1717
DEBUG = True
1818

19-
ALLOWED_HOSTS = []
19+
ALLOWED_HOSTS = ['*'] # Allow all hosts in development - restrict in production
2020

2121
# CSRF_TRUSTED_ORIGINS = [
2222
# 'http://localhost:3000'
@@ -161,6 +161,12 @@
161161
# https://docs.djangoproject.com/en/5.2/howto/static-files/
162162

163163
STATIC_URL = 'static/'
164+
STATIC_ROOT = BASE_DIR / 'staticfiles'
165+
166+
# Additional locations of static files
167+
# STATICFILES_DIRS = [
168+
# BASE_DIR / 'static',
169+
# ]
164170

165171
# Default primary key field type
166172
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

refresh_collation.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER DATABASE "Luqta_db" REFRESH COLLATION VERSION;

0 commit comments

Comments
 (0)