subscriptions package

Submodules

subscriptions.abstract module

Abstract templates for the Djanog Flexible Subscriptions app.

class subscriptions.abstract.CreateView(**kwargs)

Bases: django.views.generic.edit.CreateView

Extends CreateView to specify of extensible HTML template

template_extends

Path to HTML template that this view extends.

Type:str
get_context_data(**kwargs)

Overriding get_context_data to add additional context.

template_extends = 'subscriptions/base.html'
class subscriptions.abstract.DeleteView(**kwargs)

Bases: django.views.generic.edit.DeleteView

Extends DeleteView to specify of extensible HTML template

template_extends

Path to HTML template that this view extends.

Type:str
get_context_data(**kwargs)

Overriding get_context_data to add additional context.

template_extends = 'subscriptions/base.html'
class subscriptions.abstract.DetailView(**kwargs)

Bases: django.views.generic.detail.DetailView

Extends DetailView to specify of extensible HTML template

template_extends

Path to HTML template that this view extends.

Type:str
get_context_data(**kwargs)

Overriding get_context_data to add additional context.

template_extends = 'subscriptions/base.html'
class subscriptions.abstract.ListView(**kwargs)

Bases: django.views.generic.list.ListView

Extends ListView to specify of extensible HTML template

template_extends

Path to HTML template that this view extends.

Type:str
get_context_data(*, object_list=None, **kwargs)

Overriding get_context_data to add additional context.

template_extends = 'subscriptions/base.html'
class subscriptions.abstract.TemplateView(**kwargs)

Bases: django.views.generic.base.TemplateView

Extends TemplateView to specify of extensible HTML template.

template_extends

Path to HTML template that this view extends.

Type:str
get_context_data(**kwargs)

Overriding get_context_data to add additional context.

template_extends = 'subscriptions/base.html'
class subscriptions.abstract.UpdateView(**kwargs)

Bases: django.views.generic.edit.UpdateView

Extends UpdateView to specify of extensible HTML template

template_extends

Path to HTML template that this view extends.

Type:str
get_context_data(**kwargs)

Overriding get_context_data to add additional context.

template_extends = 'subscriptions/base.html'

subscriptions.conf module

Functions for general package configuration.

subscriptions.conf.compile_settings()

Compiles and validates all package settings and defaults.

Provides basic checks to ensure required settings are declared and applies defaults for all missing settings.

Returns:All possible Django Flexible Subscriptions settings.
Return type:dict
subscriptions.conf.determine_currency_settings()

Determines details for Currency handling.

Validates the provided currency locale setting and then returns a Currency object.

Returns:a Currency object for the provided setting.
Return type:obj
subscriptions.conf.string_to_module_and_class(string)

Breaks a string to a module and class name component.

subscriptions.conf.validate_currency_settings(currency_locale)

Validates provided currency settings.

Parameters
currency_locale (str or dict): a currency locale string or
a dictionary defining custom currency formating conventions.
Raises:
  • ImproperlyConfigured – specified string currency_locale not support.
  • TypeError – invalid parameter type provided.

subscriptions.forms module

Forms for Django Flexible Subscriptions.

class subscriptions.forms.PaymentForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)

Bases: django.forms.forms.Form

Form to collect details required for payment billing.

