瀏覽代碼

421 mongush

locadm 1 年之前
當前提交
6a2bb6dfc8

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 7 - 0
.idea/misc.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Black">
+    <option name="sdkName" value="Python 3.12 (pythonProject)" />
+  </component>
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject)" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
+    </modules>
+  </component>
+</project>

+ 10 - 0
.idea/pythonProject.iml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/.venv" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

二進制
bboard/bboard.data


+ 0 - 0
bboard/bboard/__init__.py


+ 16 - 0
bboard/bboard/asgi.py

@@ -0,0 +1,16 @@
+"""
+ASGI config for bboard project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bboard.settings")
+
+application = get_asgi_application()

+ 123 - 0
bboard/bboard/settings.py

@@ -0,0 +1,123 @@
+"""
+Django settings for bboard project.
+
+Generated by 'django-admin startproject' using Django 5.0.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/5.0/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/5.0/ref/settings/
+"""
+import os
+from pathlib import Path
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = "django-insecure-@jn7m@mzl1(dw56c*m8up_slmicdi(77caej1+orj*7r4#u+j+"
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+# Application definition
+
+INSTALLED_APPS = [
+    "django.contrib.admin",
+    "django.contrib.auth",
+    "django.contrib.contenttypes",
+    "django.contrib.sessions",
+    "django.contrib.messages",
+    "django.contrib.staticfiles",
+    "main.apps.MainConfig",
+    "bootstrap4",
+]
+
+MIDDLEWARE = [
+    "django.middleware.security.SecurityMiddleware",
+    "django.contrib.sessions.middleware.SessionMiddleware",
+    "django.middleware.common.CommonMiddleware",
+    "django.middleware.csrf.CsrfViewMiddleware",
+    "django.contrib.auth.middleware.AuthenticationMiddleware",
+    "django.contrib.messages.middleware.MessageMiddleware",
+    "django.middleware.clickjacking.XFrameOptionsMiddleware",
+]
+
+ROOT_URLCONF = "bboard.urls"
+
+TEMPLATES = [
+    {
+        "BACKEND": "django.template.backends.django.DjangoTemplates",
+        "DIRS": [],
+        "APP_DIRS": True,
+        "OPTIONS": {
+            "context_processors": [
+                "django.template.context_processors.debug",
+                "django.template.context_processors.request",
+                "django.contrib.auth.context_processors.auth",
+                "django.contrib.messages.context_processors.messages",
+            ],
+        },
+    },
+]
+
+WSGI_APPLICATION = "bboard.wsgi.application"
+
+# Database
+# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
+
+DATABASES = {
+    "default": {
+        "ENGINE": "django.db.backends.sqlite3",
+        "NAME": BASE_DIR / "bboard.data",
+    }
+}
+
+# Password validation
+# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+    {
+        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
+    },
+    {
+        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
+    },
+    {
+        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
+    },
+    {
+        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
+    },
+]
+
+# Internationalization
+# https://docs.djangoproject.com/en/5.0/topics/i18n/
+
+LANGUAGE_CODE = "ru-ru"
+
+TIME_ZONE = "Asia/Tomsk"
+
+USE_I18N = True
+
+USE_TZ = True
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/5.0/howto/static-files/
+
+STATIC_URL = "static/"
+
+# Default primary key field type
+# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
+
+DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
+MEDIA_URL = "/media/"
+MEDIA_ROOT = os.path.join(BASE_DIR, "media")
+
+AUTH_USER_MODEL = "main.CustUser"

+ 25 - 0
bboard/bboard/urls.py

@@ -0,0 +1,25 @@
+"""
+URL configuration for bboard project.
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/5.0/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  path('', views.home, name='home')
+Class-based views
+    1. Add an import:  from other_app.views import Home
+    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
+Including another URLconf
+    1. Import the include() function: from django.urls import include, path
+    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
+"""
+from django.conf import settings
+from django.conf.urls.static import static
+from django.contrib import admin
+from django.urls import path, include
+
+urlpatterns = [
+    path("admin/", admin.site.urls),
+    path('', include('main.urls'))
+]+static(settings.MEDIA_URL, document_root=settings)

+ 16 - 0
bboard/bboard/wsgi.py

@@ -0,0 +1,16 @@
+"""
+WSGI config for bboard project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bboard.settings")
+
+application = get_wsgi_application()

