summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspl3g <spleefer6@gmail.com>2026-05-31 16:12:10 +0300
committerspl3g <spleefer6@gmail.com>2026-05-31 16:12:10 +0300
commit611f3017c00dd9a220402489602defab66f2c9f0 (patch)
tree8e068f6100e8a0aab1ffb3aa0c6878651ea28103
parentd2e7e7141037377d293b00e691fa835694783f26 (diff)
add login and products views
-rw-r--r--config/settings.py7
-rw-r--r--config/urls.py11
-rw-r--r--core/templates/core/base.html41
-rw-r--r--core/templates/core/login.html31
-rw-r--r--core/templates/core/product_list.html41
-rw-r--r--core/views.py12
6 files changed, 140 insertions, 3 deletions
diff --git a/config/settings.py b/config/settings.py
index ed0ea02..8ba7d50 100644
--- a/config/settings.py
+++ b/config/settings.py
@@ -80,7 +80,7 @@ DATABASES = {
"USER": "postgres",
"PASSWORD": "123456",
"HOST": "localhost",
- "PORT": "5445",
+ "PORT": "4444",
}
}
@@ -120,5 +120,8 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.0/howto/static-files/
+STATIC_URL = "static/"
+STATICFILES_DIRS = [BASE_DIR / "static"]
+MEDIA_URL = "/media/"
+MEDIA_ROOT = BASE_DIR / "media"
-STATIC_URL = 'static/'
diff --git a/config/urls.py b/config/urls.py
index 56f8c8c..ff27744 100644
--- a/config/urls.py
+++ b/config/urls.py
@@ -16,7 +16,18 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
+from django.contrib.auth.views import LogoutView
+from django.conf import settings
+from django.conf.urls.static import static
+
+from core.views import UserLoginView, ProductListView
urlpatterns = [
path('admin/', admin.site.urls),
+ path("", UserLoginView.as_view(), name="login"),
+ path("logout/", LogoutView.as_view(), name="logout"),
+ path("products/", ProductListView.as_view(), name="products"),
]
+
+if settings.DEBUG:
+ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
diff --git a/core/templates/core/base.html b/core/templates/core/base.html
new file mode 100644
index 0000000..56d9e17
--- /dev/null
+++ b/core/templates/core/base.html
@@ -0,0 +1,41 @@
+{% load static %}
+
+<!DOCTYPE html>
+<head>
+ <meta charset="utf-8">
+ <title>{% block title %}ООО «Обувь»{% endblock %}</title>
+ <link rel="stylesheet" href="{% static 'css/style.css' %}">
+</head>
+
+<body>
+ <header>
+ <div class="header-left">
+ <span>оОобувь</span>
+ </div>
+ <div class="header-right">
+ {% if user.is_authenticated %}
+ <span>{{ user.role.name }}</span>
+ <strong>{{ user.full_name }}</strong>
+ <form action="{% url 'logout' %}" method="post" style="display: inline;">
+ {% csrf_token %}
+ <button class="logout-button" type="submit">Выйти</button>
+ </form>
+ {% else %}
+ <span class="role-badge">Гость</span> |
+ <a href="{% url 'login' %}">Войти</a>
+ {% endif %}
+ </div>
+ </header>
+
+ <div class="container">
+ <h1>{% block h1 %}{% endblock %}</h1>
+
+ {% if messages %}
+ {% for message in messages %}
+ <div class="alert alert-{{ message.tags }}">{{message}}</div>
+ {% endfor %}
+ {% endif %}
+
+ {% block content %}{% endblock %}
+ </div>
+</body>
diff --git a/core/templates/core/login.html b/core/templates/core/login.html
new file mode 100644
index 0000000..c17f521
--- /dev/null
+++ b/core/templates/core/login.html
@@ -0,0 +1,31 @@
+{% extends 'core/base.html' %}
+
+{% block title %}Авторизация - ООобувь{% endblock %}
+{% block h1 %}Вход в систему{% endblock %}
+
+{% block content %}
+<div>
+ <form method="post">
+ {% csrf_token %}
+ {% if form.errors %}
+ <div>
+ {% for field in form %}
+ {% for error in field.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endfor %}
+
+ {% for error in form.non_field_errors %}
+ {{ error }}
+ {% endfor %}
+ </div>
+ {% endif %}
+
+ <label>Почта:</label>
+ <input type="text" name="username">
+ <label>Пароль:</label>
+ <input type="password" name="password">
+ <button type="submit" class="btn">Войти</button>
+ </form>
+</div>
+{% endblock %}
diff --git a/core/templates/core/product_list.html b/core/templates/core/product_list.html
new file mode 100644
index 0000000..ac4b8c7
--- /dev/null
+++ b/core/templates/core/product_list.html
@@ -0,0 +1,41 @@
+{% extends 'core/base.html' %}
+{% load static %}
+
+{% block title %}Список товаров - ООбувь{% endblock %}
+{% block h1 %}Каталог товаров{% endblock %}
+
+{% block content %}
+<div>
+ {% for product in products %}
+ <div class="product-card
+ {% if product.discount > 15 %}sale{% endif %}
+ {% if product.quantity == 0 %}out-of-stock{% endif %}">
+ {% if product.photo %}
+ <img src="{{ product.photo.url }}" class="image" alt="{{ product.name }}">
+ {% else %}
+ <img src="{% static 'images/picture.png' %}" class="image" alt="Заглушка">
+ {% endif %}
+ <div class="details">
+ <strong>{{product.category}} | {{product.name}}</strong>
+ <br/>
+ Описание товара: {{ product.description }}
+ <br/>
+ Производитель: {{ product.manufacturer }}
+ <br/>
+ Поставщик: {{ product.supplier.name }}
+ <br/>
+ {% if product.discount > 0 %}
+ Цена: <span class="old-price">{{ product.price }}</span> {{ product.final_price|floatformat:2 }} руб.
+ {% else %}
+ Цена: {{ product.price }} руб.
+ {% endif %}
+ <br/>
+ Единица измерения: {{ product.unit }}
+ <br/>
+ Колличество на складе: {{ product.discount }}
+ </div>
+ <div class="sale">{{ product.discount }}</div>
+ </div>
+ {% endfor %}
+</div>
+{% endblock %}
diff --git a/core/views.py b/core/views.py
index 91ea44a..6957abc 100644
--- a/core/views.py
+++ b/core/views.py
@@ -1,3 +1,13 @@
from django.shortcuts import render
+from django.views.generic import ListView
+from django.contrib.auth.views import LoginView
-# Create your views here.
+from .models import Product
+
+class UserLoginView(LoginView):
+ template_name = "core/login.html"
+
+class ProductListView(ListView):
+ model = Product
+ template_name = "core/product_list.html"
+ context_object_name = "products"