CC_MONTHS = (('1', '01 - January'), ('2', '02 - February'), ('3', '03 - March'), ('4', '04 - April'), ('5', '05 - May'), ('6', '06 - June'), ('7', '07 - July'), ('8', '08 - August'), ('9', '09 - September'), ('10', '10 - October'), ('11', '11 - November'), ('12', '12 - December'))
CC_YEARS = [(2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024), (2025, 2025), (2026, 2026), (2027, 2027), (2028, 2028), (2029, 2029), (2030, 2030), (2031, 2031), (2032, 2032), (2033, 2033), (2034, 2034), (2035, 2035), (2036, 2036), (2037, 2037), (2038, 2038), (2039, 2039), (2040, 2040), (2041, 2041), (2042, 2042), (2043, 2043), (2044, 2044), (2045, 2045), (2046, 2046), (2047, 2047), (2048, 2048), (2049, 2049), (2050, 2050), (2051, 2051), (2052, 2052), (2053, 2053), (2054, 2054), (2055, 2055), (2056, 2056), (2057, 2057), (2058, 2058), (2059, 2059), (2060, 2060), (2061, 2061), (2062, 2062), (2063, 2063), (2064, 2064), (2065, 2065), (2066, 2066), (2067, 2067), (2068, 2068), (2069, 2069), (2070, 2070), (2071, 2071), (2072, 2072), (2073, 2073), (2074, 2074), (2075, 2075), (2076, 2076), (2077, 2077), (2078, 2078), (2079, 2079)]
base_fields = {'address_city': <django.forms.fields.CharField object>, 'address_country': <django.forms.fields.CharField object>, 'address_line_1': <django.forms.fields.CharField object>, 'address_line_2': <django.forms.fields.CharField object>, 'address_line_3': <django.forms.fields.CharField object>, 'address_name': <django.forms.fields.CharField object>, 'address_postcode': <django.forms.fields.CharField object>, 'address_province': <django.forms.fields.CharField object>, 'address_title': <django.forms.fields.CharField object>, 'card_cvv': <django.forms.fields.CharField object>, 'card_expiry_month': <django.forms.fields.ChoiceField object>, 'card_expiry_year': <django.forms.fields.ChoiceField object>, 'card_number': <django.forms.fields.CharField object>, 'cardholder_name': <django.forms.fields.CharField object>}
declared_fields = {'address_city': <django.forms.fields.CharField object>, 'address_country': <django.forms.fields.CharField object>, 'address_line_1': <django.forms.fields.CharField object>, 'address_line_2': <django.forms.fields.CharField object>, 'address_line_3': <django.forms.fields.CharField object>, 'address_name': <django.forms.fields.CharField object>, 'address_postcode': <django.forms.fields.CharField object>, 'address_province': <django.forms.fields.CharField object>, 'address_title': <django.forms.fields.CharField object>, 'card_cvv': <django.forms.fields.CharField object>, 'card_expiry_month': <django.forms.fields.ChoiceField object>, 'card_expiry_year': <django.forms.fields.ChoiceField object>, 'card_number': <django.forms.fields.CharField object>, 'cardholder_name': <django.forms.fields.CharField object>}
media
class subscriptions.forms.PlanCostForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)

Bases: django.forms.models.ModelForm

Form to use with inlineformset_factory and SubscriptionPlanForm.

class Meta

Bases: object

fields = ['recurrence_period', 'recurrence_unit', 'cost']
model

alias of subscriptions.models.PlanCost

base_fields = {'cost': <django.forms.fields.DecimalField object>, 'recurrence_period': <django.forms.fields.IntegerField object>, 'recurrence_unit': <django.forms.fields.TypedChoiceField object>}
declared_fields = {}
media
class subscriptions.forms.SubscriptionPlanCostForm(*args, **kwargs)

Bases: django.forms.forms.Form

Form to handle choosing a subscription plan for payment.

base_fields = {'plan_cost': <django.forms.fields.UUIDField object>}
clean_plan_cost()

Validates that UUID is valid and returns model instance.

declared_fields = {'plan_cost': <django.forms.fields.UUIDField object>}
media
class subscriptions.forms.SubscriptionPlanForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)

Bases: django.forms.models.ModelForm

Model Form for SubscriptionPlan model.

class Meta

Bases: object

fields = ['plan_name', 'plan_description', 'group', 'tags', 'grace_period']
model

alias of subscriptions.models.SubscriptionPlan

base_fields = {'grace_period': <django.forms.fields.IntegerField object>, 'group': <django.forms.models.ModelChoiceField object>, 'plan_description': <django.forms.fields.CharField object>, 'plan_name': <django.forms.fields.CharField object>, 'tags': <django.forms.models.ModelMultipleChoiceField object>}
declared_fields = {}
media
subscriptions.forms.assemble_cc_years()

Creates a list of the next 60 years.

subscriptions.models module

Models for the Flexible Subscriptions app.

class subscriptions.models.PlanCost(*args, **kwargs)

Bases: django.db.models.base.Model

Cost and frequency of billing for a plan.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

cost

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

display_billing_frequency_text

Generates human-readable billing frequency.

display_recurrent_unit_text

