<commit_before>from django.db import models
from django.conf import settings
from activity.models import Action  # noqa

from core.countries import COUNTRIES
from accounts.models import Profile  # noqa
from ticket.constants import REQUESTER_TYPES, TICKET_STATUS, TICKET_TYPES


class Responder(models.Model):
    """Intermediate model for ticket responders (M2M)."""
    user = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True)
    ticket = models.ForeignKey(
        'Ticket', related_name='responders', db_index=True)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        unique_together = ('user', 'ticket')

    @classmethod
    def filter_by_user(cls, user, queryset=None):
        """Returns any user responder objects.

        Either related to the tickets he created or he is subscribed to.
        """
        return (queryset or cls.objects).filter(
            # Allow own responder objects
            models.Q(user=user) |
            # Allow related to user responder tickets
            models.Q(ticket__users=user) |
            # Allow related to user created tickets
            models.Q(ticket__requester=user)
        )


class Ticket(models.Model):
    """Ticket model."""

    STATUSES = TICKET_STATUS

    users = models.ManyToManyField(
        settings.AUTH_USER_MODEL, through=Responder, db_index=True)
    requester = models.ForeignKey(
        settings.AUTH_USER_MODEL, related_name='requested_tickets',
        db_index=True)

    kind = models.CharField(
        blank=False, max_length=70, choices=TICKET_TYPES,
        default=TICKET_TYPES[-1][0], db_index=True)
    request_type = models.CharField(
        blank=False, max_length=70, choices=REQUESTER_TYPES,
        default=REQUESTER_TYPES[0][0], db_index=True)
    status = models.CharField(
        max_length=70, choices=TICKET_STATUS,
        default=TICKET_STATUS[0][0], db_index=True)

    sensitive = models.BooleanField(default=False)
    whysensitive = models.CharField(max_length=150, null=True, blank=True)
    deadline_at = models.DateTimeField(null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    sent_notifications_at = models.DateTimeField(null=True)

    # Other ticket type fields, also common to all other types
    background = models.TextField(blank=False, max_length=1000)

    # Person ticket type fields
    first_name = models.CharField(max_length=512, null=True, blank=True)
    last_name = models.CharField(max_length=512, null=True, blank=True)
    born_at = models.DateTimeField(null=True)
    connections = models.TextField(max_length=1000, null=True, blank=True)
    sources = models.TextField(max_length=1000, null=True, blank=True)
    business_activities = models.TextField(
        null=True, max_length=1000, blank=True)
    initial_information = models.TextField(
        max_length=1000, null=True, blank=True)

    # Company ticket type fields
    company_name = models.CharField(max_length=512, null=True, blank=True)
    country = models.CharField(
        max_length=100, choices=COUNTRIES, null=True, db_index=True, blank=True)<commit_msg>Remove extra `max_length` from ticket `background`.<commit_after>from django.db import models
from django.conf import settings
from activity.models import Action  # noqa

from core.countries import COUNTRIES
from accounts.models import Profile  # noqa
from ticket.constants import REQUESTER_TYPES, TICKET_STATUS, TICKET_TYPES


class Responder(models.Model):
    """Intermediate model for ticket responders (M2M)."""
    user = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True)
    ticket = models.ForeignKey(
        'Ticket', related_name='responders', db_index=True)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        unique_together = ('user', 'ticket')

    @classmethod
    def filter_by_user(cls, user, queryset=None):
        """Returns any user responder objects.

        Either related to the tickets he created or he is subscribed to.
        """
        return (queryset or cls.objects).filter(
            # Allow own responder objects
            models.Q(user=user) |
            # Allow related to user responder tickets
            models.Q(ticket__users=user) |
            # Allow related to user created tickets
            models.Q(ticket__requester=user)
        )


class Ticket(models.Model):
    """Ticket model."""

    STATUSES = TICKET_STATUS

    users = models.ManyToManyField(
        settings.AUTH_USER_MODEL, through=Responder, db_index=True)
    requester = models.ForeignKey(
        settings.AUTH_USER_MODEL, related_name='requested_tickets',
        db_index=True)

    kind = models.CharField(
        blank=False, max_length=70, choices=TICKET_TYPES,
        default=TICKET_TYPES[-1][0], db_index=True)
    request_type = models.CharField(
        blank=False, max_length=70, choices=REQUESTER_TYPES,
        default=REQUESTER_TYPES[0][0], db_index=True)
    status = models.CharField(
        max_length=70, choices=TICKET_STATUS,
        default=TICKET_STATUS[0][0], db_index=True)

    sensitive = models.BooleanField(default=False)
    whysensitive = models.CharField(max_length=150, null=True, blank=True)
    deadline_at = models.DateTimeField(null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    sent_notifications_at = models.DateTimeField(null=True)

    # Other ticket type fields, also common to all other types
    background = models.TextField(blank=False)

    # Person ticket type fields
    first_name = models.CharField(max_length=512, null=True, blank=True)
    last_name = models.CharField(max_length=512, null=True, blank=True)
    born_at = models.DateTimeField(null=True)
    connections = models.TextField(max_length=1000, null=True, blank=True)
    sources = models.TextField(max_length=1000, null=True, blank=True)
    business_activities = models.TextField(
        null=True, max_length=1000, blank=True)
    initial_information = models.TextField(
        max_length=1000, null=True, blank=True)

    # Company ticket type fields
    company_name = models.CharField(max_length=512, null=True, blank=True)
    country = models.CharField(
        max_length=100, choices=COUNTRIES, null=True, db_index=True, blank=True)
{'fraction_non_alphanumeric': 0.09618703907108113, 'fraction_numerical': 0.014435901459281343, 'mean_word_length': 3.799698795180723, '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': '6388823', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1918, 'n_words': 415}