From 0a02cc8367a5554e9330e2ae4498daa297507293 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 6 Mar 2018 11:20:08 +0300 Subject: [PATCH] Fix index view --- project/urls.py | 14 +++----------- project/views.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 project/views.py diff --git a/project/urls.py b/project/urls.py index f620359c..9a1c055b 100644 --- a/project/urls.py +++ b/project/urls.py @@ -24,13 +24,13 @@ from apps.course.views import ( lessoncomment, CourseEditView, CourseOnModerationView, ) -from apps.course.models import Course from apps.user.views import ( UserView, UserEditView, NotificationEditView, PaymentHistoryView, resend_email_verify, ) from apps.payment.views import CourseBuyView, PaymentwallCallbackView, SchoolBuyView -from apps.school.models import SchoolSchedule + +from .views import IndexView urlpatterns = [ path('admin/', admin.site.urls), @@ -61,15 +61,7 @@ urlpatterns = [ path('privacy', TemplateView.as_view(template_name="templates/lilcity/privacy_policy.html"), name='privacy'), path('terms', TemplateView.as_view(template_name="templates/lilcity/terms.html"), name='terms'), path('refund-policy', TemplateView.as_view(template_name="templates/lilcity/refund_policy.html"), name='refund_policy'), - path('', - TemplateView.as_view( - template_name="templates/lilcity/main.html", - extra_context={ - 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:3], - 'school_schedules': SchoolSchedule.objects.all(), - }), - name='index' - ), + path('', IndexView.as_view(), name='index'), path('api/v1/', include(('api.v1.urls', 'api_v1'))), path('test', TemplateView.as_view(template_name="templates/lilcity/test.html"), name='test'), ] diff --git a/project/views.py b/project/views.py new file mode 100644 index 00000000..9dafb0a4 --- /dev/null +++ b/project/views.py @@ -0,0 +1,16 @@ +from django.views.generic import TemplateView + +from apps.course.models import Course +from apps.school.models import SchoolSchedule + + +class IndexView(TemplateView): + template_name = 'templates/lilcity/main.html' + + def get_context_data(self): + context = super().get_context_data() + context.update({ + 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:3], + 'school_schedules': SchoolSchedule.objects.all(), + }) + return context