<s> from rest_framework import serializers <EOL> from wq . db . patterns . base import serializers as base <EOL> import swapper <EOL> from . models import Markdown <EOL> MarkdownType = swapper . load_model ( <EOL> '<STR_LIT>' , '<STR_LIT>' , required = False <EOL> ) <EOL> def active_markdown ( qs , request ) : <EOL> mtype = MarkdownType . get_current ( request ) <EOL> return qs . filter ( type = mtype ) <EOL> class MarkdownSerializer ( base . TypedAttachmentSerializer ) : <EOL> html = serializers . ReadOnlyField ( ) <EOL> class Meta ( base . TypedAttachmentSerializer . Meta ) : <EOL> model = Markdown <EOL> list_exclude = ( '<STR_LIT:html>' , ) <EOL> class MarkedModelSerializer ( base . AttachedModelSerializer ) : <EOL> markdown = MarkdownSerializer . for_depth ( <NUM_LIT:1> ) ( many = True ) <EOL> def to_representation ( self , instance ) : <EOL> data = super ( MarkedModelSerializer , self ) . to_representation ( instance ) <EOL> if '<STR_LIT>' not in data or '<STR_LIT>' not in self . context : <EOL> return data <EOL> request = self . context [ '<STR_LIT>' ] <EOL> active_ids = active_markdown ( <EOL> instance . markdown , request <EOL> ) . values_list ( '<STR_LIT>' , flat = True ) <EOL> data [ '<STR_LIT>' ] = [ <EOL> markdown for markdown in data [ '<STR_LIT>' ] <EOL> if markdown [ '<STR_LIT:id>' ] in active_ids <EOL> ] <EOL> return data </s>
