<commit_before>from django.db import models
from django.contrib.auth.models import User
from .choices import *
from datetime import datetime
from django.dispatch import receiver
from django.db.models.signals import post_save
from info.models import ClubTag


class Club(models.Model):
    club_name = models.CharField(max_length=100, null=True)
    club_parent = models.ForeignKey('self', null=True, blank=True)
    club_members = models.ManyToManyField(User, blank=True)

    def __str__(self):
        return self.club_name


class Post(models.Model):
    post_name = models.CharField(max_length=500, null=True)
    club = models.ForeignKey(Club, on_delete=models.CASCADE, null=True, blank=True)
    tag = models.ManyToManyField(ClubTag, related_name='tagname', symmetrical=False)
    parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)
    post_holders = models.ManyToManyField(User, blank=True)
    post_approvals = models.ManyToManyField('self', related_name='approvals', symmetrical=False, blank=True)

    status = models.CharField(max_length=50, choices=POST_STATUS, default='Post created')
    perms = models.CharField(max_length=200, choices=POST_PERMS, default='normal')

    def __str__(self):
        return self.post_name

    def remove_holders(self):
        for holder in self.post_holders.all():
            history = PostHistory.objects.get(post=self, user=holder)
            history.end = datetime.now()
            history.save()

        self.post_holders.clear()
        return self.post_holders


class PostHistory(models.Model):
    post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    start = models.DateField(auto_now_add=True)
    end = models.DateField(null=True, blank=True, editable=True)


class Nomination(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField(max_length=20000, null=True, blank=True)
    brief_desc = models.TextField(max_length=300, null=True, blank=True)
    nomi_post = models.ForeignKey(Post, null=True)
    nomi_form = models.OneToOneField('forms.Questionnaire', null=True, blank=True)

    status = models.CharField(max_length=50, choices=STATUS, default='Nomination created')
    result_approvals = models.ManyToManyField(Post, related_name='result_approvals', symmetrical=False, blank=True)
    nomi_approvals = models.ManyToManyField(Post, related_name='nomi_approvals', symmetrical=False, blank=True)
    club_search = models.ManyToManyField(Post, related_name='all_clubs', symmetrical=False, blank=True)
    group_status = models.CharField(max_length= 50, choices= GROUP_STATUS, default='normal')

    opening_date = models.DateField(null=True, blank=True)
    closing_date = models.DateField(null=True, blank=True, editable=True)

    year_choice = models.CharField(max_length=100, choices=YEAR_1, null=True)
    hall_choice = models.CharField(max_length=100, choices=HALL_1, null=True)
    dept_choice = models.CharField(max_length=100, choices=DEPT_1, null=True)

    def __str__(self):
        return self.name

    def append(self):
        selected = NominationInstance.objects.filter(nomination=self, status='Accepted')
        self.status = 'Work done'
        self.save()
        for each in selected:
            PostHistory.objects.create(post=self.nomi_post, user=each.user)
            self.nomi_post.post_holders.add(each.user)

        return self.nomi_post.post_holders

    def replace(self):
        for holder in self.nomi_post.post_holders.all():
            history = PostHistory.objects.get(post=self.nomi_post, user=holder)
            history.end = datetime.now()
            history.save()

        self.nomi_post.post_holders.clear()
        self.append()
        return self.nomi_post.post_holders

    def open_to_users(self):
        self.status = 'Nomination out'
        self.opening_date = datetime.now()
        self.save()
        return self.status


class NominationInstance(models.Model):
    nomination = models.ForeignKey('Nomination', on_delete=models.CASCADE, null=True)
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
    status = models.CharField(max_length=20, choices=NOMI_STATUS,  null=True, blank=True, default=None)
    interview_status = models.CharField(max_length=20, choices=INTERVIEW_STATUS,  null=True, blank=True,
                                        default='Interview Not Done')
    filled_form = models.OneToOneField('forms.FilledForm', null=True, blank=True)

    def __str__(self):
        return str(self.user) + ' ' + str(self.id)

class Commment(models.Model):
    comments = models.TextField(max_length=10000, null=True, blank=True)
    nomi_instance=models.ForeignKey(NominationInstance,on_delete = models.CASCADE, null = True)
    user = models.ForeignKey(User,on_delete = models.SET_NULL, null=True )

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    name = models.CharField(max_length=40, blank=True)
    roll_no = models.IntegerField(null=True)
    year = models.CharField(max_length=4, choices=YEAR, default='Y16')
    programme = models.CharField(max_length=7, choices=PROGRAMME, default='B.Tech')
    department = models.CharField(max_length=200, choices=DEPT, default='AE')
    hall = models.CharField(max_length=10, choices=HALL, default=1)
    room_no = models.CharField(max_length=10, null=True, blank=True)
    contact = models.CharField(max_length=10, null=True, blank=True)

    def __str__(self):
        return str(self.name)



class GroupNomination(models.Model):
    title = models.CharField(max_length=2000,null =True)
    description = models.CharField(max_length=5000, null = True, blank = True)
    nominations = models.ManyToManyField(Nomination, symmetrical= False, blank= True)
    status = models.CharField(max_length= 50,choices= G_STATUS,default= 'created')
    approvals = models.ManyToManyField(Post, related_name='group_approvals', symmetrical=False, blank=True)
    def __str__(self):
        return str(self.title)

@receiver(post_save, sender=Nomination)
def ensure_parent_in_approvals(sender, **kwargs):<commit_msg>Indentation changes<commit_after>from django.db import models
from django.contrib.auth.models import User
from .choices import *
from datetime import datetime
from django.dispatch import receiver
from django.db.models.signals import post_save
from info.models import ClubTag


class Club(models.Model):
    club_name = models.CharField(max_length=100, null=True)
    club_parent = models.ForeignKey('self', null=True, blank=True)
    club_members = models.ManyToManyField(User, blank=True)

    def __str__(self):
        return self.club_name


class Post(models.Model):
    post_name = models.CharField(max_length=500, null=True)
    club = models.ForeignKey(Club, on_delete=models.CASCADE, null=True, blank=True)
    tag = models.ManyToManyField(ClubTag, related_name='tagname', symmetrical=False)
    parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)
    post_holders = models.ManyToManyField(User, blank=True)
    post_approvals = models.ManyToManyField('self', related_name='approvals', symmetrical=False, blank=True)

    status = models.CharField(max_length=50, choices=POST_STATUS, default='Post created')
    perms = models.CharField(max_length=200, choices=POST_PERMS, default='normal')

    def __str__(self):
        return self.post_name

    def remove_holders(self):
        for holder in self.post_holders.all():
            history = PostHistory.objects.get(post=self, user=holder)
            history.end = datetime.now()
            history.save()

        self.post_holders.clear()
        return self.post_holders


