gr421_isghdo 1 年之前
當前提交
1d20fdb85d

+ 22 - 0
market/mainapp/forms.py

@@ -0,0 +1,22 @@
+from django import forms
+from django.contrib.auth.forms import UserCreationForm
+
+from .models import *
+
+
+class RegisterForm(UserCreationForm):
+    class Meta:
+        model = CustomUser
+        fields = ("username", "password1", "password2", "photo")
+
+    def __init__(self, *args, **kwargs):
+        super(RegisterForm, self).__init__(*args, **kwargs)
+        for field_name in ('username', 'password1', 'password2', 'photo'):
+            self.fields[field_name].help_text = ''
+
+
+class OrderForm(forms.ModelForm):
+    class Meta:
+        model = Order
+        fields = "__all__"
+        widgets = {'user': forms.HiddenInput, 'product': forms.HiddenInput}

+ 51 - 0
market/mainapp/templates/base_generic.html

@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    {% block title %}<title>Market</title>{% endblock %}
+    {% load static %}
+</head>
+<style>
+    *{
+        margin: 0;
+        padding: 0;
+        box-sizing: border-box;
+        outline: none;
+    }
+
+    .header {
+        background: #1d2124;
+        color: white;
+        padding: 20px 40px;
+        display: flex;
+        justify-content: space-between;
+    }
+
+    .link {
+        color: white;
+        text-decoration: none;
+    }
+    .links {
+        display: flex;
+        justify-content: space-between;
+        gap: 20px;
+    }
+</style>
+<body>
+<div class="header">
+    <a href="{% url 'main' %}" class="link">Главная</a>
+    <div class="links">
+        <a class="link" href="{% url 'services' %}">Товары</a>
+    {% if user.is_authenticated %}
+      <a class="link" href="{% url 'profile' %}">Профиль</a>
+      <a class="link" href="{% url 'logout' %}">Выйти</a>
+    {% else %}
+      <a class="link" href="{% url 'register' %}">Регистрация</a>
+      <a class="link" href="{% url 'login' %}">Вход</a>
+    {% endif %}
+    </div>
+</div>
+{% block content %}
+{% endblock %}
+</body>
+</html>

+ 64 - 0
market/mainapp/templates/mainapp/index.html

@@ -0,0 +1,64 @@
+{% extends "base_generic.html" %}
+
+{% block title %}<title>Главная страница</title>{% endblock %}
+
+
+
+{% block content %}
+<style>
+    .mainContent{
+        padding: 20px 20px;
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: center;
+        gap: 20px;
+    }
+
+    .title {
+        margin-bottom: 40px;
+    }
+    .desc {
+        width: 50vw;
+    }
+    .mainProducts {
+        display: grid;
+        grid-template-columns: repeat(3, 1fr);
+        gap: 20px;
+    }
+
+    .mainProduct {
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: flex-start;
+        padding: 30px 30px;
+        gap: 15px;
+        box-shadow: #dadada 3px 3px 3px ;
+    }
+
+    .img {
+        width: 350px;
+    }
+</style>
+
+    <div class="mainContent">
+        <h1 class="title">Главная страница</h1>
+        <h3>Общее описание наших товаров</h3>
+        <p class="desc">Банальные, но неопровержимые выводы, а также базовые сценарии поведения пользователей, которые представляют
+            собой яркий пример континентально-европейского типа политической культуры, будут превращены в посмешище,
+            хотя само их существование приносит несомненную пользу обществу. Лишь многие известные личности объединены
+            в целые кластеры себе подобных. Также как укрепление и развитие внутренней структуры в значительной степени
+            обусловливает важность дальнейших направлений развития.
+
+        <div class="mainProducts">
+            {% for product in products %}
+            <div class="mainProduct">
+                <p><strong>{{product.name}}</strong></p>
+                <p>{{product.desc}}</p>
+                <p><img class="img" src="/media/{{ product.photo }}"></p>
+            </div>
+            {% endfor %}
+        </div>
+    </div>
+{% endblock %}

+ 52 - 0
market/mainapp/templates/mainapp/profile.html

