<commit_before>"""Group models."""

from django.db import models
from events.models import Event, Ticket


class Group(models.Model):

    """A group at an event."""

    event = models.ForeignKey(Event, related_name="raw_groups")
    team_number = models.IntegerField(default=0)
    # TODO: Make a lot of this information admin configurable
    team_name = models.CharField(max_length=200, null=True)
    description = models.TextField(blank=True, null=True)
    github_url = models.URLField()

    @property
    def name(self):
        """Return the team name, or team number if there is none."""
        return self.team_name if self.team_name else \
            "Group %s" % self.team_number

    def __unicode__(self):
        """Return the name of this group."""
        return self.name

    def members(self):
        """List members of this group."""
        return [t.ticket.user for t in self.tickets]


class TicketInGroup(models.Model):

    """A ticket in a group."""

    group = models.ForeignKey(Group, related_name="tickets")
    ticket = models.ForeignKey(Ticket, related_name="groups")


def get_group(ticket):
    """Get the group this ticket belongs to, or None."""
    return ticket.groups.first()

Ticket.group = get_group


def get_groups(event):
    """Get groups for an event, ordered by team_number."""
    return event.raw_groups.all().order_by('team_number')

Event.groups = get_groups


def get_ungrouped_users(event):
    """Get ungrouped users attending an event."""
    return set(
        [t.user for t in event.tickets.all() if not t.groups.count() > 0])

Event.ungrouped_users = get_ungrouped_users<commit_msg>ensure that group members show<commit_after>"""Group models."""

from django.db import models
from events.models import Event, Ticket


class Group(models.Model):

    """A group at an event."""

    event = models.ForeignKey(Event, related_name="raw_groups")
    team_number = models.IntegerField(default=0)
    # TODO: Make a lot of this information admin configurable
    team_name = models.CharField(max_length=200, null=True)
    description = models.TextField(blank=True, null=True)
    github_url = models.URLField()

    @property
    def name(self):
        """Return the team name, or team number if there is none."""
        return self.team_name if self.team_name else \
            "Group %s" % self.team_number

    def __unicode__(self):
        """Return the name of this group."""
        return self.name

    def members(self):
        """List members of this group."""
        return [t.ticket.user for t in self.tickets.all()]


class TicketInGroup(models.Model):

    """A ticket in a group."""

    group = models.ForeignKey(Group, related_name="tickets")
    ticket = models.ForeignKey(Ticket, related_name="groups")


def get_group(ticket):
    """Get the group this ticket belongs to, or None."""
    return ticket.groups.first()

Ticket.group = get_group


def get_groups(event):
    """Get groups for an event, ordered by team_number."""
    return event.raw_groups.all().order_by('team_number')

Event.groups = get_groups


def get_ungrouped_users(event):
    """Get ungrouped users attending an event."""
    return set(
        [t.user for t in event.tickets.all() if not t.groups.count() > 0 and
         not t.cancelled])

Event.ungrouped_users = get_ungrouped_users
{'fraction_non_alphanumeric': 0.1177525403466826, 'fraction_numerical': 0.002988643156007173, 'mean_word_length': 3.3981603153745072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2232324', 'n_tokens_mistral': 1018, 'n_tokens_neox': 980, 'n_words': 302}