<commit_before>from django.db import models
from .managers import FastBillApiManager
from django.contrib.auth.models import User
import logging
from django.utils.translation import ugettext_lazy as _
from . import helper
from django.utils.functional import cached_property
from fastbill import FastbillError

logger = logging.getLogger(__name__)


class FastBillBase(models.Model):
    """

    """
    created_at = models.DateTimeField(auto_now=True)
    changed_at = models.DateTimeField(auto_now_add=True)

    objects = FastBillApiManager()

    class Meta:
        abstract = True

    def get_user(self, customer_ext_uid):
        """
        """
        if customer_ext_uid in [0, "0"]:
            return None

        else:
            try:
                return User.objects.get(pk=customer_ext_uid)
            except User.DoesNotExist:
                logger.warning("User with pk %s does not exist. Customer object without relation created" %
                               customer_ext_uid)
                return None

class Article(FastBillBase):
    """

    """
    subscription_cancellation = models.CharField(max_length=50)
    article_number = models.IntegerField(primary_key=True)
    description = models.TextField()
    tags = models.CharField(max_length=500)
    title = models.CharField(max_length=500)
    unit_price = models.FloatField()
    is_addon = models.BooleanField()
    subscription_trial = models.CharField(max_length=50)
    subscription_interval = models.CharField(max_length=50)
    checkout_url = models.URLField(max_length=300)
    setup_fee = models.FloatField()
    subscription_duration_follow = models.CharField(max_length=50)
    return_url_success = models.URLField(max_length=300)
    vat_percent = models.FloatField()
    allow_multiple = models.BooleanField()
    return_url_cancel = models.URLField(max_length=300)
    subscription_number_events = models.IntegerField()
    currency_code = models.CharField(max_length=3)
    subscription_duration = models.CharField(max_length=50)

    @cached_property
    def subscriptions(self):
        return Subscription.objects.filter(article_number=self.article_number)

    def __unicode__(self):
        return u"Article, Number: %s Title %s" % (self.article_number, self.title)


class Customer(FastBillBase):
    """
    Crippled Customer Model. We only save needed data
    """

    customer_number = models.IntegerField()
    customer_ext_uid = models.IntegerField(null=True)
    customer_id = models.IntegerField(primary_key=True)

    dashboard_url = models.URLField(max_length=500)
    changedata_url = models.URLField(max_length=500)

    user = models.OneToOneField(User, null=True, related_name="fastbill_customer")

    deleted = models.BooleanField(default=False)

    def save(self, *args, **kwargs):
        """
        """
        if self.user is None:
            self.user = self.get_user(self.customer_ext_uid)

        super(Customer, self).save(*args, **kwargs)

    @cached_property
    def subscriptions(self):
        return Subscription.objects.filter(customer_id=self.customer_id)<commit_msg>and they changed it again<commit_after>from django.db import models
from .managers import FastBillApiManager
from django.contrib.auth.models import User
import logging
from django.utils.translation import ugettext_lazy as _
from . import helper
from django.utils.functional import cached_property
from fastbill import FastbillError

logger = logging.getLogger(__name__)


class FastBillBase(models.Model):
    """

    """
    created_at = models.DateTimeField(auto_now=True)
    changed_at = models.DateTimeField(auto_now_add=True)

    objects = FastBillApiManager()

    class Meta:
        abstract = True

    def get_user(self, customer_ext_uid):
        """
        """
        if customer_ext_uid in [0, "0"]:
            return None

        else:
            try:
                return User.objects.get(pk=customer_ext_uid)
            except User.DoesNotExist:
                logger.warning("User with pk %s does not exist. Customer object without relation created" %
                               customer_ext_uid)
                return None

class Article(FastBillBase):
    """

    """
    subscription_cancellation = models.CharField(max_length=50)
    article_number = models.IntegerField(primary_key=True)
    description = models.TextField()
    tags = models.CharField(max_length=500)
    title = models.CharField(max_length=500)
    unit_price = models.FloatField()
    is_addon = models.BooleanField()
    subscription_trial = models.CharField(max_length=50)
    subscription_interval = models.CharField(max_length=50)
    checkout_url = models.URLField(max_length=300)
    setup_fee = models.FloatField()
    subscription_duration_follow = models.CharField(max_length=50)
    return_url_success = models.URLField(max_length=300)
    vat_percent = models.FloatField()
    allow_multiple = models.BooleanField()
    return_url_cancel = models.URLField(max_length=300)
    subscription_number_events = models.IntegerField()
    currency_code = models.CharField(max_length=3)
    subscription_duration = models.CharField(max_length=50)

    @cached_property
    def subscriptions(self):
        return Subscription.objects.filter(article_number=self.article_number)

    def __unicode__(self):
        return u"Article, Number: %s Title %s" % (self.article_number, self.title)


class Customer(FastBillBase):
    """
    Crippled Customer Model. We only save needed data
    """

    customer_number = models.IntegerField()
    customer_ext_uid = models.IntegerField(null=True)
    customer_id = models.IntegerField(primary_key=True)
    hash = models.CharField(max_length=64, null=True)
    dashboard_url = models.URLField(max_length=500)
    changedata_url = models.URLField(max_length=500)

    user = models.OneToOneField(User, null=True, related_name="fastbill_customer")

    deleted = models.BooleanField(default=False)

    def save(self, *args, **kwargs):
        """
        """
        if self.user is None:
            self.user = self.get_user(self.customer_ext_uid)

        super(Customer, self).save(*args, **kwargs)

    @cached_property
    def subscriptions(self):
        return Subscription.objects.filter(customer_id=self.customer_id)
{'fraction_non_alphanumeric': 0.09264261878277451, 'fraction_numerical': 0.011123470522803115, 'mean_word_length': 3.4669978708303764, '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': '5184364', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1812, 'n_words': 354}