Skip to content

Commit

Permalink
Move SelectPlanView methods into PlanViewBase to use as superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
nospame committed Aug 27, 2024
1 parent 0859efb commit c3475f7
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions corehq/apps/domain/views/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit c3475f7

Please sign in to comment.