@@ -0,0 +1,52 @@
+{% extends 'base_generic.html' %}
+
+{% block content %}
+<style>
+    .profileContent {
+        padding: 20px 20px;
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: center;
+        gap: 20px;
+    }
+    .products {
+            display: grid;
+            grid-template-columns: repeat(3, 1fr);
+            gap: 20px;
+        }
+
+    .product {
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: flex-start;
+        padding: 30px 30px;
+        gap: 15px;
+        box-shadow: #dadada 3px 3px 3px ;
+    }
+
+</style>
+ <div class="profileContent">
+     {% if user.is_authenticated %}
+    <h2>Профиль пользователя: {{user.username}}</h2>
+    <p><img class="img" src="{{user.photo.url}}"></p>
+    <h3>Заказы пользователя:</h3>
+    {% if orders %}
+      <div class="products">
+          {% for order in orders %}
+            <div class="product">
+            <p>{{order.product.name}}</p>
+            <p>{{order.product.desc}}</p>
+            <p><img class="img" src="/media/{{order.product.photo}}"></p>
+            </div>
+          {% endfor %}
+      </div>
+    {% else %}
+      <p>У пользователя ещё нету заказов!</p>
+    {% endif %}
+  {% else %}
+    <p>Вы не вошли в свой аккаунт!</p>
+  {% endif %}
+ </div>
+{% endblock %}

+ 15 - 0
market/mainapp/templates/mainapp/register.html

@@ -0,0 +1,15 @@
+{% extends "base_generic.html" %}
+
+{% block title %}<title>Регистрация</title>{% endblock %}
+
+{% block content %}
+<style>
+
+</style>
+
+  <form method="post" enctype="multipart/form-data">
+    {% csrf_token %}
+    {{form.as_p}}
+    <input type="submit" value="Регистрация">
+  </form>
+{% endblock %}

+ 20 - 0
market/mainapp/templates/mainapp/service_detail.html

@@ -0,0 +1,20 @@
+{% extends "base_generic.html" %}
+
+{% block title %}<title>Отдельный товар или услуга</title>{% endblock %}
+
+{% block content %}
+<style>
+
+</style>
+    <div>
+        <p>{{product.name}}</p>
+        <p>{{product.desc}}</p>
+        <p><img class="img" src="/media/{{ product.photo }}"></p>
+    </div>
+
+    <form method="post">
+        {% csrf_token %}
+        {{ form.as_p }}
+        <input type="submit" value="Заказать товар/услугу">
+    </form>
+{% endblock %}

+ 48 - 0
market/mainapp/templates/mainapp/services.html

@@ -0,0 +1,48 @@
+{% extends "base_generic.html" %}
+
+{% block title %}<title>Товары и услуги</title>{% endblock %}
+
+{% block content %}
+<style>
+    .products {
+            display: grid;
+            grid-template-columns: repeat(3, 1fr);
+            gap: 20px;
+        }
+
+    .product {
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: flex-start;
+        padding: 30px 30px;
+        gap: 15px;
+        box-shadow: #dadada 3px 3px 3px ;
+    }
+    .desc {
+        display: flex;
+        justify-content: center;
+        align-items: center;
+        flex-direction: column;
+    }
+
+    .productLink {
+        color: black;
+        text-decoration: none;
+    }
+</style>
+
+    <div class="desc">
+        <h1>Товары и услуги</h1>
+    </div>
+    <div class="products">
+        {% for product in products %}
+        <div class="product">
+            <p>{{product.name}}</p>
+            <p>{{product.desc}}</p>
+            <p><img class="img" src="/media/{{ product.photo }}"></p>
+            <p><a class="productLink" href="{% url 'services-detail' product.id %}">Перейти на страницу товара/услуги</a></p>
+        </div>
+    {% endfor %}
+    </div>
+{% endblock %}

+ 5 - 0
market/mainapp/templates/registration/123.html

@@ -0,0 +1,5 @@
+{% extends 'base_generic.html' %}
+
+{% block content %}
+
+{% endblock %}

+ 16 - 0
market/mainapp/templates/registration/login.html

@@ -0,0 +1,16 @@
+{% extends "base_generic.html" %}
+
+{% block title %}<title>Вход</title>{% endblock %}
+
+{% block content %}
+    {% if user.is_authenticated %}
+        <p>Вы уже вошли в аккаунт, <a href="{% url 'main' %}">главная страница</a></p>
+    {% else %}
+        <form method="post">
+            {% csrf_token %}
+            <p>Логин: {{ form.username }}</p>
+            <p>Пароль: {{ form.password }}</p>
+            <input type="submit" value="Войти">
+        </form>
+    {% endif %}
+{% endblock %}

+ 13 - 0
market/mainapp/urls.py

@@ -0,0 +1,13 @@
+from django.urls import path, include
+
+from . import views
+
+urlpatterns = [
+    path('', views.Main.as_view(), name="main"),
+    path('', include('django.contrib.auth.urls')),
+    path('logout', views.logoutUser, name='logout'),
+    path('service/', views.ServiceList.as_view(), name="services"),
+    path('service/<int:id>/', views.service_detail, name='services-detail'),
+    path('register/', views.RegisterView.as_view(), name="register"),
+    path('profile/', views.profile, name="profile"),
+]