<commit_before>from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext as _

from period import Period



class RelatedUserBase(models.Model):
    """
    .. attribute:: tag

        A string with less than 50 characters.
    """
    tag = models.CharField(max_length=50, verbose_name=_('Tag'),
                          help_text=_('A string with less than 50 characters.'))
    user = models.ForeignKey(User, verbose_name=_('User'))

    class Meta:
        abstract = True # This model will then not be used to create any database table. Instead, when it is used as a base class for other models, its fields will be added to those of the child class.
        unique_together = ('tag', 'user')
        app_label = 'core'


class RelatedExaminer(RelatedUserBase):
    """
    .. attribute:: period

        A django.db.models.ForeignKey_ that points to the `Period`_.
    """
    period = models.ForeignKey(Period, related_name='relatedexaminers',
                               verbose_name=_('Period'))


class RelatedStudent(RelatedUserBase):
    """
    .. attribute:: period

        A django.db.models.ForeignKey_ that points to the `Period`_.
    """
    period = models.ForeignKey(Period, related_name='relatedstudents',
                               verbose_name=_('Period'))


    def __unicode__(self):
        return '{0}:{1}:{2}'.format(self.tag, self.user, self.period)<commit_msg>apps.core.models.relateduser: Simplified #144.<commit_after>from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext as _
from django.db.models import Q

from period import Period
from node import Node
from abstract_is_admin import AbstractIsAdmin



class RelatedUserBase(models.Model, AbstractIsAdmin):
    username = models.SlugField(max_length=30, help_text=_('A username.'))

    class Meta:
        abstract = True # This model will then not be used to create any database table. Instead, when it is used as a base class for other models, its fields will be added to those of the child class.
        unique_together = ('period', 'username')
        app_label = 'core'

    @classmethod
    def q_is_admin(cls, user_obj):
        return Q(admins=user_obj) | \
                Q(period__admins=user_obj) | \
                Q(period__parentnode__admins=user_obj) | \
                Q(period__parentnode__parentnode__pk__in=Node._get_nodepks_where_isadmin(user_obj))

    def __unicode__(self):
        return '{0}:{1}'.format(self.period, self.username)


class RelatedExaminer(RelatedUserBase):
    """
    .. attribute:: period

        A django.db.models.ForeignKey_ that points to the `Period`_.
    """
    period = models.ForeignKey(Period, related_name='relatedexaminers',
                               verbose_name=_('Period'))


class RelatedStudent(RelatedUserBase):
    """
    .. attribute:: period

        A django.db.models.ForeignKey_ that points to the `Period`_.
    """
    period = models.ForeignKey(Period, related_name='relatedstudents',
                               verbose_name=_('Period'))
{'fraction_non_alphanumeric': 0.10079491255961844, 'fraction_numerical': 0.005087440381558029, 'mean_word_length': 2.9129353233830844, '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': '5778602', 'n_tokens_mistral': 899, 'n_tokens_neox': 858, 'n_words': 246}