<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from model_utils.managers import PassThroughManager


class ConnectedAccountManager(PassThroughManager):

    def get_queryset(self, *args, **kwargs):
        queryset = super(ConnectedAccountManager, self).get_queryset(*args,
                                                                     **kwargs)
        return queryset.filter(application__isnull=False)


class CustomerManager(PassThroughManager):

    def sync(self, account=None):
        # TODO: Pagination
        account = self._get_account()
        response = self.model._stripe.Customer.all(
            api_key=account.secret_key, include=['total_count'])
        for item in response['data']:
            self.get_or_create(stripe_id=item['id'], account=account,
                               defaults={'_api_data': item})


class PlanManager(PassThroughManager):

    def sync(self, account=None):
        # TODO: Pagination
        account = self._get_account()
        response = self.model._stripe.Plan.all(
            api_key=account.secret_key, include=['total_count'])
        for item in response['data']:
            self.get_or_create(stripe_id=item['id'], account=account,
                               defaults={'_api_data': item})


class StandardAccountManager(PassThroughManager):

    def get_queryset(self, *args, **kwargs):
        queryset = super(StandardAccountManager, self).get_queryset(*args,
                                                                    **kwargs)
        return queryset.filter(application__isnull=True)


class SubscriptionManager(PassThroughManager):

    def sync(self, customer=None):
        customer = customer or self._get_customer()
        # TODO: Pagination
        response = self.model._stripe.Customer.retrieve(
            api_key=customer.account.secret_key,
            id=customer.stripe_id).subscriptions.all(include=['total_count'])
        for item in response['data']:
            plan, created = customer.account.plans.get_or_create(
                stripe_id=item['plan']['id'])
            self.get_or_create(stripe_id=item['id'],
                               account=customer.account, customer=customer,
                               plan=plan, defaults={'_api_data': item})<commit_msg>Also store api data if creating a plan whilst syncing customer subscriptions.<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from model_utils.managers import PassThroughManager


class ConnectedAccountManager(PassThroughManager):

    def get_queryset(self, *args, **kwargs):
        queryset = super(ConnectedAccountManager, self).get_queryset(*args,
                                                                     **kwargs)
        return queryset.filter(application__isnull=False)


class CustomerManager(PassThroughManager):

    def sync(self, account=None):
        # TODO: Pagination
        account = self._get_account()
        response = self.model._stripe.Customer.all(
            api_key=account.secret_key, include=['total_count'])
        for item in response['data']:
            self.get_or_create(stripe_id=item['id'], account=account,
                               defaults={'_api_data': item})


class PlanManager(PassThroughManager):

    def sync(self, account=None):
        # TODO: Pagination
        account = self._get_account()
        response = self.model._stripe.Plan.all(
            api_key=account.secret_key, include=['total_count'])
        for item in response['data']:
            self.get_or_create(stripe_id=item['id'], account=account,
                               defaults={'_api_data': item})


class StandardAccountManager(PassThroughManager):

    def get_queryset(self, *args, **kwargs):
        queryset = super(StandardAccountManager, self).get_queryset(*args,
                                                                    **kwargs)
        return queryset.filter(application__isnull=True)


class SubscriptionManager(PassThroughManager):

    def sync(self, customer=None):
        customer = customer or self._get_customer()
        # TODO: Pagination
        response = self.model._stripe.Customer.retrieve(
            api_key=customer.account.secret_key,
            id=customer.stripe_id).subscriptions.all(include=['total_count'])
        for item in response['data']:
            plan, created = customer.account.plans.get_or_create(
                stripe_id=item['plan']['id'],
                defaults={'_api_data': item['plan']})
            self.get_or_create(stripe_id=item['id'],
                               account=customer.account, customer=customer,
                               plan=plan, defaults={'_api_data': item})
{'fraction_non_alphanumeric': 0.10581346716854872, 'fraction_numerical': 0.0004182350480970305, 'mean_word_length': 2.3659394792399717, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5970827', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1215, 'n_words': 226}