<commit_before>from rest_framework import serializers
from wq.db.patterns.base import serializers as base
import swapper
MarkdownType = swapper.load_model(
    'mark', 'MarkdownType', required=False
)
from .models import Markdown


class MarkdownSerializer(base.TypedAttachmentSerializer):
    attachment_fields = ['id', 'summary', 'markdown']
    type_model = MarkdownType
    html = serializers.ReadOnlyField()

    class Meta(base.TypedAttachmentSerializer.Meta):
        model = Markdown


class MarkedModelSerializer(base.AttachedModelSerializer):
    markdown = MarkdownSerializer(many=True)

    def to_representation(self, instance):
        data = super(MarkedModelSerializer, self).to_representation(instance)
        if 'markdown' not in data:
            return

        # Only include active markdown in output
        # (FIXME: ideally this filter would happen *before* initial
        #  serialization)
        from .rest import active_markdown
        request = self.context['request']
        active_ids = active_markdown(
            instance.markdown, request
        ).values_list('pk', flat=True)
        data['markdown'] = [
            markdown for markdown in data['markdown']
            if markdown['id'] in active_ids
        ]
        return data

    class Meta:
        list_exclude = ('markdown',)<commit_msg>markdown not in list views<commit_after>from rest_framework import serializers
from wq.db.patterns.base import serializers as base
import swapper
MarkdownType = swapper.load_model(
    'mark', 'MarkdownType', required=False
)
from .models import Markdown


class MarkdownSerializer(base.TypedAttachmentSerializer):
    attachment_fields = ['id', 'summary', 'markdown']
    type_model = MarkdownType
    html = serializers.ReadOnlyField()

    class Meta(base.TypedAttachmentSerializer.Meta):
        model = Markdown


class MarkedModelSerializer(base.AttachedModelSerializer):
    markdown = MarkdownSerializer(many=True)

    def to_representation(self, instance):
        data = super(MarkedModelSerializer, self).to_representation(instance)
        if 'markdown' not in data:
            return data

        # Only include active markdown in output
        # (FIXME: ideally this filter would happen *before* initial
        #  serialization)
        from .rest import active_markdown
        request = self.context['request']
        active_ids = active_markdown(
            instance.markdown, request
        ).values_list('pk', flat=True)
        data['markdown'] = [
            markdown for markdown in data['markdown']
            if markdown['id'] in active_ids
        ]
        return data

    class Meta:
        list_exclude = ('markdown',)
{'fraction_non_alphanumeric': 0.08524833209785027, 'fraction_numerical': 0.0, 'mean_word_length': 3.101823708206687, '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': '1755152', 'n_tokens_mistral': 727, 'n_tokens_neox': 694, 'n_words': 192}