class PostHistory(models.Model):
    post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    start = models.DateField(auto_now_add=True)
    end = models.DateField(null=True, blank=True, editable=True)


class Nomination(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField(max_length=20000, null=True, blank=True)
    brief_desc = models.TextField(max_length=300, null=True, blank=True)
    nomi_post = models.ForeignKey(Post, null=True)
    nomi_form = models.OneToOneField('forms.Questionnaire', null=True, blank=True)

    status = models.CharField(max_length=50, choices=STATUS, default='Nomination created')
    result_approvals = models.ManyToManyField(Post, related_name='result_approvals', symmetrical=False, blank=True)
    nomi_approvals = models.ManyToManyField(Post, related_name='nomi_approvals', symmetrical=False, blank=True)
    club_search = models.ManyToManyField(Post, related_name='all_clubs', symmetrical=False, blank=True)
    group_status = models.CharField(max_length= 50, choices= GROUP_STATUS, default='normal')

    opening_date = models.DateField(null=True, blank=True)
    closing_date = models.DateField(null=True, blank=True, editable=True)

    year_choice = models.CharField(max_length=100, choices=YEAR_1, null=True)
    hall_choice = models.CharField(max_length=100, choices=HALL_1, null=True)
    dept_choice = models.CharField(max_length=100, choices=DEPT_1, null=True)

    def __str__(self):
        return self.name

    def append(self):
        selected = NominationInstance.objects.filter(nomination=self, status='Accepted')
        self.status = 'Work done'
        self.save()
        for each in selected:
            PostHistory.objects.create(post=self.nomi_post, user=each.user)
            self.nomi_post.post_holders.add(each.user)

        return self.nomi_post.post_holders

    def replace(self):
        for holder in self.nomi_post.post_holders.all():
            history = PostHistory.objects.get(post=self.nomi_post, user=holder)
            history.end = datetime.now()
            history.save()

        self.nomi_post.post_holders.clear()
        self.append()
        return self.nomi_post.post_holders

    def open_to_users(self):
        self.status = 'Nomination out'
        self.opening_date = datetime.now()
        self.save()
        return self.status


class NominationInstance(models.Model):
    nomination = models.ForeignKey('Nomination', on_delete=models.CASCADE, null=True)
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
    status = models.CharField(max_length=20, choices=NOMI_STATUS,  null=True, blank=True, default=None)
    interview_status = models.CharField(max_length=20, choices=INTERVIEW_STATUS,  null=True, blank=True,
                                        default='Interview Not Done')
    filled_form = models.OneToOneField('forms.FilledForm', null=True, blank=True)

    def __str__(self):
        return str(self.user) + ' ' + str(self.id)


class Commment(models.Model):
    comments = models.TextField(max_length=10000, null=True, blank=True)
    nomi_instance=models.ForeignKey(NominationInstance,on_delete = models.CASCADE, null = True)
    user = models.ForeignKey(User,on_delete = models.SET_NULL, null=True )


class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    name = models.CharField(max_length=40, blank=True)
    roll_no = models.IntegerField(null=True)
    year = models.CharField(max_length=4, choices=YEAR, default='Y16')
    programme = models.CharField(max_length=7, choices=PROGRAMME, default='B.Tech')
    department = models.CharField(max_length=200, choices=DEPT, default='AE')
    hall = models.CharField(max_length=10, choices=HALL, default=1)
    room_no = models.CharField(max_length=10, null=True, blank=True)
    contact = models.CharField(max_length=10, null=True, blank=True)

    def __str__(self):
        return str(self.name)


class GroupNomination(models.Model):
    title = models.CharField(max_length=2000,null =True)
    description = models.CharField(max_length=5000, null = True, blank = True)
    nominations = models.ManyToManyField(Nomination, symmetrical= False, blank= True)
    status = models.CharField(max_length= 50,choices= G_STATUS,default= 'created')
    approvals = models.ManyToManyField(Post, related_name='group_approvals', symmetrical=False, blank=True)

    def __str__(self):
        return str(self.title)


@receiver(post_save, sender=Nomination)
def ensure_parent_in_approvals(sender, **kwargs):
{'fraction_non_alphanumeric': 0.11334669338677354, 'fraction_numerical': 0.011703406813627254, 'mean_word_length': 4.440907108591365, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '453909', 'n_tokens_mistral': 4039, 'n_tokens_neox': 3855, 'n_words': 696}