From 15a75ce78d24291eaf9475a3ec47fb50b6f77024 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 27 Sep 2017 15:08:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D1=83=D0=B6=D0=BD=D0=BE=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20csv=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BF=D0=BA=D1=83=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lms/urls.py | 1 + lms/views.py | 48 ++++++++++++- templates/index_menu.html | 5 ++ templates/price.html | 145 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 198 insertions(+), 1 deletion(-) create mode 100755 templates/price.html diff --git a/lms/urls.py b/lms/urls.py index 8d6616d..2424496 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -9,6 +9,7 @@ from access.views import profile_view urlpatterns = [ url(r'^$', views.index), + url(r'^price/$', views.price), url(r'^oferta/', views.show_oferta), url(r'^test/$', views.test), url(r'^all_comments/$', views.all_comments), diff --git a/lms/views.py b/lms/views.py index 41f3d5b..b38c0b4 100644 --- a/lms/views.py +++ b/lms/views.py @@ -10,7 +10,11 @@ from finance.models import Bill from courses.templates import comment_fabric from library.models import Article from management.reports import get_now_success_hw, get_second_success_hw -from django.http import HttpResponse +from django.http import HttpResponse +from django.template.defaulttags import register +from lms.settings import STATIC_ROOT +import csv + def sortByTimeStamp(inputStr): return inputStr['sort'] @@ -27,6 +31,48 @@ def access_error(request): return {} +@response_decor(template='price.html', without_auth=True) +def price(request): + if request.user.is_authenticated() and request.user.in_role in ['M', 'S']: + return {'redirect': '/access/profile'} + journals = [] + for course in Course.objects.all() if request.user.is_authenticated() and request.user.is_admin else Course.objects.filter(public=True): + do = True + if course.hidden: + if not request.user.is_authenticated(): + do = False + else: + if not request.user.is_admin: + try: + Bill.objects.get(service__course=course, user=request.user, status='F') + except Bill.DoesNotExist: + do = False + if do: + journal, created = TeacherJ.objects.get_or_create(course=course, student=user_fabric(request.user)) + if not journal.full and Bill.objects.filter(user=user_fabric(request.user), service__course=course, status='F').exists(): + if not journal.start_date: + journal.start_date = datetime.datetime.now() + journal.save() + check_journal(journal) + journals.append(journal.get_head_face()) + + with open(STATIC_ROOT+'/prices.csv', mode='r') as infile: + reader = csv.reader(infile) + prices = {} + + for rows in reader: + prices[int(rows[0])] = rows[1] + + @register.filter + def get_item(dictionary, key): + return dictionary.get(key) + + return {'courses': journals, + 'prices': prices, + 'directions': ({'count': i.count(), 'title': i.title, 'color': i.color} for i in MaterialDirection.objects.all() if i.count() != 0), + 'bought': Bill.objects.filter(user=request.user, status='F').exists() if request.user.is_authenticated() else False} + + @response_decor(template='index.html', without_auth=True) def index(request): if request.user.is_authenticated() and request.user.in_role in ['M', 'S']: diff --git a/templates/index_menu.html b/templates/index_menu.html index b326dfd..59d11b7 100755 --- a/templates/index_menu.html +++ b/templates/index_menu.html @@ -122,6 +122,11 @@ Контакты + {% if request.user.is_anonymous %} +
  • + Цены +
  • + {% endif %}
  • Помощь
  • diff --git a/templates/price.html b/templates/price.html new file mode 100755 index 0000000..76b299b --- /dev/null +++ b/templates/price.html @@ -0,0 +1,145 @@ +{% extends 'base_index.html' %} +{% load static %} +{% block page_title %}Доступные курсы «{{ NAME }}»{% endblock %} +{% block title %}Доступные курсы «{{ NAME }}»{% endblock %} +{% block head %} + + {% if bought %} + + {% endif %} +{% endblock %} +{% block content %} +
    + +
    + {% include 'right_site.html' %} + + + + + + + + + + +{% endblock %} + +{% block js %} + +{% endblock %}