<commit_before>from django.db import models

from django.db.models.signals import post_save
from django.dispatch import receiver

from base import util
from base.models import MediaRemovalMixin


class Leaflet(MediaRemovalMixin, models.Model):
    '''
    Represents a given (generated) leaflet.
    '''

    def get_leaflet_path(self, *args):
        return "leaflets/{name}.pdf".format(name=unicode(self))

    def get_thumbnail_path(self):
        return "leaflets/thumbnails/{name}.jpg".format(name=unicode(self))

    def get_media_files(self):
        return [self.get_leaflet_path(), self.get_thumbnail_path()]

    def __unicode__(self):
        return "{competition}-{year}-{issue}"\
               .format(competition=self.competition,
                       year=self.year,
                       issue=self.issue)

    competition = models.ForeignKey('competitions.Competition')
    year = models.IntegerField()
    issue = models.IntegerField()
    leaflet = models.FileField(upload_to=get_leaflet_path)

    # Fields added via foreign keys:

    #  problemset_set

    # TODO: more than one problemset can point to given leaflet, is that a
    #       problem?

    class Meta:
        ordering = ['competition', '-year', 'issue']<commit_msg>leaflets: Change leaflet path on updates<commit_after>from django.db import models

from django.db.models.signals import post_save
from django.dispatch import receiver

from base import util
from base.models import MediaRemovalMixin


class Leaflet(MediaRemovalMixin, models.Model):
    '''
    Represents a given (generated) leaflet.
    '''

    def get_leaflet_path(self, *args):
        return "leaflets/{name}.pdf".format(name=unicode(self))

    def get_thumbnail_path(self):
        return "leaflets/thumbnails/{name}.jpg".format(name=unicode(self))

    def get_media_files(self):
        return [self.get_leaflet_path(), self.get_thumbnail_path()]

    def __unicode__(self):
        return "{competition}-{year}-{issue}"\
               .format(competition=self.competition,
                       year=self.year,
                       issue=self.issue)

    competition = models.ForeignKey('competitions.Competition')
    year = models.IntegerField()
    issue = models.IntegerField()
    leaflet = models.FileField(upload_to=get_leaflet_path)

    def save(self, *args, **kwargs):
        if self.pk:
            self.leaflet = self.get_leaflet_path()
        return super(Leaflet, self).save(*args, **kwargs)

    # Fields added via foreign keys:

    #  problemset_set

    # TODO: more than one problemset can point to given leaflet, is that a
    #       problem?

    class Meta:
        ordering = ['competition', '-year', 'issue']
{'fraction_non_alphanumeric': 0.10864745011086474, 'fraction_numerical': 0.0, 'mean_word_length': 3.0282738095238093, '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': '6393016', 'n_tokens_mistral': 812, 'n_tokens_neox': 782, 'n_words': 182}