Converts recurrence_unit integer to text.

get_recurrence_unit_display(*, field=<django.db.models.fields.CharField: recurrence_unit>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

next_billing_datetime(current)

Calculates next billing date for provided datetime.

Parameters:current (datetime) – The current datetime to compare against.
Returns:The next time billing will be due.
Return type:datetime
objects = <django.db.models.manager.Manager object>
plan

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

plan_id
recurrence_period

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

recurrence_unit

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

slug

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

subscriptions

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

transactions

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class subscriptions.models.PlanList(*args, **kwargs)

Bases: django.db.models.base.Model

Model to record details of a display list of SubscriptionPlans.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

footer

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

header

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
plan_list_details

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

slug

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

subtitle

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

title

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class subscriptions.models.PlanListDetail(*args, **kwargs)

Bases: django.db.models.base.Model

Model to add additional details to plans when part of PlanList.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

html_content

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
order

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

plan

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

plan_id
plan_list

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

plan_list_id
subscribe_button_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class subscriptions.models.PlanTag(*args, **kwargs)

Bases: django.db.models.base.Model

A tag for a subscription plan.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
plans

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

tag

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class subscriptions.models.SubscriptionPlan(*args, **kwargs)

Bases: django.db.models.base.Model

Details for a subscription plan.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

costs

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

display_tags()

Displays tags as a string (truncates if more than 3).

grace_period

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

group

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

group_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
plan_description

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

plan_list_details

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

plan_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

slug

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

tags

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class subscriptions.models.SubscriptionTransaction(*args, **kwargs)

Bases: django.db.models.base.Model

Details for a subscription plan billing.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

amount

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_transaction

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_date_transaction(*, field=<django.db.models.fields.DateTimeField: date_transaction>, is_next=True, **kwargs)
get_previous_by_date_transaction(*, field=<django.db.models.fields.DateTimeField: date_transaction>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
subscription

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

subscription_id
user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id
class subscriptions.models.UserSubscription(*args, **kwargs)

Bases: django.db.models.base.Model

Details of a user’s specific subscription.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

active

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

cancelled

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_billing_end

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_billing_last

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_billing_next

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_billing_start

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
subscription

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

subscription_id
user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id

subscriptions.management.commands._manager module

Utility/helper functions for Django Flexible Subscriptions.

class subscriptions.management.commands._manager.Manager

Bases: object

Manager object to help manage subscriptions & billing.

notify_expired(subscription)

Sends notification of expired subscription.

Parameters:subscription (obj) – A UserSubscription instance.
notify_new(subscription)

Sends notification of newly active subscription

Parameters:subscription (obj) – A UserSubscription instance.
notify_payment_error(subscription)

Sends notification of a payment error

Parameters:subscription (obj) – A UserSubscription instance.
notify_payment_success(subscription)

Sends notifiation of a payment success

Parameters:subscription (obj) – A UserSubscription instance.
process_due(subscription)

Handles processing of a due subscription.

Parameters:subscription (obj) – A UserSubscription instance.
process_expired(subscription)

Handles processing of expired/cancelled subscriptions.

Parameters:subscription (obj) – A UserSubscription instance.
process_new(subscription)

Handles processing of a new subscription.

Parameters:subscription (obj) – A UserSubscription instance.
process_payment(*args, **kwargs)

Processes payment and confirms if payment is accepted.

This method needs to be overriden in a project to handle payment processing with the appropriate payment provider.

Can return value that evalutes to True to indicate payment success and any value that evalutes to False to indicate payment error.

process_subscriptions()

Calls all required subscription processing functions.

static record_transaction(subscription, transaction_date=None)

Records transaction details in SubscriptionTransaction.

Parameters:
  • subscription (obj) – A UserSubscription object.
  • transaction_date (obj) – A DateTime object of when payment occurred (defaults to current datetime if none provided).
Returns:

The created SubscriptionTransaction instance.

Return type:

obj

retrieve_transaction_date(payment)

Returns the transaction date from provided payment details.

Method should be overriden to accomodate the implemented payment processing if a more accurate datetime is required.

Returns
obj: The current datetime.

subscriptions.views module

Views for the Flexible Subscriptions app.

class subscriptions.views.DashboardView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.TemplateView

Dashboard view to manage subscription details.

permission_required = 'subscriptions.subscriptions'
raise_exception = True
template_name = 'subscriptions/dashboard.html'
class subscriptions.views.PlanCreateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.CreateView

View to create a new subscription plan.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful creation.

Type:str
success_url

URL to redirect to on successful creation.

Type:str
context_object_name = 'plan'
form_class

alias of subscriptions.forms.SubscriptionPlanForm

form_invalid(form, cost_forms)

Handles re-rendering invalid forms with errors.

Parameters:
  • form (obj) – Parent SubscriptionPlanForm instance to return.
  • cost_forms (obj) – PlanCostFormSet instance to return.
Returns:

Renders original page with form content.

Return type:

obj

form_valid(form, cost_forms)

Handles processing of valid forms.

Parameters:
  • form (obj) – Parent SubscriptionPlanForm instance to process.
  • cost_forms (obj) – PlanCostFormSet instance to process.
Returns:

HttpResponseRedirect object to success_url.

Return type:

obj

get(request, *args, **kwargs)

Overriding get method to handle inline formset.

model

alias of subscriptions.models.SubscriptionPlan

permission_required = 'subscriptions.subscriptions'
post(request, *args, **kwargs)

Overriding post method to handle inline formsets.

raise_exception = True
success_message = 'Subscription plan successfully added'
success_url = '/dfs/plans/'
template_name = 'subscriptions/plan_create.html'
class subscriptions.views.PlanDeleteView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.DeleteView

View to delete a subscription plan.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful creation.

Type:str
success_url

URL to redirect to on successful creation.

Type:str
context_object_name = 'plan'
delete(request, *args, **kwargs)

Override delete to allow success message to be added.

model

alias of subscriptions.models.SubscriptionPlan

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'plan_id'
raise_exception = True
success_message = 'Subscription plan successfully deleted'
success_url = '/dfs/plans/'
template_name = 'subscriptions/plan_delete.html'
class subscriptions.views.PlanListCreateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.CreateView

View to create a new plan list.

context_object_name = 'plan_list'
fields = ['title', 'subtitle', 'header', 'footer', 'active']
model

alias of subscriptions.models.PlanList

permission_required = 'subscriptions.subscriptions'
raise_exception = True
success_message = 'Plan list successfully added'
success_url = '/dfs/plan-lists/'
template_name = 'subscriptions/plan_list_create.html'
class subscriptions.views.PlanListDeleteView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.DeleteView

View to delete a plan list.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful deletion.

Type:str
success_url

URL to redirect to on successful deletion.

Type:str
context_object_name = 'plan_list'
delete(request, *args, **kwargs)

Override delete to allow success message to be added.

model

alias of subscriptions.models.PlanList

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'plan_list_id'
raise_exception = True
success_message = 'Plan list successfully deleted'
success_url = '/dfs/plan-lists/'
template_name = 'subscriptions/plan_list_delete.html'
class subscriptions.views.PlanListDetailCreateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.CreateView

View to create a new plan list.

fields = ['plan', 'plan_list', 'html_content', 'subscribe_button_text', 'order']
get_context_data(**kwargs)

Extend context to include the parent PlanList object.

get_success_url()

Return the URL to redirect to after processing a valid form.

model

alias of subscriptions.models.PlanListDetail

permission_required = 'subscriptions.subscriptions'
raise_exception = True
success_message = 'Subscription plan successfully added to plan list'
template_name = 'subscriptions/plan_list_detail_create.html'
class subscriptions.views.PlanListDetailDeleteView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.DeleteView

View to delete a plan list detail.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful deletion.

Type:str
success_url

URL to redirect to on successful deletion.

Type:str
context_object_name = 'plan_list_detail'
delete(request, *args, **kwargs)

Override delete to allow success message to be added.

get_context_data(**kwargs)

Extend context to include the parent PlanList object.

get_success_url()
model

alias of subscriptions.models.PlanListDetail

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'plan_list_detail_id'
raise_exception = True
success_message = 'Subscription plan successfully removed from plan list'
template_name = 'subscriptions/plan_list_detail_delete.html'
class subscriptions.views.PlanListDetailListView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.DetailView

List of plan lists.

context_object_name = 'plan_list'
model

alias of subscriptions.models.PlanList

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'plan_list_id'
raise_exception = True
template_name = 'subscriptions/plan_list_detail_list.html'
class subscriptions.views.PlanListDetailUpdateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.UpdateView

View to update the details of a plan list detail.

fields = ['plan', 'plan_list', 'html_content', 'subscribe_button_text', 'order']
get_context_data(**kwargs)

Extend context to include the parent PlanList object.

get_success_url()

Return the URL to redirect to after processing a valid form.

model

alias of subscriptions.models.PlanListDetail

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'plan_list_detail_id'
raise_exception = True
success_message = 'Plan list details successfully updated'
template_name = 'subscriptions/plan_list_detail_update.html'
class subscriptions.views.PlanListListView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.ListView

List of plan lists.

context_object_name = 'plan_lists'
model

alias of subscriptions.models.PlanList

permission_required = 'subscriptions.subscriptions'
raise_exception = True
template_name = 'subscriptions/plan_list_list.html'
class subscriptions.views.PlanListUpdateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.UpdateView

View to update the details of a plan list.

context_object_name = 'plan_list'
fields = ['title', 'subtitle', 'header', 'footer', 'active']
model

alias of subscriptions.models.PlanList

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'plan_list_id'
raise_exception = True
success_message = 'Plan list successfully updated'
success_url = '/dfs/plan-lists/'
template_name = 'subscriptions/plan_list_update.html'
class subscriptions.views.PlanListView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.ListView

List of all subscription plans.

context_object_name = 'plans'
model

alias of subscriptions.models.SubscriptionPlan

permission_required = 'subscriptions.subscriptions'
raise_exception = True
template_name = 'subscriptions/plan_list.html'
class subscriptions.views.PlanUpdateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.UpdateView

View to update a subscription plan.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful creation.

Type:str
success_url

URL to redirect to on successful creation.

Type:str
context_object_name = 'plan'
form_class

alias of subscriptions.forms.SubscriptionPlanForm

form_invalid(form, cost_forms)

Handles re-rendering invalid forms with errors.

Parameters:
  • form (obj) – Parent SubscriptionPlanForm instance to return.
  • cost_forms (obj) – PlanCostFormSet instance to return.
Returns:

Renders original page with form content.

Return type:

obj

form_valid(form, cost_forms)

Handles processing of valid forms.

Parameters:
  • form (obj) – Parent SubscriptionPlanForm instance to process.
  • cost_forms (obj) – PlanCostFormSet instance to process.
Returns:

HttpResponseRedirect object to success_url.

Return type:

obj

get(request, *args, **kwargs)

Overriding get method to handle inline formset.

model

alias of subscriptions.models.SubscriptionPlan

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'plan_id'
post(request, *args, **kwargs)

Overriding post method to handle inline formsets.

raise_exception = True
success_message = 'Subscription plan successfully updated'
success_url = '/dfs/plans/'
template_name = 'subscriptions/plan_update.html'
class subscriptions.views.SubscribeCancelView(**kwargs)

Bases: django.contrib.auth.mixins.LoginRequiredMixin, subscriptions.abstract.DetailView

View to handle cancelling of subscription.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful creation.

Type:str
success_url

URL to redirect to on successful creation.

Type:str
context_object_name = 'subscription'
get_object(queryset=None)

Overrides get_object to restrict to logged in user.

get_success_url()

Returns the success URL.

model

alias of subscriptions.models.UserSubscription

pk_url_kwarg = 'subscription_id'
post(request, *args, **kwargs)

Updates a subscription’s details to cancel it.

success_message = 'Subscription successfully cancelled'
success_url = 'dfs_subscribe_user_list'
template_name = 'subscriptions/subscribe_cancel.html'
class subscriptions.views.SubscribeList(**kwargs)

Bases: subscriptions.abstract.TemplateView

Detail view of the first active PlanList instance.

View is designed to be the user-facing subscription list and customizable through the PlanList and PlanListDetail models.

context_object_name = 'plan_list'
get(request, *args, **kwargs)

Ensures content is available to display, then returns page.

get_context_data(**kwargs)

Extend context to include the parent PlanList object.

template_name = 'subscriptions/subscribe_list.html'
class subscriptions.views.SubscribeThankYouView(**kwargs)

Bases: django.contrib.auth.mixins.LoginRequiredMixin, subscriptions.abstract.TemplateView

A thank you page and summary for a new subscription.

context_object_name = 'transaction'
get_context_data(**kwargs)

Overriding get_context_data to add additional context.

get_object()

Returns the provided transaction instance.

template_name = 'subscriptions/subscribe_thank_you.html'
class subscriptions.views.SubscribeUserList(**kwargs)

Bases: django.contrib.auth.mixins.LoginRequiredMixin, subscriptions.abstract.ListView

List of all a user’s subscriptions.

context_object_name = 'subscriptions'
get_queryset()

Overrides get_queryset to restrict list to logged in user.

model

alias of subscriptions.models.UserSubscription

template_name = 'subscriptions/subscribe_user_list.html'
class subscriptions.views.SubscribeView(**kwargs)

Bases: django.contrib.auth.mixins.LoginRequiredMixin, subscriptions.abstract.TemplateView

View to handle all aspects of the subscribing process.

This view will need to be subclassed and some methods overridden to implement the payment solution.

Additionally, this view is extended from a TemplateView with the additional attributes noted below.

payment_form

Django Form to handle subscription payment.

Type:obj
subscription_plan

A SubscriptionPlan instance. Will be set by methods during processing.

Type:obj
success_url

URL to redirect to on successful creation.

Type:str
template_preview

Path to HTML template for the preview view.

Type:str
template_confirmation

Path to HTML template for the confirmation view.

Type:str

Notes

View only accessible via POST requests. The request must include an ID to a SubscriptionPlan +/- associated PlanCost instance (if past the preview view).

confirmation = False
get(request, *args, **kwargs)

Returns 404 error as this method is not implemented.

get_context_data(**kwargs)

Overriding get_context_data to add additional context.

get_object()

Gets the subscription plan object.

get_success_url(**kwargs)

Returns the success URL.

get_template_names()

Returns the proper template name based on payment stage.

hide_form(form)

Replaces form widgets with hidden inputs.

Parameters:form (obj) – A form instance.
Returns:The modified form instance.
Return type:obj
payment_form

alias of subscriptions.forms.PaymentForm

post(request, *args, **kwargs)

Handles all POST requests to the SubscribeView.

The ‘action’ POST argument is used to determine which context to render.

Notes

The action POST parameter determines what stage to progress view to. None directs to preview processing, confirm directs to confirmation processing, and process directs to payment and subscription processing.

process_payment(*args, **kwargs)

Processes payment and confirms if payment is accepted.

This method needs to be overriden in a project to handle payment processing with the appropriate payment provider.

Can return value that evalutes to True to indicate payment success and any value that evalutes to False to indicate payment error.

process_subscription(request, **kwargs)

Moves forward with payment & subscription processing.

If forms are invalid will move back to confirmation page for user to correct errors.

record_transaction(subscription, transaction_date=None)

Records transaction details in SubscriptionTransaction.

Parameters:
  • subscription (obj) – A UserSubscription object.
  • transaction_date (obj) – A DateTime object of when payment occurred (defaults to current datetime if none provided).
Returns:

The created SubscriptionTransaction instance.

Return type:

obj

render_confirmation(request, **kwargs)

Renders a confirmation page before processing payment.

If forms are invalid will return to preview view for user to correct errors.

render_preview(request, **kwargs)

Renders preview of subscription and collect payment details.

retrieve_transaction_date(payment)

Returns the transaction date from provided payment details.

Method should be overriden to accomodate the implemented payment processing if a more accurate datetime is required.

Returns
obj: The current datetime.
setup_subscription(request_user, plan_cost)

Adds subscription to user and adds them to required group.

Parameters:
  • request_user (obj) – A Django user instance.
  • plan_cost (obj) – A PlanCost instance.
Returns:

The newly created UserSubscription instance.

Return type:

obj

subscription_plan = None
success_url = 'dfs_subscribe_thank_you'
template_confirmation = 'subscriptions/subscribe_confirmation.html'
template_preview = 'subscriptions/subscribe_preview.html'
class subscriptions.views.SubscriptionCreateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.CreateView

View to create a new user subscription.

context_object_name = 'subscription'
fields = ['user', 'subscription', 'date_billing_start', 'date_billing_end']
model

alias of subscriptions.models.UserSubscription

permission_required = 'subscriptions.subscriptions'
raise_exception = True
success_message = 'User subscription successfully added'
success_url = '/dfs/subscriptions/'
template_name = 'subscriptions/subscription_create.html'
class subscriptions.views.SubscriptionDeleteView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.DeleteView

View to delete a user subscription.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful creation.

Type:str
success_url

URL to redirect to on successful creation.

Type:str
context_object_name = 'subscription'
delete(request, *args, **kwargs)

Override delete to allow success message to be added.

model

alias of subscriptions.models.UserSubscription

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'subscription_id'
raise_exception = True
success_message = 'User subscription successfully deleted'
success_url = '/dfs/subscriptions/'
template_name = 'subscriptions/subscription_delete.html'
class subscriptions.views.SubscriptionListView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.ListView

List of all subscriptions for the users

context_object_name = 'users'
model

alias of django.contrib.auth.models.User

paginate_by = 100
permission_required = 'subscriptions.subscriptions'
queryset
raise_exception = True
template_name = 'subscriptions/subscription_list.html'
class subscriptions.views.SubscriptionUpdateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.UpdateView

View to update the details of a user subscription.

context_object_name = 'subscription'
fields = ['subscription', 'date_billing_start', 'date_billing_end', 'date_billing_last', 'date_billing_next', 'active', 'cancelled']
model

alias of subscriptions.models.UserSubscription

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'subscription_id'
raise_exception = True
success_message = 'User subscription successfully updated'
success_url = '/dfs/subscriptions/'
template_name = 'subscriptions/subscription_update.html'
class subscriptions.views.TagCreateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.CreateView

View to create a new tag.

context_object_name = 'tag'
fields = ['tag']
model

alias of subscriptions.models.PlanTag

permission_required = 'subscriptions.subscriptions'
raise_exception = True
success_message = 'Tag successfully added'
success_url = '/dfs/tags/'
template_name = 'subscriptions/tag_create.html'
class subscriptions.views.TagDeleteView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.DeleteView

View to delete a tag.

View is extended to handle additional attributes noted below.

success_message

Message to display on successful deletion.

Type:str
success_url

URL to redirect to on successful deletion.

Type:str
context_object_name = 'tag'
delete(request, *args, **kwargs)

Override delete to allow success message to be added.

model

alias of subscriptions.models.PlanTag

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'tag_id'
raise_exception = True
success_message = 'Tag successfully deleted'
success_url = '/dfs/tags/'
template_name = 'subscriptions/tag_delete.html'
class subscriptions.views.TagListView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.ListView

List of all tags.

context_object_name = 'tags'
model

alias of subscriptions.models.PlanTag

permission_required = 'subscriptions.subscriptions'
raise_exception = True
template_name = 'subscriptions/tag_list.html'
class subscriptions.views.TagUpdateView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.contrib.messages.views.SuccessMessageMixin, subscriptions.abstract.UpdateView

View to update the details of a tag.

context_object_name = 'tag'
fields = ['tag']
model

alias of subscriptions.models.PlanTag

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'tag_id'
raise_exception = True
success_message = 'Tag successfully updated'
success_url = '/dfs/tags/'
template_name = 'subscriptions/tag_update.html'
class subscriptions.views.TransactionDetailView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.DetailView

Shows details of a specific subscription payment transaction.

context_object_name = 'transaction'
model

alias of subscriptions.models.SubscriptionTransaction

permission_required = 'subscriptions.subscriptions'
pk_url_kwarg = 'transaction_id'
raise_exception = True
template_name = 'subscriptions/transaction_detail.html'
class subscriptions.views.TransactionListView(**kwargs)

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, subscriptions.abstract.ListView

List of all subscription payment transactions.

context_object_name = 'transactions'
model

alias of subscriptions.models.SubscriptionTransaction

paginate_by = 50
permission_required = 'subscriptions.subscriptions'
raise_exception = True
template_name = 'subscriptions/transaction_list.html'