<s> import logging <EOL> from flask import url_for <EOL> from quokka . core . db import db <EOL> from quokka . utils . text import slugify <EOL> from quokka . core . models . signature import Publishable , Ordered <EOL> logger = logging . getLogger ( ) <EOL> class SubContentPurpose ( db . Document ) : <EOL> title = db . StringField ( max_length = <NUM_LIT:255> , required = True ) <EOL> identifier = db . StringField ( max_length = <NUM_LIT:255> , required = True , unique = True ) <EOL> module = db . StringField ( ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> self . identifier = slugify ( self . identifier or self . title ) <EOL> super ( SubContentPurpose , self ) . save ( * args , ** kwargs ) <EOL> def __unicode__ ( self ) : <EOL> return self . title <EOL> class SubContent ( Publishable , Ordered , db . EmbeddedDocument ) : <EOL> """<STR_LIT>""" <EOL> content = db . ReferenceField ( '<STR_LIT>' , required = True ) <EOL> caption = db . StringField ( ) <EOL> purpose = db . ReferenceField ( SubContentPurpose , required = True ) <EOL> identifier = db . StringField ( ) <EOL> @ property <EOL> def thumb ( self ) : <EOL> try : <EOL> return url_for ( '<STR_LIT>' , filename = self . content . thumb ) <EOL> except Exception as e : <EOL> logger . warning ( str ( e ) ) <EOL> return self . content . get_main_image_url ( thumb = True ) <EOL> meta = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> def clean ( self ) : <EOL> self . identifier = self . purpose . identifier <EOL> def __unicode__ ( self ) : <EOL> return self . content and self . content . title or self . caption </s>
