From c3475f72d6cd1e38b577f0f88428c0d1694c56d4 Mon Sep 17 00:00:00 2001 From: nospame Date: Tue, 27 Aug 2024 15:33:51 -0700 Subject: [PATCH] Move SelectPlanView methods into PlanViewBase to use as superclass --- corehq/apps/domain/views/accounting.py | 47 ++++++++++++++------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/corehq/apps/domain/views/accounting.py b/corehq/apps/domain/views/accounting.py index 96716f23cff4..0972eaedb70a 100644 --- a/corehq/apps/domain/views/accounting.py +++ b/corehq/apps/domain/views/accounting.py @@ -963,24 +963,10 @@ def is_form_editable(self): ) -class SelectPlanView(DomainAccountingSettings): - template_name = 'domain/select_plan.html' - urlname = 'domain_select_plan' +class PlanViewBase(DomainAccountingSettings): page_title = gettext_lazy("Change Plan") - step_title = gettext_lazy("Select Plan") - edition = None lead_text = gettext_lazy("Please select a plan below that fits your organization's needs.") - - def dispatch(self, request, *args, **kwargs): - if not self.can_change_subscription: - raise Http404() - return super().dispatch(request, *args, **kwargs) - - @property - def can_change_subscription(self): - subscription = self.current_subscription - is_annual_plan = subscription.plan_version.plan.is_annual_plan - return not is_annual_plan + edition = None @property @memoized @@ -1071,7 +1057,7 @@ def steps(self): @property def main_context(self): - context = super(SelectPlanView, self).main_context + context = super().main_context context.update({ 'steps': self.steps, 'step_title': self.step_title, @@ -1115,7 +1101,24 @@ def page_context(self): } -class SelectedEnterprisePlanView(SelectPlanView): +class SelectPlanView(PlanViewBase): + template_name = 'domain/select_plan.html' + urlname = 'domain_select_plan' + step_title = gettext_lazy("Select Plan") + + def dispatch(self, request, *args, **kwargs): + if not self.can_change_subscription: + raise Http404() + return super().dispatch(request, *args, **kwargs) + + @property + def can_change_subscription(self): + subscription = self.current_subscription + is_annual_plan = subscription.plan_version.plan.is_annual_plan + return not is_annual_plan + + +class SelectedEnterprisePlanView(PlanViewBase): template_name = 'domain/selected_enterprise_plan.html' urlname = 'enterprise_request_quote' step_title = gettext_lazy("Contact Dimagi") @@ -1157,7 +1160,7 @@ def post(self, request, *args, **kwargs): return self.get(request, *args, **kwargs) -class SelectedAnnualPlanView(SelectPlanView): +class SelectedAnnualPlanView(PlanViewBase): template_name = 'domain/selected_annual_plan.html' urlname = 'annual_plan_request_quote' step_title = gettext_lazy("Contact Dimagi") @@ -1219,7 +1222,7 @@ def post(self, request, *args, **kwargs): return self.get(request, *args, **kwargs) -class ConfirmSelectedPlanView(SelectPlanView): +class ConfirmSelectedPlanView(PlanViewBase): template_name = 'domain/confirm_plan.html' urlname = 'confirm_selected_plan' @@ -1540,7 +1543,7 @@ def subscription(self): return subscription -class SubscriptionRenewalView(SelectPlanView, SubscriptionMixin): +class SubscriptionRenewalView(PlanViewBase, SubscriptionMixin): urlname = "domain_subscription_renewal" page_title = gettext_lazy("Renew Plan") step_title = gettext_lazy("Renew Plan") @@ -1594,7 +1597,7 @@ def page_context(self): return context -class ConfirmSubscriptionRenewalView(SelectPlanView, DomainAccountingSettings, +class ConfirmSubscriptionRenewalView(PlanViewBase, DomainAccountingSettings, AsyncHandlerMixin, SubscriptionMixin): template_name = 'domain/confirm_subscription_renewal.html' urlname = 'domain_subscription_renewal_confirmation'