-
Notifications
You must be signed in to change notification settings - Fork 14
[#H21] Django TG hw #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nikita5390
wants to merge
1
commit into
Chudopal:main
Choose a base branch
from
Nikita5390:TelegramBot_shop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
Shops/building_materials_store/app/Homework/shop_bot2/manage.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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', 'shop_bot.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() |
Empty file.
3 changes: 3 additions & 0 deletions
3
Shops/building_materials_store/app/Homework/shop_bot2/products/admin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. |
6 changes: 6 additions & 0 deletions
6
Shops/building_materials_store/app/Homework/shop_bot2/products/apps.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class ProductsConfig(AppConfig): | ||
| default_auto_field = 'django.db.models.BigAutoField' | ||
| name = 'products' |
42 changes: 42 additions & 0 deletions
42
Shops/building_materials_store/app/Homework/shop_bot2/products/migrations/0001_initial.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Generated by Django 4.0.5 on 2022-07-11 18:50 | ||
|
|
||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
| import uuid | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='Manufacturer', | ||
| fields=[ | ||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('brand', models.CharField(max_length=50)), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='Teg', | ||
| fields=[ | ||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('name', models.CharField(max_length=50)), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='Product', | ||
| fields=[ | ||
| ('name_product', models.CharField(max_length=100)), | ||
| ('description', models.CharField(max_length=250)), | ||
| ('weight', models.FloatField(default=1)), | ||
| ('cost', models.FloatField()), | ||
| ('uuid', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)), | ||
| ('made_product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='products.manufacturer')), | ||
| ('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='products.teg')), | ||
| ], | ||
| ), | ||
| ] |
Empty file.
24 changes: 24 additions & 0 deletions
24
Shops/building_materials_store/app/Homework/shop_bot2/products/models.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from django.db import models | ||
| import uuid | ||
|
|
||
| # Create your models here. | ||
|
|
||
| class Manufacturer(models.Model): | ||
| brand = models.CharField(null=False, max_length=50) | ||
|
|
||
|
|
||
| class Teg(models.Model): | ||
| name = models.CharField(null=False, max_length=50) | ||
|
|
||
|
|
||
| class Product(models.Model): | ||
| name_product = models.CharField(null=False, max_length=100) | ||
| description = models.CharField(max_length=250) | ||
| weight = models.FloatField(default=1) | ||
| cost = models.FloatField(null=False) | ||
| made_product = models.ForeignKey(Manufacturer, on_delete=models.CASCADE) | ||
| uuid = models.UUIDField(primary_key=True, default=uuid.uuid4) | ||
| tag = models.ForeignKey(Teg, on_delete=models.CASCADE) | ||
|
|
||
| def __str__(self): | ||
| return f"{self.name_product} - {self.cost}" |
3 changes: 3 additions & 0 deletions
3
Shops/building_materials_store/app/Homework/shop_bot2/products/tests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.test import TestCase | ||
|
|
||
| # Create your tests here. |
11 changes: 11 additions & 0 deletions
11
Shops/building_materials_store/app/Homework/shop_bot2/products/urls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from django.urls import path | ||
| from .views import get_all_products, get_filter_products1, get_filter_products2, get_product_info | ||
|
|
||
|
|
||
| urlpatterns = [ | ||
| path('', view=get_all_products), | ||
| path('price_gt=20&price_lt=50/', view=get_filter_products1), | ||
| path('price_gte=20&price_lte=50/', view=get_filter_products2), | ||
| path('info/<str:product_name>', view=get_product_info), | ||
| ] | ||
|
|
||
25 changes: 25 additions & 0 deletions
25
Shops/building_materials_store/app/Homework/shop_bot2/products/views.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from django.shortcuts import render | ||
| from django.http import HttpResponse | ||
| from .models import Product, Manufacturer, Teg | ||
|
|
||
|
|
||
| # Create your views here. | ||
|
|
||
| def get_all_products(request): | ||
| all_product = Product.objects.all() | ||
| return render(request, 'landing/list.html', {"all_product": all_product}) | ||
|
|
||
|
|
||
| def get_filter_products1(request): | ||
| all_product = Product.objects.filter(cost__gt=20, cost__lt=50) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не стоит хардкодить значения, получать их надо прямо из запроса |
||
| return render(request, 'landing/list.html', {"all_product": all_product}) | ||
|
|
||
|
|
||
| def get_filter_products2(request): | ||
| all_product = Product.objects.filter(cost__gte=20, cost__lte=50) | ||
| return render(request, 'landing/list.html', {"all_product": all_product}) | ||
|
|
||
|
|
||
| def get_product_info(request, product_name): | ||
| all_product = Product.objects.filter(name_product=product_name) | ||
| return render(request, 'landing/list_info.html', {"all_product": all_product}) | ||
Empty file.
16 changes: 16 additions & 0 deletions
16
Shops/building_materials_store/app/Homework/shop_bot2/shop_bot/asgi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """ | ||
| ASGI config for shop_bot 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', 'shop_bot.settings') | ||
|
|
||
| application = get_asgi_application() |
130 changes: 130 additions & 0 deletions
130
Shops/building_materials_store/app/Homework/shop_bot2/shop_bot/settings.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| """ | ||
| Django settings for shop_bot project. | ||
|
|
||
| Generated by 'django-admin startproject' using Django 4.0.5. | ||
|
|
||
| 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-zc*-nv+z!am!o6)m7j@9uvbn2i)v*($f4!k&$=0-%*qa3^@h&v' | ||
|
|
||
| # 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', | ||
| 'products', | ||
| ] | ||
|
|
||
| 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 = 'shop_bot.urls' | ||
|
|
||
| TEMPLATES_PATH = BASE_DIR.joinpath("templates") | ||
|
|
||
| TEMPLATES = [ | ||
| { | ||
| 'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
| 'DIRS': [TEMPLATES_PATH], | ||
| '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 = 'shop_bot.wsgi.application' | ||
|
|
||
|
|
||
| # Database | ||
| # https://docs.djangoproject.com/en/4.0/ref/settings/#databases | ||
|
|
||
| DATABASES = { | ||
| 'default': { | ||
| 'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
| 'NAME': 'shop_bot', | ||
| 'USER': 'admin', | ||
| 'PASSWORD': 'admin', | ||
|
Comment on lines
+84
to
+85
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ну все теперь я знаю пароль и могу поломать все приложение) |
||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| # 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' | ||
13 changes: 13 additions & 0 deletions
13
Shops/building_materials_store/app/Homework/shop_bot2/shop_bot/templates/base.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>{% block title %} Default title {% endblock %}</title> | ||
| </head> | ||
| <body> | ||
| <div style="style=text-align: center; background-color: bisque;"> | ||
| {% block content %} {% endblock %} | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> |
17 changes: 17 additions & 0 deletions
17
Shops/building_materials_store/app/Homework/shop_bot2/shop_bot/templates/landing/list.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| {% extends 'base.html' %} | ||
|
|
||
| {% block title %} Продукты {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <ul> | ||
| {% if all_product %} | ||
|
|
||
| {% for a in all_product %} | ||
| <li>{{a.name_product}} - {{a.cost}};</li> | ||
| {% endfor %} | ||
| {% else %} | ||
| Товары не найдены! | ||
| {% endif %} | ||
|
|
||
| {% endblock %} | ||
| </ul> |
17 changes: 17 additions & 0 deletions
17
...building_materials_store/app/Homework/shop_bot2/shop_bot/templates/landing/list_info.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| {% extends 'base.html' %} | ||
|
|
||
| {% block title %} Продукты {% endblock %} | ||
|
|
||
| {% block content %} | ||
| <ul> | ||
| {% if all_product %} | ||
|
|
||
| {% for a in all_product %} | ||
| <li>{{a.name_product}} - {{a.cost}}, description: {{a.description}}, weight: {{a.weight}}, made_product: {{a.made_product}};</li> | ||
| {% endfor %} | ||
| {% else %} | ||
| Товары не найдены! | ||
| {% endif %} | ||
|
|
||
| {% endblock %} | ||
| </ul> |
23 changes: 23 additions & 0 deletions
23
Shops/building_materials_store/app/Homework/shop_bot2/shop_bot/urls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """shop_bot 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 | ||
| from django.urls import include | ||
|
|
||
| urlpatterns = [ | ||
| path('admin/', admin.site.urls), | ||
| path('products/', include('products.urls')), | ||
| ] |
16 changes: 16 additions & 0 deletions
16
Shops/building_materials_store/app/Homework/shop_bot2/shop_bot/wsgi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """ | ||
| WSGI config for shop_bot 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', 'shop_bot.settings') | ||
|
|
||
| application = get_wsgi_application() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ой не, это неправильно. Почитай лучше эту статью: https://metanit.com/python/django/3.4.php