diff --git a/Shops/skin_shop/app/main.py b/Shops/skin_shop/app/main.py new file mode 100644 index 0000000..18d1903 --- /dev/null +++ b/Shops/skin_shop/app/main.py @@ -0,0 +1,93 @@ +# """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 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 @@ + + +
+ +