<commit_before>from django.views.generic import TemplateView, FormView
from django.core.urlresolvers import reverse
from django.http import Http404

import billing.loading
import billing.processor
from billing.forms import SubscriptionConfirmationForm
from billing.models import Subscription, ProductType


class BillingOverviewView(TemplateView):
    """
    presents a list/descriptions of the different products on offer
    
    Should display links to the various product pages so users can upgrade
    or downgrade their current subscription.
    """
    template_name = 'billing/overview.html'
    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(BillingOverviewView, self).get_context_data(**kwargs)
        # Add in a list of all the products
        context['all_products'] = billing.loading.get_products(hidden=True)
        context['public_products'] = billing.loading.get_products()
        billing_account = self.request.user.billing_account
        context['billing_account'] = billing_account
        context['products'] = billing_account.get_visible_products()
        current_product = billing_account.get_current_product_class()
        context['current_product'] = current_product
        return context

class BaseBillingDetailsView(FormView):
    def get_success_url(self):
        return self.request.path
    def form_valid(self, form):
        ba = self.request.user.billing_account

        # let billing processor save details
        form.billing_account = ba
        form.save()

        # do redirect (or do more processing by ignoring return value)
        return super(BaseBillingDetailsView, self).form_valid(form)

class BaseSubscriptionView(BaseBillingDetailsView):
    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(BaseSubscriptionView, self).get_context_data(**kwargs)
        product = billing.loading.get_product(self.kwargs['product'])
        context['product'] = product
        return context
    def form_valid(self, form):
        super(BaseSubscriptionView, self).form_valid(form)

        ba = self.request.user.billing_account

        # create subscription
        ba.subscribe_to_product(self.kwargs['product'])

        # let FormView do redirect
        return FormView.form_valid(self, form)<commit_msg>use BaseBillingDetails view redirect in BaseSubScriptionView<commit_after>from django.views.generic import TemplateView, FormView
from django.core.urlresolvers import reverse
from django.http import Http404

import billing.loading
import billing.processor
from billing.forms import SubscriptionConfirmationForm
from billing.models import Subscription, ProductType


class BillingOverviewView(TemplateView):
    """
    presents a list/descriptions of the different products on offer
    
    Should display links to the various product pages so users can upgrade
    or downgrade their current subscription.
    """
    template_name = 'billing/overview.html'
    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(BillingOverviewView, self).get_context_data(**kwargs)
        # Add in a list of all the products
        context['all_products'] = billing.loading.get_products(hidden=True)
        context['public_products'] = billing.loading.get_products()
        billing_account = self.request.user.billing_account
        context['billing_account'] = billing_account
        context['products'] = billing_account.get_visible_products()
        current_product = billing_account.get_current_product_class()
        context['current_product'] = current_product
        return context

class BaseBillingDetailsView(FormView):
    def get_success_url(self):
        return self.request.path
    def form_valid(self, form):
        ba = self.request.user.billing_account

        # let billing processor save details
        form.billing_account = ba
        form.save()

        # do redirect (or do more processing by ignoring return value)
        return super(BaseBillingDetailsView, self).form_valid(form)

class BaseSubscriptionView(BaseBillingDetailsView):
    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(BaseSubscriptionView, self).get_context_data(**kwargs)
        product = billing.loading.get_product(self.kwargs['product'])
        context['product'] = product
        return context
    def form_valid(self, form):
        response = super(BaseSubscriptionView, self).form_valid(form)

        ba = self.request.user.billing_account

        # create subscription
        ba.subscribe_to_product(self.kwargs['product'])

        # return the redirect
        return response
{'fraction_non_alphanumeric': 0.0757013201320132, 'fraction_numerical': 0.0012376237623762376, 'mean_word_length': 3.6137012369172217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3987913', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1223, 'n_words': 337}