<commit_before>from django.contrib.contenttypes.models import ContentType

from autocomplete_light.generic import GenericForeignKeyField
from .base import ChannelBase

__all__ = ['GenericChannelBase']


class GenericChannelBase(ChannelBase):
    """
    Wraps around multiple querysets, from multiple model classes, rather than
    just one.

    This is also interresting as it overrides **all** the default model logic
    from ChannelBase. Hell, you could even copy it and make your
    CSVChannelBase, a channel that uses a CSV file as backend. But only if
    you're really bored or for a milion dollars.
    """

    def result_as_value(self, result):
        """
        Rely on GenericForeignKeyField to return a string containing the
        content type id and object id of the result.

        Because this channel is made for that field, and to avoid code
        duplication.
        """
        return GenericForeignKeyField.prepare_value(None, result)

    def order_results(self, results):
        """
        Return results, **without** doing any ordering.<commit_msg>Bugfix in GenericChannelBase, was not using GFK right<commit_after>from django.contrib.contenttypes.models import ContentType

from autocomplete_light.generic import GenericForeignKeyField
from .base import ChannelBase

__all__ = ['GenericChannelBase']


class GenericChannelBase(ChannelBase):
    """
    Wraps around multiple querysets, from multiple model classes, rather than
    just one.

    This is also interresting as it overrides **all** the default model logic
    from ChannelBase. Hell, you could even copy it and make your
    CSVChannelBase, a channel that uses a CSV file as backend. But only if
    you're really bored or for a milion dollars.
    """

    def result_as_value(self, result):
        """
        Rely on GenericForeignKeyField to return a string containing the
        content type id and object id of the result.

        Because this channel is made for that field, and to avoid code
        duplication.
        """
        field = GenericForeignKeyField()
        return field.prepare_value(result)

    def order_results(self, results):
        """
        Return results, **without** doing any ordering.
{'fraction_non_alphanumeric': 0.059694793536804305, 'fraction_numerical': 0.0, 'mean_word_length': 3.2056603773584906, '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': '3936695', 'n_tokens_mistral': 565, 'n_tokens_neox': 549, 'n_words': 243}