Skip to content

Commit 5b13fd1

Browse files
committed
HW08: init
1 parent 0998850 commit 5b13fd1

File tree

26 files changed

+605
-1
lines changed

26 files changed

+605
-1
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ repos:
5252
- --max-line-length=120
5353
- --ignore-imports=yes
5454
- -d duplicate-code
55-
- -d C0111,W0621,R0913,R1705,W0201,R0903,W0613
55+
- -d C0111,W0621,R0913,R1705,W0201,R0903,W0613,C0415,C0103
5656

5757

5858
- repo: https://github.com/asottile/pyupgrade

homework_08/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.12
2+
3+
ENV PYTHONUNBUFFERED=1
4+
5+
RUN mkdir -p /app
6+
WORKDIR /app
7+
8+
COPY Makefile pyproject.toml poetry.lock
9+
RUN poetry install --no-root
10+
COPY ./mysite .
11+
12+
ENTRYPOINT [ "python", "/app/mysicte/manage.py", 'runserver' ]

homework_08/Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
SETTINGS_DIR=settings
2+
PYTHON=python3
3+
OS_TYPE=Lin
4+
5+
# Define default server to run
6+
DEV_SETTINGS=settings_dev.py
7+
PROD_SETTINGS=$(SETTINGS_DIR)/settings_prod.py
8+
9+
# Update project name
10+
PROJECT_DIR=./mysite
11+
12+
# Define Django commands
13+
dev:
14+
$(PYTHON) $(PROJECT_DIR)/manage.py runserver
15+
16+
test:
17+
$(PYTHON) $(PROJECT_DIR)/manage.py test polls
18+
19+
prod:
20+
$(PYTHON) manage.py runserver
21+
22+
migrate-dev:
23+
$(PYTHON) $(PROJECT_DIR)/manage.py migrate
24+
25+
migrate-prod:
26+
$(PYTHON) manage.py migrate
27+
28+
# Help command to display available options
29+
help:
30+
@echo "Django Makefile Commands:"
31+
@echo " dev: Run the server in dev mode"
32+
@echo " test: Run unit tests"
33+
@echo " prod: Run the server in prod mode"
34+
@echo " migrate-dev: Run migrations in dev mode"
35+
@echo " migrate-prod: Run migrations in prod mode"
36+
@echo " help: Display this help message"
37+
38+
.PHONY: dev test prod migrate-dev migrate-prod help

homework_08/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Задание
2+
### Django tutorial
3+
4+
*Задание*: полностью пройти туториал по django https://docs.djangoproject.com/en/5.0/intro/tutorial01/, оформив при этом результирующий проект с соблюдением всех лучших практик, которые обсуждались раннее, а также в парадигме 12 factor app https://12factor.net (это общая статья, как прикладывать к django легко можно найти; критику подходу можно почитать тут https://xenitab.github.io/blog/2022/02/23/12factor/)
5+
6+
*Цель задания*: получить навык работы с django, а также набить руку в создании сервисов, которые можно было бы назвать production grade/
7+
8+
*Критерии успеха*: код в репозитории целиком реализует функционал туториала, проект сруктурирован стандартным образом, настроены проверки линторв, форматтеры и т.д., а сам сервис максимально следует парадигме 12 factor app.
9+
10+
## Deadline
11+
Задание желательно сдать в течение недели. Код, отправленный на ревью в это время, рассматривается в первом приоритете. Нарушение делайна не карается. Пытаться сдать ДЗ можно до конца курсы. Код, отправленный с опозданием, когда по плану предполагается работа над более актуальным ДЗ, будет рассматриваться в более низком приоритете без гарантий по высокой скорости проверки.
12+
13+
## Обратная связь
14+
Cтудент коммитит все необходимое в свой github/gitlab репозитарий. Далее необходимо зайти в ЛК, найти занятие, ДЗ по которому выполнялось, нажать “Чат с преподавателем” и отправить ссылку. После этого ревью и общение на тему ДЗ будет происходить в рамках этого чата.

homework_08/mysite/__init__.py

Whitespace-only changes.

homework_08/mysite/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()

homework_08/mysite/mysite/__init__.py

Whitespace-only changes.

homework_08/mysite/mysite/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for mysite project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
15+
16+
application = get_asgi_application()
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""
2+
Django settings for mysite project.
3+
4+
Generated by 'django-admin startproject' using Django 5.0.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.0/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = "django-insecure-__er)c+3x%##^yl(%+7^e=!32-4!(04f+utu(#z(+sjzh8w*wh"
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = [] # type: ignore
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
"polls.apps.PollsConfig",
35+
"django.contrib.admin",
36+
"django.contrib.auth",
37+
"django.contrib.contenttypes",
38+
"django.contrib.sessions",
39+
"django.contrib.messages",
40+
"django.contrib.staticfiles",
41+
]
42+
43+
MIDDLEWARE = [
44+
"django.middleware.security.SecurityMiddleware",
45+
"django.contrib.sessions.middleware.SessionMiddleware",
46+
"django.middleware.common.CommonMiddleware",
47+
"django.middleware.csrf.CsrfViewMiddleware",
48+
"django.contrib.auth.middleware.AuthenticationMiddleware",
49+
"django.contrib.messages.middleware.MessageMiddleware",
50+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
51+
]
52+
53+
ROOT_URLCONF = "mysite.urls"
54+
55+
TEMPLATES = [
56+
{
57+
"BACKEND": "django.template.backends.django.DjangoTemplates",
58+
"DIRS": [BASE_DIR / "templates"],
59+
"APP_DIRS": True,
60+
"OPTIONS": {
61+
"context_processors": [
62+
"django.template.context_processors.debug",
63+
"django.template.context_processors.request",
64+
"django.contrib.auth.context_processors.auth",
65+
"django.contrib.messages.context_processors.messages",
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = "mysite.wsgi.application"
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
76+
77+
DATABASES = {
78+
"default": {
79+
"ENGINE": "django.db.backends.sqlite3",
80+
"NAME": BASE_DIR / "db.sqlite3",
81+
}
82+
}
83+
84+
85+
# Password validation
86+
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
87+
88+
AUTH_PASSWORD_VALIDATORS = [
89+
{
90+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
91+
},
92+
{
93+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
94+
},
95+
{
96+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
97+
},
98+
{
99+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
100+
},
101+
]
102+
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
106+
107+
LANGUAGE_CODE = "en-us"
108+
109+
TIME_ZONE = "America/Chicago"
110+
111+
USE_I18N = True
112+
113+
USE_TZ = True
114+
115+
116+
# Static files (CSS, JavaScript, Images)
117+
# https://docs.djangoproject.com/en/5.0/howto/static-files/
118+
119+
STATIC_URL = "static/"
120+
121+
# Default primary key field type
122+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
123+
124+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

homework_08/mysite/mysite/urls.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
URL configuration for mysite project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.0/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
18+
from django.contrib import admin
19+
from django.urls import include, path
20+
21+
urlpatterns = [
22+
path("polls/", include("polls.urls")),
23+
path("admin/", admin.site.urls),
24+
]

0 commit comments

Comments
 (0)