<commit_before># AGAGD Models Imports
import agagd_core.models as agagd_models

# DJango Imports
import django_tables2 as tables

# AGAGD Column Imports
from agagd_core.tables.core import ChapterColumn
from django.core.exceptions import ObjectDoesNotExist
from django.urls import reverse
from django.utils.safestring import mark_safe

# Base Bootstrap Column Attributes
default_bootstrap_column_attrs = {
    "th": {"class": "d-none d-lg-table-cell d-xl-table-cell"},
    "td": {"class": "d-none d-lg-table-cell d-xl-table-cell"},
}

# Base Bootstrap Column Header Attributes
default_bootstrap_header_column_attrs = {
    "class": "table",
    "thead": {"class": "thead-dark"},
    "th": {"scope": "col"},
}

# Column for the Winner of the Game
class LinkFullMembersNameColumn(tables.Column):
    def __init__(
        self,
        color="W",
        viewname=None,
        urlconf=None,
        args=None,
        kwargs=None,
        current_app=None,
        attrs=None,
        **extra,
    ):
        super().__init__(
            attrs=attrs,
            linkify=dict(
                viewname=viewname,
                urlconf=urlconf,
                args=args,
                kwargs=kwargs,
                current_app=current_app,
            ),
            **extra,
        )
        self.color = color

    def render(self, value, record):
        if record["result"] == self.color:
            self.attrs["td"] = {"class": "winner"}
        elif record["result"] != self.color:
            self.attrs["td"] = {"class": "runner-up"}

        try:
            member_name_and_id = agagd_models.Member.objects.get(member_id=value)
            value = f"{member_name_and_id.full_name} ({value})"
        except ObjectDoesNotExist:
            value = None

        return value


# Basic table which is use as as base for many of the game layouts.
class GamesTable(tables.Table):
    game_date = tables.Column(
        verbose_name="Date", attrs=default_bootstrap_column_attrs, orderable=False
    )
    handicap = tables.Column(attrs=default_bootstrap_column_attrs, orderable=False)
    pin_player_1 = LinkFullMembersNameColumn(
        color="W",
        viewname="players_profile",
        verbose_name="White",
        kwargs={"player_id": tables.A("pin_player_1")},
        orderable=False,
    )
    pin_player_2 = LinkFullMembersNameColumn(
        color="B",
        viewname="players_profile",
        verbose_name="Black",
        kwargs={"player_id": tables.A("pin_player_2")},
        orderable=False,
    )
    tournament_code = tables.LinkColumn(
        verbose_name="Tournament",
        viewname="tournament_detail",
        kwargs={"code": tables.A("tournament_code")},
        orderable=False,
    )

    class Meta:
        model = agagd_models.Game
        fields = (
            "pin_player_1",
            "pin_player_2",
            "tournament_code",
            "handicap",
            "game_date",
        )
        sequence = fields
        attrs = default_bootstrap_header_column_attrs
        template_name = "django_tables2/bootstrap4.html"


class PlayersInformationTable(tables.Table):
    full_name = tables.Column()
    member_id = tables.Column()
    status = tables.Column()
    rating = tables.Column()
    renewal_due = tables.Column()

    class Meta:
        template_name = "beta.player_profile_information.html"


class PlayersOpponentTable(tables.Table):
    opponent = tables.Column(
        orderable=False,
        linkify={
            "viewname": "players_profile",
            "args": [tables.A("opponent.member_id")],
        },
    )
    total = tables.Column(orderable=False, verbose_name="Games")
    won = tables.Column(orderable=False, verbose_name="Won", default=0)
    lost = tables.Column(orderable=False, verbose_name="Lost")
    ratio = tables.Column(
        verbose_name="Rate", default=0, empty_values=(-1,), orderable=False
    )

    def render_ratio(self, record):
        ratio = record["won"] / record["total"]

        return f"{ratio:.2f}"

    class Meta:
        attrs = default_bootstrap_header_column_attrs
        template_name = "django_tables2/bootstrap4.html"


