From 1497ff204b37efc01c62714910a40245ea5db256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 9 Jan 2018 17:56:48 +0200 Subject: [PATCH] Fix active plan display in the pricing page. --- hc/payments/tests/test_pricing.py | 11 +++++++++++ hc/payments/views.py | 7 +++++-- templates/accounts/billing.html | 4 ++-- templates/payments/pricing.html | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/hc/payments/tests/test_pricing.py b/hc/payments/tests/test_pricing.py index f53fe6b2..147a934c 100644 --- a/hc/payments/tests/test_pricing.py +++ b/hc/payments/tests/test_pricing.py @@ -35,3 +35,14 @@ class PricingTestCase(BaseTestCase): r = self.client.get("/pricing/") self.assertContains(r, "To manage this team") + + def test_it_shows_active_plan(self): + self.sub = Subscription(user=self.alice) + self.sub.subscription_id = "test-id" + self.sub.plan_id = "P5" + self.sub.save() + + self.client.login(username="alice@example.org", password="password") + + r = self.client.get("/pricing/") + self.assertContains(r, "Standard (monthly)", status_code=200) diff --git a/hc/payments/views.py b/hc/payments/views.py index 98eb7646..c5ed8c26 100644 --- a/hc/payments/views.py +++ b/hc/payments/views.py @@ -3,7 +3,6 @@ from django.contrib.auth.decorators import login_required from django.http import (HttpResponseBadRequest, HttpResponseForbidden, JsonResponse, HttpResponse) from django.shortcuts import get_object_or_404, redirect, render -from django.template.loader import render_to_string from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST import six @@ -24,7 +23,11 @@ def pricing(request): ctx = {"page": "pricing"} return render(request, "payments/pricing_not_owner.html", ctx) - ctx = {"page": "pricing"} + # Don't use Subscription.objects.for_user method here, so a + # subscription object is not created just by viewing a page. + sub = Subscription.objects.filter(user_id=request.user.id).first() + + ctx = {"page": "pricing", "sub": sub} return render(request, "payments/pricing.html", ctx) diff --git a/templates/accounts/billing.html b/templates/accounts/billing.html index cf33b984..382a7044 100644 --- a/templates/accounts/billing.html +++ b/templates/accounts/billing.html @@ -238,7 +238,7 @@ value="Y48" {% if sub.plan_id == "Y48" %} checked {% endif %}> - Yearly, $48/year (20% off monthly) + Annual, $48/year (20% off monthly)

Plus Unlimited checks, unlimited team members

@@ -259,7 +259,7 @@ value="Y480" {% if sub.plan_id == "Y480" %} checked {% endif %}> - Yearly, $480/year (20% off monthly) + Annual, $480/year (20% off monthly)
diff --git a/templates/payments/pricing.html b/templates/payments/pricing.html index ef8e036a..b1ca07ad 100644 --- a/templates/payments/pricing.html +++ b/templates/payments/pricing.html @@ -15,13 +15,13 @@

Your account is currently on the {% if sub.plan_id == "P5" %} - Monthly Standard + Standard (monthly) {% elif sub.plan_id == "P50" %} - Monthly Plus + Plus (monthly) {% elif sub.plan_id == "Y48" %} - Yearly Standard + Standard (annual) {% elif sub.plan_id == "Y480" %} - Yearly Plus + Plus (annual) {% else %} Free {% endif %}