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
5 changes: 3 additions & 2 deletions django_views_routing_homework/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django_views_routing_homework.views.level_1.a_welcome_user import welcome_user_view
from django_views_routing_homework.views.level_1.c_baned_username import is_username_banned_view
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.b_greet_user_language import greet_user_in_different_languages_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_3.b_validate_user_data import validate_user_data_view
Expand All @@ -15,13 +16,13 @@
path('admin/', admin.site.urls),
path('welcome/', welcome_user_view),
path('banned/<slug:username>/', is_username_banned_view),
path('user-info-by-username/<int:username>/', get_user_info_by_username_view),
path('user-info-by-username/<str:username>/', get_user_info_by_username_view),
path('products/', get_products_view),
path('authorization/', authorization_view),
path('process-authorization/', process_authorization_view),
path('me/ip/', show_user_ip_view),
path('user/validate/', validate_user_data_view),
path('user/github/<slug:github_username>/full-name/', validate_user_data_view),
path('text/generate/', generate_file_with_text_view),
# добавлять пути тут
path('greet/<str:name>/<str:language>/', greet_user_in_different_languages_view),
]
5 changes: 3 additions & 2 deletions django_views_routing_homework/views/level_2/c_product_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@


def get_products_view(request):
products = []
# код писать тут
products = PRODUCTS
if product_type := request.GET.get('type'):
products = [product for product in PRODUCTS if product['type'] == product_type]

return JsonResponse(data=products, safe=False)
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
def process_authorization_view(request):
if request.method == 'POST':
data = json.loads(request.body)
# код писать тут
password = USERNAME_TO_PASSWORD_MAPPER.get(data['username'])
status = 200 if password and data['password'] == password else 403
return JsonResponse(data={}, status=status)
else:
return HttpResponseNotAllowed(permitted_methods=['POST'])


# не обращайте внимания на эту вьюху, она нужна лишь для отрисовки страницы авторизации
def authorization_view(request):
return render(request, 'authorization.html')