Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv/
9 changes: 8 additions & 1 deletion django_views_routing_homework/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from django_views_routing_homework.views.level_2.a_user_info_by_username import get_user_info_by_username_view
from django_views_routing_homework.views.level_2.c_product_type import get_products_view
from django_views_routing_homework.views.level_2.d_authorization import authorization_view, process_authorization_view
from django_views_routing_homework.views.level_1.b_bye_user import bye_user_view
from django_views_routing_homework.views.level_1.d_user_info import get_user_info_view
from django_views_routing_homework.views.level_1.e_month_title import get_month_title_view


urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -15,5 +19,8 @@
path('products/', get_products_view),
path('authorization/', authorization_view),
path('process-authorization/', process_authorization_view),
# добавлять пути тут
path('bye/', bye_user_view),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 верно, замапили путь на вьюху-обработчик

path('user-info/<int:user_id>/', get_user_info_view),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 используем path parameter с заданным типом при маппинге на вьюху

path('month-title/<int:month_number>/', get_month_title_view),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 все верно, задаем номер месяца как числовой path parameter

]

Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@


def welcome_user_view(request):
welcome_message = 'Bye, user'
welcome_message = 'Hello, user'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 верно

return HttpResponse(welcome_message)
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@


def is_username_banned_view(request, username: str):
# код писать тут
return HttpResponse('User not banned')
if username in BANNED_USERNAMES:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 верно

return HttpResponse('User banned')
else:
return HttpResponse('User not banned')
28 changes: 25 additions & 3 deletions django_views_routing_homework/views/level_1/e_month_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,33 @@
вызывалась вьюха get_month_title_view. Например http://127.0.0.1:8000/month-title/3/
"""

MONTHS = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 словарь хорошо подходит для такой задачи

1: 'Январь',
2: 'Февраль',
3: 'Март',
4: 'Апрель',
5: 'Май',
6: 'Июнь',
7: 'Июль',
8: 'Август',
9: 'Сентябрь',
10: 'Октябрь',
11: 'Ноябрь',
12: 'Декабрь',
}


def get_month_title_by_number(month_number: int):
pass # код писать тут
if month_number in MONTHS:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 верно
💡 еще чтобы два раза не искать элемент в словаре, можно было бы использовать get метод словаря

return MONTHS.get(month_number)

return MONTHS[month_number]
else:
return None


def get_month_title_view(request, month_number: int):
# код писать тут
return HttpResponseNotFound('Месяца с таким номером не существует')
month_title = get_month_title_by_number(month_number)

if month_title:
return HttpResponse(month_title)
else:
return HttpResponseNotFound('Месяца с таким номером не существует')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 верно