From 442ae435e75a0bd46e65a7669a1139f861e5ac33 Mon Sep 17 00:00:00 2001 From: amurasm <101619423+amurasm@users.noreply.github.com> Date: Tue, 15 Mar 2022 20:34:18 +0400 Subject: [PATCH 01/11] =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.1-first-project/first_project/app/views.py | 15 +++++++++++---- .../first_project/first_project/urls.py | 7 +++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/1.1-first-project/first_project/app/views.py b/1.1-first-project/first_project/app/views.py index ad1b3dec0..16aff26fb 100644 --- a/1.1-first-project/first_project/app/views.py +++ b/1.1-first-project/first_project/app/views.py @@ -1,3 +1,6 @@ +from datetime import datetime +from os import listdir + from django.http import HttpResponse from django.shortcuts import render, reverse @@ -8,8 +11,8 @@ def home_view(request): # функцию `reverse` pages = { 'Главная страница': reverse('home'), - 'Показать текущее время': '', - 'Показать содержимое рабочей директории': '' + 'Показать текущее время': reverse('time'), + 'Показать содержимое рабочей директории': reverse('workdir') } # context и параметры render менять не нужно @@ -23,7 +26,7 @@ def home_view(request): def time_view(request): # обратите внимание – здесь HTML шаблона нет, # возвращается просто текст - current_time = None + current_time = datetime.now().strftime("%Y.%m.%d %H:%M:%S") msg = f'Текущее время: {current_time}' return HttpResponse(msg) @@ -32,4 +35,8 @@ def workdir_view(request): # по аналогии с `time_view`, напишите код, # который возвращает список файлов в рабочей # директории - raise NotImplemented + list_dir = listdir() + msg = '' + for item in list_dir: + msg = msg + '
' + item + '
' + return HttpResponse(msg) diff --git a/1.1-first-project/first_project/first_project/urls.py b/1.1-first-project/first_project/first_project/urls.py index 9cff514f1..3c6d45ae0 100644 --- a/1.1-first-project/first_project/first_project/urls.py +++ b/1.1-first-project/first_project/first_project/urls.py @@ -16,14 +16,13 @@ from django.contrib import admin from django.urls import path, include -from app.views import home_view - +from app.views import home_view, workdir_view, time_view urlpatterns = [ path('', home_view, name='home'), # Раскомментируйте код, чтобы данные урлы # обрабатывались Django - # path('current_time/', time_view, name='time'), - # path('workdir/', workdir_view, name='workdir'), + path('current_time/', time_view, name='time'), + path('workdir/', workdir_view, name='workdir'), path('admin/', admin.site.urls), ] From 49e9c1458f23880528e69b5f75738c6c9335f9a2 Mon Sep 17 00:00:00 2001 From: amurasm <101619423+amurasm@users.noreply.github.com> Date: Sun, 20 Mar 2022 21:16:24 +0400 Subject: [PATCH 02/11] =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calculator/templates/calculator/index.html | 5 ++++- .../recipes/calculator/templatetags/__init__.py | 0 .../recipes/calculator/templatetags/extras.py | 12 ++++++++++++ 1.2-requests-templates/recipes/calculator/views.py | 13 +++++++++++++ 1.2-requests-templates/recipes/recipes/settings.py | 1 + 1.2-requests-templates/recipes/recipes/urls.py | 3 +++ 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 1.2-requests-templates/recipes/calculator/templatetags/__init__.py create mode 100644 1.2-requests-templates/recipes/calculator/templatetags/extras.py diff --git a/1.2-requests-templates/recipes/calculator/templates/calculator/index.html b/1.2-requests-templates/recipes/calculator/templates/calculator/index.html index bc607f1fd..f67db2580 100644 --- a/1.2-requests-templates/recipes/calculator/templates/calculator/index.html +++ b/1.2-requests-templates/recipes/calculator/templates/calculator/index.html @@ -5,10 +5,13 @@{{ ingredient }}: {{ amount }}
+{{ ingredient }}: {% multiply amount servings %}
{% empty %}Такого рецепта не знаю :(
{% endfor %} + +