diff options
| author | spl3g <spleefer6@gmail.com> | 2026-05-31 16:12:10 +0300 |
|---|---|---|
| committer | spl3g <spleefer6@gmail.com> | 2026-05-31 16:12:10 +0300 |
| commit | 611f3017c00dd9a220402489602defab66f2c9f0 (patch) | |
| tree | 8e068f6100e8a0aab1ffb3aa0c6878651ea28103 /core | |
| parent | d2e7e7141037377d293b00e691fa835694783f26 (diff) | |
add login and products views
Diffstat (limited to 'core')
| -rw-r--r-- | core/templates/core/base.html | 41 | ||||
| -rw-r--r-- | core/templates/core/login.html | 31 | ||||
| -rw-r--r-- | core/templates/core/product_list.html | 41 | ||||
| -rw-r--r-- | core/views.py | 12 |
4 files changed, 124 insertions, 1 deletions
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" |
