<commit_before>from django.db import models

from django.utils import timezone
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError

# Create your models here.

class PostType(models.Model):
    # President, Vice-President, Respo Com etc
    description = models.CharField(max_length = 50, blank=False)

    def __unicode__(self):
        return self.description

# group de type assos/club/listeBDE/listePipo etc
class GroupCategory(models.Model):
    name = models.CharField(max_length = 50, unique = True)

    def __unicode__(self):
        return self.name


class Group(models.Model):
    name = models.CharField(max_length = 50, unique = True, blank = False)
    category = models.ForeignKey(GroupCategory, null=False)

    createdOn = models.DateTimeField(null = False, blank = False)
    deletedOn = models.DateTimeField(null = True, blank = True)

    logo = models.ImageField(upload_to = 'groups/logo')
    newsfeed = models.URLField(blank = True)

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.createdOn = timezone.now()
        super(Group, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.name

class Bureau(models.Model):
    # debut de mandat
    createdDate = models.DateTimeField(null = False)
    # fin du mandat null si mandat en cours
    endDate = models.DateTimeField(null = True, blank=True)

    group = models.ForeignKey(Group, blank=False, related_name='bureaus')

    def currentBureauExist(self):
        if self.endDate == None:
            return Bureau.objects.filter(group=self.group, endDate=None).count() > 0
        return False

    def is_current(self):
        return self.endDate is not None

    def clean(self):
        if self.currentBureauExist():
            raise ValidationError('Another current Bureau exists already, update its endDate before setting a new Bureau')

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.createdDate = timezone.now()
        super(Bureau, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.group.name

    class Meta:
        ordering = ('group__category', 'group__name', '-createdDate')

class Post(models.Model):
    utilisateur = models.ForeignKey(get_user_model(), related_name='post')

    bureau = models.ForeignKey(Bureau)

    description = models.TextField(blank=True)

    postType = models.ForeignKey(PostType, null=False)

    class Meta:
        unique_together = ('bureau', 'postType',)

class Message(models.Model):
    poster = models.ForeignKey(
        get_user_model(),
        related_name='message',
    )

    pubDate = models.DateTimeField(null = False)
    title = models.TextField(max_length=140, blank=False)
    content = models.TextField(blank=False)

    IMPORTANCE_LEVEL = (
        (0, 'Normal'),
        (1, 'Priority'),
    )

    group = models.ForeignKey(Group)

    importance = models.IntegerField(choices = IMPORTANCE_LEVEL,
                                     blank = False,
                                     default = 0)

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.pubDate = timezone.now()
        super(Message, self).save(*args, **kwargs)
<commit_msg>newsfeed title -> charfield<commit_after>from django.db import models

from django.utils import timezone
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError

# Create your models here.

class PostType(models.Model):
    # President, Vice-President, Respo Com etc
    description = models.CharField(max_length = 50, blank=False)

    def __unicode__(self):
        return self.description

# group de type assos/club/listeBDE/listePipo etc
class GroupCategory(models.Model):
    name = models.CharField(max_length = 50, unique = True)

    def __unicode__(self):
        return self.name


class Group(models.Model):
    name = models.CharField(max_length = 50, unique = True, blank = False)
    category = models.ForeignKey(GroupCategory, null=False)

    createdOn = models.DateTimeField(null = False, blank = False)
    deletedOn = models.DateTimeField(null = True, blank = True)

    logo = models.ImageField(upload_to = 'groups/logo')
    newsfeed = models.URLField(blank = True)

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.createdOn = timezone.now()
        super(Group, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.name

class Bureau(models.Model):
    # debut de mandat
    createdDate = models.DateTimeField(null = False)
    # fin du mandat null si mandat en cours
    endDate = models.DateTimeField(null = True, blank=True)

    group = models.ForeignKey(Group, blank=False, related_name='bureaus')

    def currentBureauExist(self):
        if self.endDate == None:
            return Bureau.objects.filter(group=self.group, endDate=None).count() > 0
        return False

    def is_current(self):
        return self.endDate is not None

    def clean(self):
        if self.currentBureauExist():
            raise ValidationError('Another current Bureau exists already, update its endDate before setting a new Bureau')

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.createdDate = timezone.now()
        super(Bureau, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.group.name

    class Meta:
        ordering = ('group__category', 'group__name', '-createdDate')

class Post(models.Model):
    utilisateur = models.ForeignKey(get_user_model(), related_name='post')

    bureau = models.ForeignKey(Bureau)

    description = models.TextField(blank=True)

    postType = models.ForeignKey(PostType, null=False)

    class Meta:
        unique_together = ('bureau', 'postType',)

class Message(models.Model):
    poster = models.ForeignKey(
        get_user_model(),
        related_name='message',
    )

    pubDate = models.DateTimeField(null = False)
    title = models.CharField(max_length=140, blank=False)
    content = models.TextField(blank=False)

    IMPORTANCE_LEVEL = (
        (0, 'Normal'),
        (1, 'Priority'),
    )

    group = models.ForeignKey(Group)

    importance = models.IntegerField(choices = IMPORTANCE_LEVEL,
                                     blank = False,
                                     default = 0)

    def save(self, *args, **kwargs):
        if self.pk is None:
            self.pubDate = timezone.now()
        super(Message, self).save(*args, **kwargs)

{'fraction_non_alphanumeric': 0.10803408399269629, 'fraction_numerical': 0.003956177723676202, 'mean_word_length': 2.9148302561048243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4071461', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1876, 'n_words': 476}