Documentation for the Code

Plan Models

The Plan Model is a concrete, swappable subclass of the abstract BasePlan.

  • BasePlan
  • Plan
class flexible_plans.models.plans.BasePlan(*args, **kwargs)[source]

BasePlan is TimeStamped, which means it holds a reference to dates of creation and modification. BasePlan is SoftDeletable, which means it becomes deactivated and not removed entirely (to keep a reference to subscribed plans which become soft-deleted and thus no more available).

BasePlan also can be visible and available. Plan is displayed on the list of currently available plans for user if it is visible. User cannot change plan to a plan that is not visible. Available means that user can buy a plan. If plan is not visible but still available it means that user which is using this plan already will be able to extend this plan again. If plan is not visible and not available, he will be forced then to change plan next time he extends an account.

BasePlan is defined by its Features, which can be quotas, permissions on objects and features

static get_default_plan(cls)[source]

Shortcut to retrieve the default plan to be assigned if no plan is selected :param cls: :return: default Plan instance

get_features_dict()[source]

Retrieve a Dict of all the plan’s feature to pass through validators :return: {feat.codename: feat.value}

static get_provider_choices()[source]

Scans settings to look for configured payment providers and serve them as choice list :return: [PaymentProvider]

class flexible_plans.models.plans.Plan(*args, **kwargs)[source]

Single plan defined in the system. A plan can be customized (for specific users), which means that only those users can purchase this plan and have it selected.

exception DoesNotExist
exception MultipleObjectsReturned
class flexible_plans.models.plans.PlanFeature(id, plan, feature)[source]
exception DoesNotExist
exception MultipleObjectsReturned

Feature Models

There are a few Feature concrete, swappable subsclasses of the abstract BaseFeature to represent different types of features with different logic:

  • BaseFeature
  • Feature
  • MeteredFeature
  • CumulativeFeature
  • PermissionFeature
class flexible_plans.models.features.BaseFeature(*args, **kwargs)[source]

BaseFeature Abstract Model defines the feature behaviour

get_validator()[source]

Get the proper validator from the ValidatorPolicy registry :return: Validator object that matches with the feature codename or None

log_usage()[source]

Logs the feature usage, against the correct validator

class flexible_plans.models.features.CumulativeFeature(id, name, codename, description, feature_ptr, usage)[source]
exception DoesNotExist
exception MultipleObjectsReturned
class flexible_plans.models.features.Feature(*args, **kwargs)[source]

Feature default implementation Feature is a swappable model to allow client to use their own Feature model. It is recommended to subclass BaseFeature to inherit all the behaviours and base fields. Being Feature a base class of other specific Feature Classes, it support an InheritanceManager to return all kinds of objects on Feature querysets

exception DoesNotExist
exception MultipleObjectsReturned
class flexible_plans.models.features.MeteredFeature(id, name, codename, description, feature_ptr, units, usage)[source]
exception DoesNotExist
exception MultipleObjectsReturned

Views

All the CRUD views are defined and available. Plus, specific views for the Plan management are available