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 %} +