<commit_before>from django.db import models
import logging

from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType


logger = logging.getLogger(__file__)


class URLChangeMethod(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_id = models.TextField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

    method_name = models.TextField()
    current_url = models.TextField(blank=True)
    old_urls = models.ManyToManyField(
        'OldURL',
        related_name='model_method'
    )

    def __unicode__(self):
        return u'{}.{}, with current url {}'.format(
            self.content_object,
            self.method_name,
            self.current_url
        )


class OldURL(models.Model):
    url = models.TextField(unique=True)

    def __unicode__(self):
        return u'{}'.format(self.url)

    def get_new_url(self):
        all_new_urls = self.model_method.order_by('-current_url').values_list('current_url', flat=True)
        new_url = all_new_urls[0]
        if len(all_new_urls) > 1:
            logger.warning(
                ('the url {} has multiple new_urls associated with it'
                 '{} was chosen out of {}').format(
                     self,
                     new_url,
                     all_new_urls
                 )
            )
        return new_url
<commit_msg>Fixed formatting for 2.6<commit_after>from django.db import models
import logging

from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType


logger = logging.getLogger(__file__)


class URLChangeMethod(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_id = models.TextField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

    method_name = models.TextField()
    current_url = models.TextField(blank=True)
    old_urls = models.ManyToManyField(
        'OldURL',
        related_name='model_method'
    )

    def __unicode__(self):
        return u'{0}.{1}, with current url {2}'.format(
            self.content_object,
            self.method_name,
            self.current_url
        )


class OldURL(models.Model):
    url = models.TextField(unique=True)

    def __unicode__(self):
        return u'{}'.format(self.url)

    def get_new_url(self):
        all_new_urls = self.model_method.order_by('-current_url').values_list('current_url', flat=True)
        new_url = all_new_urls[0]
        if len(all_new_urls) > 1:
            logger.warning(
                ('the url {0} has multiple new_urls associated with it'
                 '{1} was chosen out of {2}').format(
                     self,
                     new_url,
                     all_new_urls
                 )
            )
        return new_url

{'fraction_non_alphanumeric': 0.09772329246935202, 'fraction_numerical': 0.004203152364273205, 'mean_word_length': 2.3247962747380675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5592610', 'n_tokens_mistral': 832, 'n_tokens_neox': 814, 'n_words': 167}