+ 0 - 0
bboard/main/__init__.py


+ 6 - 0
bboard/main/admin.py

@@ -0,0 +1,6 @@
+from django.contrib import admin
+
+from .models import CustUser, Product
+
+admin.site.register(CustUser)
+admin.site.register(Product)

+ 6 - 0
bboard/main/apps.py

@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class MainConfig(AppConfig):
+    default_auto_field = "django.db.models.BigAutoField"
+    name = "main"

+ 9 - 0
bboard/main/forms.py

@@ -0,0 +1,9 @@
+from django.contrib.auth.forms import UserCreationForm
+
+from .models import CustUser
+
+
+class RegisterUserForm(UserCreationForm):
+    class Meta:
+        model = CustUser
+        fields = ['username', 'email', 'password1', 'password2', 'avatar']

+ 132 - 0
bboard/main/migrations/0001_initial.py

@@ -0,0 +1,132 @@
+# Generated by Django 5.0 on 2023-12-26 05:06
+
+import django.contrib.auth.models
+import django.contrib.auth.validators
+import django.utils.timezone
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    initial = True
+
+    dependencies = [
+        ("auth", "0012_alter_user_first_name_max_length"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="CustUser",
+            fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
+                ("password", models.CharField(max_length=128, verbose_name="password")),
+                (
+                    "last_login",
+                    models.DateTimeField(
+                        blank=True, null=True, verbose_name="last login"
+                    ),
+                ),
+                (
+                    "is_superuser",
+                    models.BooleanField(
+                        default=False,
+                        help_text="Designates that this user has all permissions without explicitly assigning them.",
+                        verbose_name="superuser status",
+                    ),
+                ),
+                (
+                    "username",
+                    models.CharField(
+                        error_messages={
+                            "unique": "A user with that username already exists."
+                        },
+                        help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
+                        max_length=150,
+                        unique=True,
+                        validators=[
+                            django.contrib.auth.validators.UnicodeUsernameValidator()
+                        ],
+                        verbose_name="username",
+                    ),
+                ),
+                (
+                    "first_name",
+                    models.CharField(
+                        blank=True, max_length=150, verbose_name="first name"
+                    ),
+                ),
+                (
+                    "last_name",
+                    models.CharField(
+                        blank=True, max_length=150, verbose_name="last name"
+                    ),
+                ),
+                (
+                    "email",
+                    models.EmailField(
+                        blank=True, max_length=254, verbose_name="email address"
+                    ),
+                ),
+                (
+                    "is_staff",
+                    models.BooleanField(
+                        default=False,
+                        help_text="Designates whether the user can log into this admin site.",
+                        verbose_name="staff status",
+                    ),
+                ),
+                (
+                    "is_active",
+                    models.BooleanField(
+                        default=True,
+                        help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
+                        verbose_name="active",
+                    ),
+                ),
+                (
+                    "date_joined",
+                    models.DateTimeField(
+                        default=django.utils.timezone.now, verbose_name="date joined"
+                    ),
+                ),
+                ("avatar", models.ImageField(blank=True, upload_to="avatars/")),
+                (
+                    "groups",
+                    models.ManyToManyField(
+                        blank=True,
+                        help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
+                        related_name="user_set",
+                        related_query_name="user",
+                        to="auth.group",
+                        verbose_name="groups",
+                    ),
+                ),
+                (
+                    "user_permissions",
+                    models.ManyToManyField(
+                        blank=True,
+                        help_text="Specific permissions for this user.",
+                        related_name="user_set",
+                        related_query_name="user",
+                        to="auth.permission",
+                        verbose_name="user permissions",
+                    ),
+                ),
+            ],
+            options={
+                "verbose_name": "user",
+                "verbose_name_plural": "users",
+                "abstract": False,
+            },
+            managers=[
+                ("objects", django.contrib.auth.models.UserManager()),
+            ],
+        ),
+    ]

+ 29 - 0
bboard/main/migrations/0002_product.py

