<commit_before># encoding: utf-8
from __future__ import unicode_literals
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch.dispatcher import receiver
from django.db import IntegrityError
from copy import copy


class Faculty(models.Model):
    name = models.CharField(max_length=100, primary_key=True)

    class Meta:
        verbose_name_plural = 'Faculties'  # admin will show correct plural

    def __unicode__(self):
        return self.name


class Degree(models.Model):
    faculty = models.ForeignKey(Faculty)
    name = models.CharField(max_length=100)

    def __unicode__(self):
        rep = [
            "<Degree object>",
            "faculty: {0}".format(repr(self.faculty)),
            "name: {0}".format(repr(self.name)),
        ]
        return '\n'.join(rep)


class Subject(models.Model):
    faculty = models.ForeignKey(Faculty)
    name = models.CharField(max_length=100)

    class Meta:
        unique_together = ("faculty", "name")
        ordering = ("name", "faculty")

    def __unicode__(self):
        return "{0} a {1}".format(self.name, self.faculty)


class SubjectDuplicate(models.Model):
    """Stores subjects that appear multiple times on the degree subject list
    under similar names.
    """
    faculty = models.ForeignKey(Faculty)
    name = models.CharField(max_length=100)

    class Meta:
        unique_together = ("faculty", "name")
        ordering = ("name", "faculty")

    def __unicode__(self):
        return "{0} a {1}".format(self.name, self.faculty)


@receiver(post_delete, sender=Subject)
def _subject_delete(sender, instance, **kwargs):
    try:
        fields = {
            'faculty': copy(instance.faculty),
            'name': copy(instance.name),
        }
        print fields
        duplicate = SubjectDuplicate(**fields)
        duplicate.save()
    except IntegrityError, e:
        print e


class SubjectAlias(models.Model):
    '''Links a subject alias to its 'official' name.
    Parsed data is not always accurate with subject names, so to solve
    inconsistencies, this model will link those mispellings with the actual
    subject.
    '''
    name = models.CharField(max_length=100)
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE)

    class Meta:
        verbose_name_plural = 'Subject aliases'
        unique_together = ("name", "subject")
        ordering = ("subject", "name")


class Year(models.Model):
    year = models.CharField(max_length=100, primary_key=True)

    def __unicode__(self):
        return self.year


GROUP_CHOICES = (
    ("GRUP 1", "GRUP 1"),
    ("GRUP 2", "GRUP 2"),
)


class Class(models.Model):
    subject = models.ForeignKey(Subject, null=True, blank=True)
    group = models.CharField(max_length=50, choices=GROUP_CHOICES, blank=True)
    subgroup = models.CharField(max_length=50, blank=True)
    kind = models.CharField(max_length=50, blank=True)
    room = models.CharField(max_length=50, blank=True)
    date_start = models.DateTimeField('class start', null=True, blank=True)
    date_end = models.DateTimeField('class end', null=True, blank=True)
    year = models.ForeignKey(Year)
    raw_entry = models.TextField()

    class Meta:
        verbose_name_plural = 'Classes'

    def __unicode__(self):
        rep = [
            "<Class object>"
            "subject: " + repr(self.subject),
            "kind: " + repr(self.kind),
            "group: " + repr(self.group),
            "room: " + repr(self.room),
            "date_start: " + repr(self.date_start),
            "date_end: " + repr(self.date_end),
        ]
        return '\n'.join(rep)


class DegreeSubject(models.Model):
    TERM_CHOICES = (
        ('1r Trimestre', '1r Trimestre'),
        ('2n Trimestre', '2n Trimestre'),
        ('3r Trimestre', '3r Trimestre'),
    )
    subject = models.ForeignKey(Subject)
    degree = models.ForeignKey(Degree)
    year = models.ForeignKey(Year)
    term = models.CharField(max_length=50, choices=TERM_CHOICES)
    group = models.CharField(max_length=50, choices=GROUP_CHOICES)


class Calendar(models.Model):
    calendar = models.FileField(upload_to='.')
    degree_subject = models.ManyToManyField(DegreeSubject)<commit_msg>More changes on the model.<commit_after># encoding: utf-8
from __future__ import unicode_literals
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch.dispatcher import receiver
from django.db import IntegrityError
from copy import copy


class Faculty(models.Model):
    name = models.CharField(max_length=100, primary_key=True)

    class Meta:
        verbose_name_plural = 'Faculties'  # admin will show correct plural

    def __unicode__(self):
        return self.name


