<commit_before>import datetime

from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import F, Q, Sum
from django.utils import timezone
from django.utils.text import slugify
from django.contrib.auth.models import User


class Country(models.Model):
    code = models.CharField(max_length=3, primary_key=True)
    name = models.CharField(max_length=255, unique=True)

    class Meta:
        verbose_name_plural = 'countries'

    def __unicode__(self):
        return u'%s (%s)' % (self.name, self.code)


class Season(models.Model):
    year_from = models.PositiveSmallIntegerField(db_index=True)
    year_to = models.PositiveSmallIntegerField()

    class Meta:
        unique_together = ('year_from', 'year_to')

    @property
    def name(self):
        return '%s/%s' % (self.year_from, str(self.year_to)[-2:])

    def __unicode__(self):
        return u'%s' % (self.name)

    @staticmethod
    def curr_year():
        today = datetime.datetime.today()
        middle = datetime.datetime(today.year, 7, 1)
        if today < middle:
            return today.year - 1
        return today.year


class Club(models.Model):
    name = models.CharField(max_length=100)
    short_name = models.CharField(
        max_length=15, blank=True,
        help_text="For use as common name, ex. Vardar, Hypo, FCM...")
    initials = models.CharField(
        max_length=3, blank=True,
        help_text="For use in matches, ex. GYO, VAR, BUD...")
    country = models.CharField(max_length=3)
    ehf_id = models.IntegerField('EHF id', unique=True)
    address = models.CharField(
        max_length=200, blank=True,
        help_text="Separate address items with commas.")
    website = models.URLField(blank=True)
    twitter = models.URLField(blank=True)
    facebook = models.URLField(blank=True)
    logo = models.ImageField(upload_to='clubs', blank=True, null=True)
    players = models.ManyToManyField(
        'Player', through='PlayerContract', blank=True)
    coaches = models.ManyToManyField(
        'Coach', through='CoachContract', blank=True)
    fans = models.ManyToManyField(User, related_name='fav_clubs')

    def __unicode__(self):
        return u'%s' % (self.name)

    def get_absolute_url(self):
        return reverse('data:club_detail',
                       kwargs={'pk': self.pk, 'slug': slugify(self.name)})

    def get_current_team(self):
        today = datetime.datetime.today()
        middle = datetime.datetime(today.year, 7, 1)
        season_year = today.year
        if today < middle:
            season_year -= 1
        return self.playercontract_set.select_related(
            'player', 'season').filter(
            season__year_from=season_year, departure_month=None)

    def get_current_coaches(self):
        today = datetime.datetime.today()
        middle = datetime.datetime(today.year, 7, 1)
        season_year = today.year
        if today < middle:
            season_year -= 1
        return self.coachcontract_set.filter(
            season__year_from=season_year, departure_month=None)

    def get_matches(self):
        query = Q(home_team=self) | Q(away_team=self)
        return Match.objects.filter(query).order_by('-match_datetime')

    def address_lines(self):
        if self.address:
            return self.address.split(',')
        return []

    def has_logo(self):
        if self.logo:
            return True
        return False
    has_logo.boolean = True
    has_logo.short_description = 'Has logo?'

    def admin_thumbnail(self):
        if self.logo:
            return u'<img src="%s" />' % (self.logo.url)
        else:<commit_msg>Use select_related() in club matches.<commit_after>import datetime

from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import F, Q, Sum
from django.utils import timezone
from django.utils.text import slugify
from django.contrib.auth.models import User


class Country(models.Model):
    code = models.CharField(max_length=3, primary_key=True)
    name = models.CharField(max_length=255, unique=True)

    class Meta:
        verbose_name_plural = 'countries'

    def __unicode__(self):
        return u'%s (%s)' % (self.name, self.code)


class Season(models.Model):
    year_from = models.PositiveSmallIntegerField(db_index=True)
    year_to = models.PositiveSmallIntegerField()

    class Meta:
        unique_together = ('year_from', 'year_to')

    @property
    def name(self):
        return '%s/%s' % (self.year_from, str(self.year_to)[-2:])

    def __unicode__(self):
        return u'%s' % (self.name)

    @staticmethod
    def curr_year():
        today = datetime.datetime.today()
        middle = datetime.datetime(today.year, 7, 1)
        if today < middle:
            return today.year - 1
        return today.year


class Club(models.Model):
    name = models.CharField(max_length=100)
    short_name = models.CharField(
        max_length=15, blank=True,
        help_text="For use as common name, ex. Vardar, Hypo, FCM...")
    initials = models.CharField(
        max_length=3, blank=True,
        help_text="For use in matches, ex. GYO, VAR, BUD...")
    country = models.CharField(max_length=3)
    ehf_id = models.IntegerField('EHF id', unique=True)
    address = models.CharField(
        max_length=200, blank=True,
        help_text="Separate address items with commas.")
    website = models.URLField(blank=True)
    twitter = models.URLField(blank=True)
    facebook = models.URLField(blank=True)
    logo = models.ImageField(upload_to='clubs', blank=True, null=True)
    players = models.ManyToManyField(
        'Player', through='PlayerContract', blank=True)
    coaches = models.ManyToManyField(
        'Coach', through='CoachContract', blank=True)
    fans = models.ManyToManyField(User, related_name='fav_clubs')

    def __unicode__(self):
        return u'%s' % (self.name)

    def get_absolute_url(self):
        return reverse('data:club_detail',
                       kwargs={'pk': self.pk, 'slug': slugify(self.name)})

    def get_current_team(self):
        today = datetime.datetime.today()
        middle = datetime.datetime(today.year, 7, 1)
        season_year = today.year
        if today < middle:
            season_year -= 1
        return self.playercontract_set.select_related(
            'player', 'season').filter(
            season__year_from=season_year, departure_month=None)

    def get_current_coaches(self):
        today = datetime.datetime.today()
        middle = datetime.datetime(today.year, 7, 1)
        season_year = today.year
        if today < middle:
            season_year -= 1
        return self.coachcontract_set.filter(
            season__year_from=season_year, departure_month=None)

    def get_matches(self):
        query = Q(home_team=self) | Q(away_team=self)
        return Match.objects.filter(query).select_related(
            ).order_by('-match_datetime')

    def address_lines(self):
        if self.address:
            return self.address.split(',')
        return []

    def has_logo(self):
        if self.logo:
            return True
        return False
    has_logo.boolean = True
    has_logo.short_description = 'Has logo?'

    def admin_thumbnail(self):
        if self.logo:
            return u'<img src="%s" />' % (self.logo.url)
        else:
{'fraction_non_alphanumeric': 0.11467391304347826, 'fraction_numerical': 0.006521739130434782, 'mean_word_length': 2.786522633744856, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2075401', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2230, 'n_words': 490}