From bbd30565c754203bb15970a805e2e9306a46b44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=9B=D1=8E?= =?UTF-8?q?=D0=BB=D1=8F?= Date: Fri, 6 May 2022 20:51:49 +0300 Subject: [PATCH 1/4] add shop skeleton --- Shops/skin_shop/app/main.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Shops/skin_shop/app/main.py diff --git a/Shops/skin_shop/app/main.py b/Shops/skin_shop/app/main.py new file mode 100644 index 0000000..e69de29 From 5fbac37efa06a5ad197c900ac5a160d86cc93bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=9B=D1=8E?= =?UTF-8?q?=D0=BB=D1=8F?= Date: Fri, 6 May 2022 21:11:07 +0300 Subject: [PATCH 2/4] added some changes --- Shops/skin_shop/app/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Shops/skin_shop/app/main.py b/Shops/skin_shop/app/main.py index e69de29..f7d1785 100644 --- a/Shops/skin_shop/app/main.py +++ b/Shops/skin_shop/app/main.py @@ -0,0 +1 @@ +print('Hello world') From 0d618060d89eeee08d966aa403bf6a3ad21c4ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=9B=D1=8E?= =?UTF-8?q?=D0=BB=D1=8F?= Date: Tue, 17 May 2022 01:12:33 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=BE=20read=20fun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shops/skin_shop/app/main.py | 94 ++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/Shops/skin_shop/app/main.py b/Shops/skin_shop/app/main.py index f7d1785..18d1903 100644 --- a/Shops/skin_shop/app/main.py +++ b/Shops/skin_shop/app/main.py @@ -1 +1,93 @@ -print('Hello world') +# """5. Напишите программу магазина. +# Покупатели могут покупать какие-то продукты в магазине. + +# Возможности покупателя: +# - посмотреть все товары и цены на них +# - выбрать товар +# - посмотреть сумму покупки(сумма цен выбранных товаров) +# Взаимодействие происходит через консоль. + +# Товары храните просто в какой-нибудь из коллекций. +# Выбор товара - это ввод пользователем строки названия товара +# """ + +import json + +products = [ + ("Rogozhka",100), + ("Velour",200), + ("Vicrovelour",300), + ("Shenil",400), +] + +order = [] + +def read_file(filename: str) -> dict: + + with open(filename) as file: + data = json.load(file) + return data + + +# № function 1 +def get_all_products() -> list: + data = read_file('Shops\skin_shop\\app\storage.json') + id = 0 + result = '' + for product in data.get('products'): + print(product) + id += 1 + #result += f'{id}.{product[0]} : {product[1]}$' + "\n" + + return result + +# № function 2 +def add_product(product_id: int) ->str: + + order.append(products[product_id - 1]) + result = f'Вы выбрали {products[product_id - 1][0]} стоимость {products[product_id - 1][1]}$' + "\n" + return result + +# № function 3 +def get_sum_price() -> str: + sum = 0 + for order_item in order: + sum += order_item[1] + return sum + + +def managment_func(num_func: int): + result = "" + if num_func == 1: + result = get_all_products() + elif num_func == 2: + product_id = int(input(get_all_products() + 'Введите номер продукта: ')) + result = add_product(product_id) + elif num_func == 3: + result = f'Сумма покупки {get_sum_price()}$' + else: + result = 'Введены неверные значения' + + return result + +def menu(): + menu = """ + 0 - Выход + 1 - Посмотреть товары + 2 - Добавить в корзину + 3 - Посмотреть корзину + """ + "\n" + "Выберите действие: " + return menu + + +def run() -> None: + choice = "" + while choice != 'Выход': + choice = int(input(menu())) + message = managment_func(choice) + print(message) + +run() + + + \ No newline at end of file From e30e251f789e1761a1cd215ee9db2ed4d397498b Mon Sep 17 00:00:00 2001 From: EvgeniyLyulya <103605592+EvgeniyLyulya@users.noreply.github.com> Date: Tue, 9 Aug 2022 17:28:36 +0300 Subject: [PATCH 4/4] [HW_practic] --- .../website/article/__init__.py | 0 .../youtubePractic/website/article/admin.py | 6 + .../youtubePractic/website/article/apps.py | 7 + .../article/migrations/0001_initial.py | 33 +++++ .../website/article/migrations/__init__.py | 0 .../youtubePractic/website/article/models.py | 25 ++++ .../youtubePractic/website/article/tests.py | 3 + .../youtubePractic/website/article/urls.py | 7 + .../youtubePractic/website/article/views.py | 8 ++ .../youtubePractic/website/manage.py | 22 +++ .../website/templates/articles/list.html | 7 + .../youtubePractic/website/templates/asd.py | 0 .../website/templates/base.html | 12 ++ .../website/website/__init__.py | 0 .../youtubePractic/website/website/asgi.py | 16 +++ .../website/website/settings.py | 125 ++++++++++++++++++ .../youtubePractic/website/website/urls.py | 22 +++ .../youtubePractic/website/website/wsgi.py | 16 +++ 18 files changed, 309 insertions(+) create mode 100644 Shops/skin_shop/youtubePractic/website/article/__init__.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/admin.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/apps.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/migrations/0001_initial.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/migrations/__init__.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/models.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/tests.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/urls.py create mode 100644 Shops/skin_shop/youtubePractic/website/article/views.py create mode 100644 Shops/skin_shop/youtubePractic/website/manage.py create mode 100644 Shops/skin_shop/youtubePractic/website/templates/articles/list.html create mode 100644 Shops/skin_shop/youtubePractic/website/templates/asd.py create mode 100644 Shops/skin_shop/youtubePractic/website/templates/base.html create mode 100644 Shops/skin_shop/youtubePractic/website/website/__init__.py create mode 100644 Shops/skin_shop/youtubePractic/website/website/asgi.py create mode 100644 Shops/skin_shop/youtubePractic/website/website/settings.py create mode 100644 Shops/skin_shop/youtubePractic/website/website/urls.py create mode 100644 Shops/skin_shop/youtubePractic/website/website/wsgi.py diff --git a/Shops/skin_shop/youtubePractic/website/article/__init__.py b/Shops/skin_shop/youtubePractic/website/article/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Shops/skin_shop/youtubePractic/website/article/admin.py b/Shops/skin_shop/youtubePractic/website/article/admin.py new file mode 100644 index 0000000..c18ecf0 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/article/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Article, Comment +admin.site.register(Article) +admin.site.register(Comment) + +# Register your models here. diff --git a/Shops/skin_shop/youtubePractic/website/article/apps.py b/Shops/skin_shop/youtubePractic/website/article/apps.py new file mode 100644 index 0000000..b1fcb67 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/article/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class ArticleConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'article' + verbose_name = 'blog' diff --git a/Shops/skin_shop/youtubePractic/website/article/migrations/0001_initial.py b/Shops/skin_shop/youtubePractic/website/article/migrations/0001_initial.py new file mode 100644 index 0000000..d93d876 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/article/migrations/0001_initial.py @@ -0,0 +1,33 @@ +# Generated by Django 4.0.6 on 2022-08-03 21:12 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Article', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('article_title', models.CharField(max_length=200, verbose_name='имя статьи')), + ('article_text', models.TextField(verbose_name='текс статьи')), + ('pub_date', models.DateTimeField(verbose_name='дата публикации')), + ], + ), + migrations.CreateModel( + name='comment', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('author_name', models.CharField(max_length=50, verbose_name='автор комментария')), + ('comment_text', models.CharField(max_length=200, verbose_name='текс комментария')), + ('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='article.article')), + ], + ), + ] diff --git a/Shops/skin_shop/youtubePractic/website/article/migrations/__init__.py b/Shops/skin_shop/youtubePractic/website/article/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Shops/skin_shop/youtubePractic/website/article/models.py b/Shops/skin_shop/youtubePractic/website/article/models.py new file mode 100644 index 0000000..36ee522 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/article/models.py @@ -0,0 +1,25 @@ +import datetime +from django.db import models +from django.utils import timezone + +class Article(models.Model): + article_title = models.CharField('имя статьи', max_length = 200) + article_text = models.TextField('текс статьи') + pub_date = models.DateTimeField('дата публикации') + + + def __str__(self): + return self.article_title + + def was_publisher_recently(self): + return self.pub_date >= (timezone.now() - datetime.timedelta(days = 7)) + + +class Comment(models.Model): + article = models.ForeignKey(Article, on_delete = models.CASCADE) + author_name = models.CharField('автор комментария', max_length = 50) + comment_text= models.CharField('текс комментария', max_length = 200) + + + def __str__(self): + return self.author_name \ No newline at end of file diff --git a/Shops/skin_shop/youtubePractic/website/article/tests.py b/Shops/skin_shop/youtubePractic/website/article/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/article/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Shops/skin_shop/youtubePractic/website/article/urls.py b/Shops/skin_shop/youtubePractic/website/article/urls.py new file mode 100644 index 0000000..b2ee85a --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/article/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from .import views + + +urlpatterns = [ + path('', views.index, name = '_index_'), +] \ No newline at end of file diff --git a/Shops/skin_shop/youtubePractic/website/article/views.py b/Shops/skin_shop/youtubePractic/website/article/views.py new file mode 100644 index 0000000..1b41ffe --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/article/views.py @@ -0,0 +1,8 @@ +from django.shortcuts import render + +def index(request): + return render(request, 'article/list.html') + + + + diff --git a/Shops/skin_shop/youtubePractic/website/manage.py b/Shops/skin_shop/youtubePractic/website/manage.py new file mode 100644 index 0000000..ac2f90c --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/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', 'website.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() diff --git a/Shops/skin_shop/youtubePractic/website/templates/articles/list.html b/Shops/skin_shop/youtubePractic/website/templates/articles/list.html new file mode 100644 index 0000000..66b1280 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/templates/articles/list.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} + +{% block title %}Последние статьи{% endblock %} + +{% block content %} + Проверка... +{% endblock %} \ No newline at end of file diff --git a/Shops/skin_shop/youtubePractic/website/templates/asd.py b/Shops/skin_shop/youtubePractic/website/templates/asd.py new file mode 100644 index 0000000..e69de29 diff --git a/Shops/skin_shop/youtubePractic/website/templates/base.html b/Shops/skin_shop/youtubePractic/website/templates/base.html new file mode 100644 index 0000000..19fb0a8 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/templates/base.html @@ -0,0 +1,12 @@ + + + + + {% block title %}My site{% endblock %} + + + {% block content %}{% endblock %} + + + + \ No newline at end of file diff --git a/Shops/skin_shop/youtubePractic/website/website/__init__.py b/Shops/skin_shop/youtubePractic/website/website/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Shops/skin_shop/youtubePractic/website/website/asgi.py b/Shops/skin_shop/youtubePractic/website/website/asgi.py new file mode 100644 index 0000000..1c62361 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/website/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for website 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings') + +application = get_asgi_application() diff --git a/Shops/skin_shop/youtubePractic/website/website/settings.py b/Shops/skin_shop/youtubePractic/website/website/settings.py new file mode 100644 index 0000000..1b71f0a --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/website/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for website project. + +Generated by 'django-admin startproject' using Django 4.0.6. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +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/4.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-i62z$8@#wacsfw4o7*f1a51%ege8*q#7oxln2u#8msp^3t0_q+' + +# 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', + 'article', +] + +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 = 'website.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + os.path.join(PROJECT_ROOT, 'templates')], + '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 = 'website.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/Shops/skin_shop/youtubePractic/website/website/urls.py b/Shops/skin_shop/youtubePractic/website/website/urls.py new file mode 100644 index 0000000..dd4ce05 --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/website/urls.py @@ -0,0 +1,22 @@ +"""website URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.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.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('article/', include('article.urls')), + path('admin/', admin.site.urls), + ] diff --git a/Shops/skin_shop/youtubePractic/website/website/wsgi.py b/Shops/skin_shop/youtubePractic/website/website/wsgi.py new file mode 100644 index 0000000..1a372df --- /dev/null +++ b/Shops/skin_shop/youtubePractic/website/website/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for website 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings') + +application = get_wsgi_application()