class Degree(models.Model):
    faculty = models.ForeignKey(Faculty)
    name = models.CharField(max_length=100)

    def __unicode__(self):
        rep = [
            "<Degree object>",
            "faculty: {0}".format(repr(self.faculty)),
            "name: {0}".format(repr(self.name)),
        ]
        return '\n'.join(rep)


class Subject(models.Model):
    faculty = models.ForeignKey(Faculty)
    name = models.CharField(max_length=100)

    class Meta:
        unique_together = ("faculty", "name")
        ordering = ("name", "faculty")

    def __unicode__(self):
        return "{0} a {1}".format(self.name, self.faculty)


class SubjectDuplicate(models.Model):
    """Stores subjects that appear multiple times on the degree subject list
    under similar names.
    """
    faculty = models.ForeignKey(Faculty)
    name = models.CharField(max_length=100)

    class Meta:
        unique_together = ("faculty", "name")
        ordering = ("name", "faculty")

    def __unicode__(self):
        return "{0} a {1}".format(self.name, self.faculty)


@receiver(post_delete, sender=Subject)
def _subject_delete(sender, instance, **kwargs):
    try:
        fields = {
            'faculty': copy(instance.faculty),
            'name': copy(instance.name),
        }
        print fields
        duplicate = SubjectDuplicate(**fields)
        duplicate.save()
    except IntegrityError, e:
        print e


class SubjectAlias(models.Model):
    '''Links a subject alias to its 'official' name.
    Parsed data is not always accurate with subject names, so to solve
    inconsistencies, this model will link those mispellings with the actual
    subject.
    '''
    name = models.CharField(max_length=100)
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE)

    class Meta:
        verbose_name_plural = 'Subject aliases'
        unique_together = ("name", "subject")
        ordering = ("subject", "name")


class AcademicYear(models.Model):
    year = models.CharField(max_length=100, primary_key=True)

    def __unicode__(self):
        return self.year


GROUP_CHOICES = (
    ("GRUP 1", "GRUP 1"),
    ("GRUP 2", "GRUP 2"),
)


class Class(models.Model):
    subject = models.ForeignKey(Subject, null=True, blank=True)
    group = models.CharField(max_length=50, choices=GROUP_CHOICES, blank=True)
    subgroup = models.CharField(max_length=50, blank=True)
    kind = models.CharField(max_length=50, blank=True)
    room = models.CharField(max_length=50, blank=True)
    date_start = models.DateTimeField('class start', null=True, blank=True)
    date_end = models.DateTimeField('class end', null=True, blank=True)
    academic_year = models.ForeignKey(AcademicYear)
    raw_entry = models.TextField()

    class Meta:
        verbose_name_plural = 'Classes'

    def __unicode__(self):
        rep = [
            "<Class object>"
            "subject: " + repr(self.subject),
            "kind: " + repr(self.kind),
            "group: " + repr(self.group),
            "room: " + repr(self.room),
            "date_start: " + repr(self.date_start),
            "date_end: " + repr(self.date_end),
        ]
        return '\n'.join(rep)


class DegreeSubject(models.Model):
    TERM_CHOICES = (
        ('1r Trimestre', '1r Trimestre'),
        ('2n Trimestre', '2n Trimestre'),
        ('3r Trimestre', '3r Trimestre'),
    )
    YEAR_CHOICES = (
        ("1r", "1r"),
        ("2n", "2n"),
        ("3r", "3r"),
        ("4t", "4t"),
        ("optatives", "optatives"),
    )
    subject = models.ForeignKey(Subject)
    degree = models.ForeignKey(Degree)
    academic_year = models.ForeignKey(AcademicYear)
    year = models.CharField(max_length=50, choices=YEAR_CHOICES)
    term = models.CharField(max_length=50, choices=TERM_CHOICES)
    group = models.CharField(max_length=50, choices=GROUP_CHOICES)


class Calendar(models.Model):
    calendar = models.FileField(upload_to='.')
    degree_subject = models.ManyToManyField(DegreeSubject)
{'fraction_non_alphanumeric': 0.12418450268971043, 'fraction_numerical': 0.011903399336156575, 'mean_word_length': 3.0509967547519703, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6469624', 'n_tokens_mistral': 2839, 'n_tokens_neox': 2689, 'n_words': 609}