# -*- coding: utf-8 -*- from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required from django.core.urlresolvers import reverse from django.views.decorators.csrf import csrf_protect from ..models import License, LicensePrice from ..consts import PAYFORMS from ..forms import LicenseForm @login_required @csrf_protect def order_license(request): """заказ лицензии """ template_name = 'customer/profile/license.html' form = LicenseForm(request.POST or None, initial = {'term': LicensePrice.objects.all()[0], 'payform': 0}) dictionary = { 'form': form, } if form.is_valid(): new_license = License(user=request.user, term=form.cleaned_data['term'].term, payform=form.cleaned_data['payform'], pay_sum=form.cleaned_data['term'].price, paid_date=form.cleaned_data['term'].price, ) new_license.save() return redirect(reverse('customer_license_list')) return render(request, template_name, dictionary) def license_list(request): """Список счетов на лицензии """ template_name = 'customer/profile/license_list.html' licenses = License.objects.filter(user=request.user).order_by('-id') dictionary = { 'licenses': licenses, } return render(request, template_name, dictionary) def paid_list(request): """Оплаченные лицензии """ template_name = 'customer/profile/paid_list.html' licenses = License.objects.filter(user=request.user, status__in=[-1, 1, 2, 3]).order_by('-id') dictionary = { 'licenses': licenses, } return render(request, template_name, dictionary)