<commit_before>from django.db import models
from django.db.models import Q
from django.core.exceptions import ValidationError
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.db.models.loading import get_model
from django.core.mail import send_mail

from ..utils.models import BaseModel
from .constants import PERMISSION_CHOICES, READ_PERMISSION, WRITE_PERMISSION


class Board(BaseModel):
    name = models.CharField(max_length=255)

    account = models.ForeignKey('accounts.Account')
    created_by = models.ForeignKey('users.User')

    is_shared = models.BooleanField(default=False)

    thumbnail_sm_path = models.TextField(blank=True)
    thumbnail_md_path = models.TextField(blank=True)
    thumbnail_lg_path = models.TextField(blank=True)

    def __str__(self):
        return self.name

    def get_thumbnail_url(self, size='sm'):
        """
        Returns full thumbnail url.
        BUCKET_URL + thumbnail path
        """
        pass

    def is_user_collaborator(self, user, permission=None):
        """
        Returns `True` if a user is a collaborator on this
        Board, `False` otherwise. Optionally checks if a user
        is a collaborator with a specific permission.
        """
        collaborators = BoardCollaborator.objects.filter(board=self, user=user)

        if permission == READ_PERMISSION:
            collaborators = collaborators.filter(
                Q(permission=WRITE_PERMISSION) | Q(permission=READ_PERMISSION))
        elif permission == WRITE_PERMISSION:
            collaborators = collaborators.filter(permission=WRITE_PERMISSION)

        return collaborators.exists()


@receiver([post_save], sender=Board)
def create_owner_collaborator(instance, created=False, **kwargs):
    """
    Create BoardCollaborator for account owner after creating a Board.
    """
    if created:
        account_owner = instance.account.owner

        BoardCollaborator.objects.create(
            board=instance,
            user=account_owner.user,
            permission=WRITE_PERMISSION
        )


class BoardCollaborator(BaseModel):
    board = models.ForeignKey('boards.Board')
    user = models.ForeignKey('users.User', blank=True, null=True)
    invited_user = models.ForeignKey('invitations.Inviteduser',
                                     blank=True, null=True)
<commit_msg>Fix case of ForeignKey to match model<commit_after>from django.db import models
from django.db.models import Q
from django.core.exceptions import ValidationError
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.db.models.loading import get_model
from django.core.mail import send_mail

from ..utils.models import BaseModel
from .constants import PERMISSION_CHOICES, READ_PERMISSION, WRITE_PERMISSION


class Board(BaseModel):
    name = models.CharField(max_length=255)

    account = models.ForeignKey('accounts.Account')
    created_by = models.ForeignKey('users.User')

    is_shared = models.BooleanField(default=False)

    thumbnail_sm_path = models.TextField(blank=True)
    thumbnail_md_path = models.TextField(blank=True)
    thumbnail_lg_path = models.TextField(blank=True)

    def __str__(self):
        return self.name

    def get_thumbnail_url(self, size='sm'):
        """
        Returns full thumbnail url.
        BUCKET_URL + thumbnail path
        """
        pass

    def is_user_collaborator(self, user, permission=None):
        """
        Returns `True` if a user is a collaborator on this
        Board, `False` otherwise. Optionally checks if a user
        is a collaborator with a specific permission.
        """
        collaborators = BoardCollaborator.objects.filter(board=self, user=user)

        if permission == READ_PERMISSION:
            collaborators = collaborators.filter(
                Q(permission=WRITE_PERMISSION) | Q(permission=READ_PERMISSION))
        elif permission == WRITE_PERMISSION:
            collaborators = collaborators.filter(permission=WRITE_PERMISSION)

        return collaborators.exists()


@receiver([post_save], sender=Board)
def create_owner_collaborator(instance, created=False, **kwargs):
    """
    Create BoardCollaborator for account owner after creating a Board.
    """
    if created:
        account_owner = instance.account.owner

        BoardCollaborator.objects.create(
            board=instance,
            user=account_owner.user,
            permission=WRITE_PERMISSION
        )


class BoardCollaborator(BaseModel):
    board = models.ForeignKey('boards.Board')
    user = models.ForeignKey('users.User', blank=True, null=True)
    invited_user = models.ForeignKey('invitations.InvitedUser',
                                     blank=True, null=True)

{'fraction_non_alphanumeric': 0.08560637851447755, 'fraction_numerical': 0.001258917331095258, 'mean_word_length': 3.2, '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': '3718335', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1297, 'n_words': 306}