class TournamentsTable(tables.Table):
    tournament_date = tables.Column(verbose_name="Date", orderable=False)
    description = tables.Column(
        verbose_name="Name",
        linkify=("tournament_detail", [tables.A("tournament_code")]),
    )
    tournament_code = tables.Column(
        verbose_name="Name",
        linkify=("tournament_detail", [tables.A("tournament_code")]),
    )
    total_players = tables.Column(
        verbose_name="# Players", attrs=default_bootstrap_column_attrs
    )
    elab_date = tables.Column(verbose_name="Rated")

    class Meta:
        attrs = default_bootstrap_header_column_attrs
        fields = (
            "description",
            "tournament_code",
            "total_players",
            "tournament_date",
            "elab_date",
        )
        model = agagd_models.Tournament
        orderable = False
        sequence = fields
        template_name = "django_tables2/bootstrap4.html"


class PlayersTournamentTable(tables.Table):
    tournament = tables.LinkColumn(
        "tournament_detail", kwargs={"code": tables.A("tournament.pk")}, orderable=False
    )
    date = tables.Column(orderable=False, default="Unknown")
    won = tables.Column(orderable=False, verbose_name="Won", default=0)
    lost = tables.Column(orderable=False, verbose_name="Lost", default=0)

    class Meta:
        fields = ("date", "tournament", "won", "lost")
        sequence = fields
        attrs = default_bootstrap_header_column_attrs
        template_name = "django_tables2/bootstrap4.html"


class SearchResultsTable(tables.Table):
    member_id = tables.Column(linkify=("players_profile", [tables.A("member_id")]))
    chapter_id = ChapterColumn(verbose_name="Chapter")
    players__rating = tables.Column(verbose_name="Rating")
    country = tables.Column()
    full_name = tables.Column(linkify=("players_profile", [tables.A("member_id")]))

    class Meta:
        attrs = default_bootstrap_header_column_attrs
        fields = (
            "full_name",
            "member_id",
            "players__rating",
            "chapter_id",
            "country",
            "state",
            "renewal_due",
        )
        model = agagd_models.Member
        orderable = False
        sequence = fields
        template_name = "django_tables2/bootstrap4.html"
<commit_msg>Small fix for Tournament Table Header.<commit_after># AGAGD Models Imports
import agagd_core.models as agagd_models

# DJango Imports
import django_tables2 as tables

# AGAGD Column Imports
from agagd_core.tables.core import ChapterColumn
from django.core.exceptions import ObjectDoesNotExist
from django.urls import reverse
from django.utils.safestring import mark_safe

# Base Bootstrap Column Attributes
default_bootstrap_column_attrs = {
    "th": {"class": "d-none d-lg-table-cell d-xl-table-cell"},
    "td": {"class": "d-none d-lg-table-cell d-xl-table-cell"},
}

# Base Bootstrap Column Header Attributes
default_bootstrap_header_column_attrs = {
    "class": "table",
    "thead": {"class": "thead-dark"},
    "th": {"scope": "col"},
}

# Column for the Winner of the Game
class LinkFullMembersNameColumn(tables.Column):
    def __init__(
        self,
        color="W",
        viewname=None,
        urlconf=None,
        args=None,
        kwargs=None,
        current_app=None,
        attrs=None,
        **extra,
    ):
        super().__init__(
            attrs=attrs,
            linkify=dict(
                viewname=viewname,
                urlconf=urlconf,
                args=args,
                kwargs=kwargs,
                current_app=current_app,
            ),
            **extra,
        )
        self.color = color

    def render(self, value, record):
        if record["result"] == self.color:
            self.attrs["td"] = {"class": "winner"}
        elif record["result"] != self.color:
            self.attrs["td"] = {"class": "runner-up"}

        try:
            member_name_and_id = agagd_models.Member.objects.get(member_id=value)
            value = f"{member_name_and_id.full_name} ({value})"
        except ObjectDoesNotExist:
            value = None

        return value


