From c721c9c6b21b56f6d7a57ae3bc261758fb94637b Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Fri, 23 Dec 2011 09:59:07 -0500 Subject: [PATCH] Now in campaign admin, you can pick specific campaign to take action on. --- frontend/templates/campaign_admin.html | 21 +++++++-------- frontend/views.py | 37 ++++++++++++++++++-------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/frontend/templates/campaign_admin.html b/frontend/templates/campaign_admin.html index 92972c47..04a2c662 100644 --- a/frontend/templates/campaign_admin.html +++ b/frontend/templates/campaign_admin.html @@ -30,19 +30,18 @@ {% endif %} +

Campaigns with active transactions

{% if campaigns_with_active_transactions %} +
+ {% csrf_token %} - - {% csrf_token %} + -
-
- {% csrf_token %}
{% else %} @@ -52,13 +51,13 @@

Campaigns with incomplete transactions

{% if campaigns_with_incomplete_transactions %} -
{% csrf_token %} +
{% else %} diff --git a/frontend/views.py b/frontend/views.py index 3d2e4362..f655d49f 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -473,19 +473,34 @@ def campaign_admin(request): command_status = _("Transactions updated based on PaymentDetails and PreapprovalDetails") except Exception, e: check_status_results = e - elif 'execute_campaigns' in request.POST.keys(): - campaigns_with_active_transactions = models.Campaign.objects.filter(transaction__status=IPN_PAY_STATUS_ACTIVE) - results = [pm.execute_campaign(c) for c in campaigns_with_active_transactions] - command_status = str(results) + elif 'execute_campaigns' in request.POST.keys(): + c_id = request.POST.get('active_campaign', None) + if c_id is not None: + try: + campaign = models.Campaign.objects.get(id=c_id) + results = pm.execute_campaign(campaign) + command_status = str(results) + except Exception, e: + command_status = "Error in executing transactions for campaign %s " % (str(e)) elif 'finish_campaigns' in request.POST.keys(): - campaigns_with_incomplete_transactions = models.Campaign.objects.filter(transaction__status=IPN_PAY_STATUS_INCOMPLETE) - results = [pm.finish_campaign(c) for c in campaigns_with_incomplete_transactions] - command_status = str(results) - pass + c_id = request.POST.get('incomplete_campaign', None) + if c_id is not None: + try: + campaign = models.Campaign.objects.get(id=c_id) + results = pm.finish_campaign(campaign) + command_status = str(results) + except Exception, e: + command_status = "Error in finishing transactions for campaign %s " % (str(e)) + elif 'cancel_campaigns' in request.POST.keys(): - campaigns_with_active_transactions = models.Campaign.objects.filter(transaction__status=IPN_PAY_STATUS_ACTIVE) - results = [pm.cancel_campaign(c) for c in campaigns_with_active_transactions] - command_status = str(results) + c_id = request.POST.get('active_campaign', None) + if c_id is not None: + try: + campaign = models.Campaign.objects.get(id=c_id) + results = pm.cancel_campaign(campaign) + command_status = str(results) + except Exception, e: + command_status = "Error in canceling transactions for campaign %s " % (str(e)) (campaigns_with_active_transactions, campaigns_with_incomplete_transactions, campaigns_with_completed_transactions, campaigns_with_canceled_transactions) = campaigns_types()