diff --git a/project/customer/urls.py b/project/customer/urls.py index 795318c..ca5a222 100644 --- a/project/customer/urls.py +++ b/project/customer/urls.py @@ -16,6 +16,7 @@ urlpatterns = patterns('', url(r'^profile/edit/$', profile.profile_edit, name='customer_profile_edit'), url(r'^profile/email/$', profile.profile_email, name='customer_profile_email'), url(r'^license/$', license.order_license, name='customer_order_license'), + url(r'^delete_license/(?P\d+)/$', license.delete_license, name='customer_order_license'), url(r'^robokassa/result/$', license.payment_result, name='robokassa_result'), url(r'^robokassa/success/$', license.payment_success, name='robokassa_success'), url(r'^robokassa/fail/$', license.payment_fail, name='robokassa_fail'), diff --git a/project/customer/views/license.py b/project/customer/views/license.py index 979b0e4..6ff6b31 100644 --- a/project/customer/views/license.py +++ b/project/customer/views/license.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import json import hashlib from django.shortcuts import render, redirect @@ -56,7 +57,7 @@ def license_list(request): """Список счетов на лицензии """ template_name = 'customer/profile/license_list.html' - licenses = License.objects.filter(user=request.user).order_by('-id') + licenses = License.objects.filter(user=request.user, deleted=False).order_by('-id') dictionary = { 'licenses': licenses, } @@ -68,7 +69,8 @@ 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') + licenses = License.objects.filter(user=request.user, + status__in=[-1, 1, 2, 3], deleted=False).order_by('-id') dictionary = { 'licenses': licenses, } @@ -77,13 +79,20 @@ def paid_list(request): @login_required def delete_license(request, pk): - template_name = 'customer/profile/delete_license.html' + if not request.is_ajax(): + return HttpResponseBadRequest() + try: - license = License.objects.get(pk=pk) + license = License.objects.get(pk=pk, status=0, user=request.user) + if request.method == 'POST': + license.deleted = True + license.save() + dictionary = {'res': 'Ok', 'id': pk} except: - raise Http404 - dictionary = {'license': license} - return render(request, template_name, dictionary) + dictionary = {'res': 'fail'} + + data = json.dumps(dictionary) + return HttpResponse(data, mimetype='application/json') @csrf_exempt diff --git a/project/myauth/views.py b/project/myauth/views.py index 363c3d7..c116989 100644 --- a/project/myauth/views.py +++ b/project/myauth/views.py @@ -102,6 +102,7 @@ def confirm_registered_email(request, key): user.profile.confirmed = True user.profile.active = True user.profile.save() + auth.logout(request) return redirect(success_url) diff --git a/project/static/js/license.js b/project/static/js/license.js index 91ce213..fa1084e 100644 --- a/project/static/js/license.js +++ b/project/static/js/license.js @@ -10,9 +10,30 @@ $(document).ready(function() { $($('[name="term"]')[0]).closest('li').show(); } } + show_month(); $('[name="payform"]').change(function(){ show_month() }); + + $('.delete_license').click(function(e){ + e.preventDefault(); + var lic_pk = $(this).data('id'); + + $('#dialogs').html('Удалить?'); + $('#dialogs').dialog({ + buttons: { + "Да": function(){ + $.post('/my/delete_license/' + lic_pk + '/', function(data){ + $('.license_' + data['id']).remove() + }); + $(this).dialog("close"); + }, + "Нет": function(){ + $(this).dialog("close"); + } + } + }) + }) }); diff --git a/project/templates/customer/profile/license_list.html b/project/templates/customer/profile/license_list.html index 23d1a94..11a9a75 100644 --- a/project/templates/customer/profile/license_list.html +++ b/project/templates/customer/profile/license_list.html @@ -7,14 +7,19 @@ Оплаченные лицензии

Выписанные счета

{% for license in licenses %} -
+
{{ license.id }}
{{ license.order_date }}
{{ license.term }}
{{ license.get_payform_display }}
{{ license.get_status_display }}
{{ license.get_action }}
+
{% if license.status == 0 %}Удалить{% endif %}
{% endfor %} {% endblock %} + +{% block js %} + +{% endblock %}