# Basic table which is use as as base for many of the game layouts.
class GamesTable(tables.Table):
    game_date = tables.Column(
        verbose_name="Date", attrs=default_bootstrap_column_attrs, orderable=False
    )
    handicap = tables.Column(attrs=default_bootstrap_column_attrs, orderable=False)
    pin_player_1 = LinkFullMembersNameColumn(
        color="W",
        viewname="players_profile",
        verbose_name="White",
        kwargs={"player_id": tables.A("pin_player_1")},
        orderable=False,
    )
    pin_player_2 = LinkFullMembersNameColumn(
        color="B",
        viewname="players_profile",
        verbose_name="Black",
        kwargs={"player_id": tables.A("pin_player_2")},
        orderable=False,
    )
    tournament_code = tables.LinkColumn(
        verbose_name="Tournament",
        viewname="tournament_detail",
        kwargs={"code": tables.A("tournament_code")},
        orderable=False,
    )

    class Meta:
        model = agagd_models.Game
        fields = (
            "pin_player_1",
            "pin_player_2",
            "tournament_code",
            "handicap",
            "game_date",
        )
        sequence = fields
        attrs = default_bootstrap_header_column_attrs
        template_name = "django_tables2/bootstrap4.html"


class PlayersInformationTable(tables.Table):
    full_name = tables.Column()
    member_id = tables.Column()
    status = tables.Column()
    rating = tables.Column()
    renewal_due = tables.Column()

    class Meta:
        template_name = "beta.player_profile_information.html"


class PlayersOpponentTable(tables.Table):
    opponent = tables.Column(
        orderable=False,
        linkify={
            "viewname": "players_profile",
            "args": [tables.A("opponent.member_id")],
        },
    )
    total = tables.Column(orderable=False, verbose_name="Games")
    won = tables.Column(orderable=False, verbose_name="Won", default=0)
    lost = tables.Column(orderable=False, verbose_name="Lost")
    ratio = tables.Column(
        verbose_name="Rate", default=0, empty_values=(-1,), orderable=False
    )

    def render_ratio(self, record):
        ratio = record["won"] / record["total"]

        return f"{ratio:.2f}"

    class Meta:
        attrs = default_bootstrap_header_column_attrs
        template_name = "django_tables2/bootstrap4.html"


class TournamentsTable(tables.Table):
    tournament_date = tables.Column(verbose_name="Date", orderable=False)
    description = tables.Column(
        verbose_name="Name",
        linkify=("tournament_detail", [tables.A("tournament_code")]),
    )
    tournament_code = tables.Column(
        verbose_name="Code",
        linkify=("tournament_detail", [tables.A("tournament_code")]),
    )
    total_players = tables.Column(
        verbose_name="# Players", attrs=default_bootstrap_column_attrs
    )
    elab_date = tables.Column(verbose_name="Rated")

    class Meta:
        attrs = default_bootstrap_header_column_attrs
        fields = (
            "description",
            "tournament_code",
            "total_players",
            "tournament_date",
            "elab_date",
        )
        model = agagd_models.Tournament
        orderable = False
        sequence = fields
        template_name = "django_tables2/bootstrap4.html"


class PlayersTournamentTable(tables.Table):
    tournament = tables.LinkColumn(
        "tournament_detail", kwargs={"code": tables.A("tournament.pk")}, orderable=False
    )
    date = tables.Column(orderable=False, default="Unknown")
    won = tables.Column(orderable=False, verbose_name="Won", default=0)
    lost = tables.Column(orderable=False, verbose_name="Lost", default=0)

    class Meta:
        fields = ("date", "tournament", "won", "lost")
        sequence = fields
        attrs = default_bootstrap_header_column_attrs
        template_name = "django_tables2/bootstrap4.html"


class SearchResultsTable(tables.Table):
    member_id = tables.Column(linkify=("players_profile", [tables.A("member_id")]))
    chapter_id = ChapterColumn(verbose_name="Chapter")
    players__rating = tables.Column(verbose_name="Rating")
    country = tables.Column()
    full_name = tables.Column(linkify=("players_profile", [tables.A("member_id")]))

    class Meta:
        attrs = default_bootstrap_header_column_attrs
        fields = (
            "full_name",
            "member_id",
            "players__rating",
            "chapter_id",
            "country",
            "state",
            "renewal_due",
        )
        model = agagd_models.Member
        orderable = False
        sequence = fields
        template_name = "django_tables2/bootstrap4.html"

{'fraction_non_alphanumeric': 0.11571329586573255, 'fraction_numerical': 0.003541458156901994, 'mean_word_length': 2.6705283978525007, 'pattern_counts': {'":': 34, '<': 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': '6062584', 'n_tokens_mistral': 3923, 'n_tokens_neox': 3809, 'n_words': 697}