@@ -0,0 +1,29 @@
+# Generated by Django 5.0 on 2023-12-26 05:28
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("main", "0001_initial"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="Product",
+            fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
+                ("name", models.CharField(max_length=100)),
+                ("photo", models.ImageField(blank=True, upload_to="photos/")),
+                ("date", models.DateField(auto_now=True)),
+            ],
+        ),
+    ]

+ 0 - 0
bboard/main/migrations/__init__.py


+ 12 - 0
bboard/main/models.py

@@ -0,0 +1,12 @@
+from django.contrib.auth.models import AbstractUser
+from django.db import models
+
+
+class CustUser(AbstractUser):
+    avatar = models.ImageField(upload_to='avatars/', blank=True)
+
+
+class Product(models.Model):
+    name = models.CharField(max_length=100)
+    photo = models.ImageField(upload_to='photos/', blank=True)
+    date = models.DateField(auto_now=True)

+ 25 - 0
bboard/main/static/css/main.css

@@ -0,0 +1,25 @@
+.header{
+    background-color: black;
+}
+.header ul li {
+    list-style-type:none;
+}
+.header ul li a {
+    color: white;
+    text-decoration:none;
+}
+.header ul{
+    display: flex;
+    gap:20px;
+    padding:20px;
+}
+.container{
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    gap:40px;
+}
+.product{
+    border: 2px solid black;
+    padding: 10px;
+}

+ 32 - 0
bboard/main/templates/base.html

@@ -0,0 +1,32 @@
+{% load static %}
+{% load bootstrap4 %}
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <link rel="stylesheet" href="{% static 'css/main.css' %}" >
+    <title> {% block title %} {% endblock %} - Интернет магазин</title>
+</head>
+<body>
+<header class="header">
+    <nav>
+        <ul >
+            <li ><a href="{% url 'main:index' %}">Главная</a></li>
+            <li><a href="{% url 'main:products' %}">Товары</a></li>
+            {% if user.is_authenticated %}
+            <li><a href="{% url 'main:profile' %}">Профиль</a></li>
+            <li><a href="{% url 'main:logout' %}">Выход</a></li>
+            {% else %}
+            <li><a href="{% url 'main:register' %}">Регистрация</a></li>
+            <li><a href="{% url 'main:login' %}">Вход</a></li>
+            {% endif %}
+        </ul>
+    </nav>
+</header>
+<div class="main">
+    <div class="container">
+        {% block content %} {% endblock %}
+    </div>
+</div>
+</body>
+</html>

+ 19 - 0
bboard/main/templates/main/index.html

@@ -0,0 +1,19 @@
+{% extends 'base.html' %}
+{% load static %}
+{% load bootstrap4 %}
+
+{% block title %} Главная {% endblock %}
+
+{% block content %}
+<h2>Главная</h2>
+{% if products %}
+{% for product in products %}
+<div class="product">
+    <a href="{% url 'main:product_detail' product.id %}">{{product.name}}</a>
+    <p>{{product.date}}</p>
+</div>
+{% endfor %}
+{% else %}
+<p>Товаров пока нет</p>
+{% endif %}
+{% endblock %}

+ 15 - 0
bboard/main/templates/main/login.html

@@ -0,0 +1,15 @@
+{% extends 'base.html' %}
+{% load static %}
+{% load bootstrap4 %}
+
+{% block title %} Вход {% endblock %}
+
+{% block content %}
+<h2>Вход</h2>
+<form method="post">
+    {% csrf_token %}
+    {% bootstrap_form form layout="horizontal" %}
+    <input type="hidden" name="next" value="{% url 'main:index' %}">
+    {% buttons submit="Вход" %}{% endbuttons %}
+</form>
+{% endblock %}

+ 13 - 0
bboard/main/templates/main/product_detail.html

@@ -0,0 +1,13 @@
+{% extends 'base.html' %}
+{% load static %}
+{% load bootstrap4 %}
+
+{% block title %} Отдельно товар {% endblock %}
+
+{% block content %}
+<h2>Отдельно товар</h2>
+<div class="product">
+    <a>{{product.name}}</a>
+    <p>{{product.date}}</p>
+</div>
+{% endblock %}

+ 19 - 0
bboard/main/templates/main/products.html

