картинки в одну высоту, добавил вывод времени
All checks were successful
Auto-Deploy-Shop / deploy (push) Successful in 7s
All checks were successful
Auto-Deploy-Shop / deploy (push) Successful in 7s
генерации и переменной среды
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,4 +6,5 @@ db.sqlite3
|
|||||||
.env
|
.env
|
||||||
staticfiles/
|
staticfiles/
|
||||||
media/
|
media/
|
||||||
.vscode
|
.vscode
|
||||||
|
.venv/
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<div class="col-md-4 mb-4">
|
<div class="col-md-4 mb-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
{% if product.image %}
|
{% if product.image %}
|
||||||
<img src="{{ product.image.url }}" class="card-img-top" alt="{{ product.name }}">
|
<img src="{{ product.image.url }}" class="card-img-top product-img" alt="{{ product.name }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">{{ product.name }}</h5>
|
<h5 class="card-title">{{ product.name }}</h5>
|
||||||
|
|||||||
@@ -1,11 +1,34 @@
|
|||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.template.loader import render_to_string
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from .models import Product
|
from .models import Product
|
||||||
|
|
||||||
|
|
||||||
def product_list(request):
|
def product_list(request):
|
||||||
items = Product.objects.all()
|
|
||||||
env_type = os.getenv("ENV_TYPE", "undefined")
|
env_type = os.getenv("ENV_TYPE", "undefined")
|
||||||
return render(request, 'products/list.html', {
|
|
||||||
|
# Measure DB query time (force evaluation)
|
||||||
|
db_start = time.time()
|
||||||
|
items = list(Product.objects.all())
|
||||||
|
db_time = time.time() - db_start
|
||||||
|
|
||||||
|
# First render to measure render time
|
||||||
|
ctx = {
|
||||||
'products': items,
|
'products': items,
|
||||||
'env_type': env_type
|
'env_type': env_type,
|
||||||
})
|
'db_time': db_time,
|
||||||
|
'total_time': None,
|
||||||
|
}
|
||||||
|
|
||||||
|
render_start = time.time()
|
||||||
|
_ = render_to_string('products/list.html', ctx, request=request)
|
||||||
|
render_time = time.time() - render_start
|
||||||
|
|
||||||
|
total_time = db_time + render_time
|
||||||
|
|
||||||
|
# Final render with measured times
|
||||||
|
ctx['total_time'] = total_time
|
||||||
|
html = render_to_string('products/list.html', ctx, request=request)
|
||||||
|
return HttpResponse(html)
|
||||||
|
|||||||
55
scripts/init_project.ps1
Normal file
55
scripts/init_project.ps1
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
param(
|
||||||
|
[string]$Username = "ack",
|
||||||
|
[string]$Email = "admin@example.com",
|
||||||
|
[string]$Password = "123"
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Initializing project environment..."
|
||||||
|
|
||||||
|
if (-not (Test-Path ".venv")) {
|
||||||
|
Write-Host "Creating virtual environment .venv..."
|
||||||
|
python -m venv .venv
|
||||||
|
} else {
|
||||||
|
Write-Host "Virtual environment .venv already exists."
|
||||||
|
}
|
||||||
|
|
||||||
|
$venvPython = Join-Path -Path ".venv" -ChildPath "Scripts\python.exe"
|
||||||
|
$venvPip = Join-Path -Path ".venv" -ChildPath "Scripts\pip.exe"
|
||||||
|
|
||||||
|
Write-Host "Upgrading pip and installing requirements..."
|
||||||
|
& $venvPython -m pip install --upgrade pip
|
||||||
|
& $venvPip install -r requirements.txt
|
||||||
|
|
||||||
|
Write-Host "Applying database migrations..."
|
||||||
|
& $venvPython manage.py migrate
|
||||||
|
|
||||||
|
Write-Host "Collecting static files..."
|
||||||
|
& $venvPython manage.py collectstatic --noinput
|
||||||
|
|
||||||
|
if (-not $Password) {
|
||||||
|
$secure = Read-Host "Enter superuser password (input hidden)" -AsSecureString
|
||||||
|
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
|
||||||
|
$plainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
|
||||||
|
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
|
||||||
|
} else {
|
||||||
|
$plainPassword = $Password
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Creating superuser (if it doesn't exist)..."
|
||||||
|
$createUserPy = @"
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
User = get_user_model()
|
||||||
|
username = '$Username'
|
||||||
|
email = '$Email'
|
||||||
|
password = '$plainPassword'
|
||||||
|
if not User.objects.filter(username=username).exists():
|
||||||
|
User.objects.create_superuser(username=username, email=email, password=password)
|
||||||
|
print('Superuser created.')
|
||||||
|
else:
|
||||||
|
print('Superuser already exists.')
|
||||||
|
"@
|
||||||
|
|
||||||
|
# pipe the python snippet into manage.py shell
|
||||||
|
$createUserPy | & $venvPython manage.py shell
|
||||||
|
|
||||||
|
Write-Host "Initialization complete. You can now run the development server with: .\.venv\Scripts\python.exe manage.py runserver"
|
||||||
@@ -7,6 +7,14 @@
|
|||||||
<title>{% block title %}Мой проект{% endblock %}</title>
|
<title>{% block title %}Мой проект{% endblock %}</title>
|
||||||
<!-- Bootstrap CSS -->
|
<!-- Bootstrap CSS -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
/* Uniform product image size */
|
||||||
|
.product-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 200px;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% block extra_css %}{% endblock %}
|
{% block extra_css %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -2,5 +2,10 @@
|
|||||||
<footer class="bg-dark text-white text-center py-4 mt-5">
|
<footer class="bg-dark text-white text-center py-4 mt-5">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p>© 2023 Мой проект. Все права защищены.</p>
|
<p>© 2023 Мой проект. Все права защищены.</p>
|
||||||
|
<p class="small mb-0">
|
||||||
|
ENV: {{ env_type|default:"unknown" }}
|
||||||
|
| Page generated in {{ total_time|default:"-"|floatformat:3 }}s
|
||||||
|
(DB: {{ db_time|default:"-"|floatformat:3 }}s)
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
@@ -15,6 +15,9 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/admin">Админка</a>
|
||||||
|
</li>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="#">Выход</a>
|
<a class="nav-link" href="#">Выход</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user