@@ -0,0 +1,19 @@
+{% extends 'base.html' %}
+{% load static %}
+{% load bootstrap4 %}
+
+{% block title %} Товары {% endblock %}
+
+{% block content %}
+<h2>Товары</h2>
+{% if products %}
+{% for product in products %}
+<div class="product">
+    <a href="{% url 'main:product_detail' product.id %}">{{product.name}}</a>
+    <p>{{product.date}}</p>
+</div>
+{% endfor %}
+{% else %}
+<p>Товаров пока нет</p>
+{% endif %}
+{% endblock %}

+ 16 - 0
bboard/main/templates/main/profile.html

@@ -0,0 +1,16 @@
+{% extends 'base.html' %}
+{% load static %}
+{% load bootstrap4 %}
+
+{% block title %} Профиль {% endblock %}
+
+{% block content %}
+<h2> Профиль </h2>
+<div>
+    <p>Ваше имя</p>
+    <p>{{user.username}}</p>
+    <p>Ваша почта</p>
+    <p>{{user.email}}</p>
+    <img href="{{user.avatar.url}}">
+</div>
+{% endblock %}

+ 14 - 0
bboard/main/templates/main/register.html

@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+{% load static %}
+{% load bootstrap4 %}
+
+{% block title %} Регистрация {% endblock %}
+
+{% block content %}
+<h2>Регистрация</h2>
+<form method="post" enctype="multipart/form-data">
+    {% csrf_token %}
+    {% bootstrap_form form layout="horizontal" %}
+     <input type="hidden" name="next" value="{% url 'main:index' %}">
+    {% buttons submit="Регистрация" %}{% endbuttons %}
+</form>

+ 3 - 0
bboard/main/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 17 - 0
bboard/main/urls.py

@@ -0,0 +1,17 @@
+from django.urls import path
+from django.conf import settings
+from django.conf.urls.static import static
+
+from . import views
+from .views import *
+
+app_name = 'main'
+
+urlpatterns = [path('', IndexView.as_view(), name='index'),
+               path('accounts/login/', BBLoginView.as_view(), name='login'),
+               path('accounts/register/', RegisterUserView.as_view(), name='register'),
+               path('accounts/logout/', views.logout_view, name='logout'),
+               path('accounts/profile/', ProfileListView.as_view(), name='profile'),
+               path('products/', ProductListView.as_view(), name='products'),
+               path('product/<int:pk>/', ProductDetailView.as_view(), name='product_detail'),
+               ] + static(settings.MEDIA_URL, document_root=settings)

+ 52 - 0
bboard/main/views.py

@@ -0,0 +1,52 @@
+from django.contrib.auth import logout
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth.views import LoginView
+from django.shortcuts import render
+from django.urls import reverse_lazy
+from django.views import generic
+from django.views.generic import TemplateView, CreateView
+
+from .forms import RegisterUserForm
+from .models import CustUser, Product
+
+
+class IndexView(generic.ListView):
+    model = Product
+    template_name = "main/index.html"
+    context_object_name = "products"
+
+    def get_queryset(self):
+        return Product.objects.order_by('-date')[:5]
+
+
+class BBLoginView(LoginView):
+    template_name = "main/login.html"
+
+
+@login_required
+def logout_view(request):
+    logout(request)
+    return render(request, 'main/index.html')
+
+
+class RegisterUserView(CreateView):
+    model = CustUser
+    template_name = "main/register.html"
+    form_class = RegisterUserForm
+    success_url = reverse_lazy("main:login")
+
+
+class ProductListView(generic.ListView):
+    model = Product
+    template_name = "main/products.html"
+    context_object_name = "products"
+
+
+class ProductDetailView(generic.DetailView):
+    model = Product
+    template_name = "main/product_detail.html"
+
+
+class ProfileListView(generic.ListView):
+    model = CustUser
+    template_name = "main/profile.html"

+ 22 - 0
bboard/manage.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+    """Run administrative tasks."""
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bboard.settings")
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError as exc:
+        raise ImportError(
+            "Couldn't import Django. Are you sure it's installed and "
+            "available on your PYTHONPATH environment variable? Did you "
+            "forget to activate a virtual environment?"
+        ) from exc
+    execute_from_command_line(sys.argv)
+
+
+if __name__ == "__main__":
+    main()

二進制
bboard/media/avatars/krasivye-kartinki-kotov-37.jpg