<s> """<STR_LIT>""" <EOL> from django . db import models <EOL> from django . utils import timezone <EOL> from django . contrib . sites . models import Site <EOL> from zinnia . settings import SEARCH_FIELDS <EOL> DRAFT = <NUM_LIT:0> <EOL> HIDDEN = <NUM_LIT:1> <EOL> PUBLISHED = <NUM_LIT:2> <EOL> def tags_published ( ) : <EOL> """<STR_LIT>""" <EOL> from tagging . models import Tag <EOL> from zinnia . models . entry import Entry <EOL> tags_entry_published = Tag . objects . usage_for_queryset ( <EOL> Entry . published . all ( ) ) <EOL> return Tag . objects . filter ( name__in = [ t . name for t in tags_entry_published ] ) <EOL> def entries_published ( queryset ) : <EOL> """<STR_LIT>""" <EOL> now = timezone . now ( ) <EOL> return queryset . filter ( <EOL> models . Q ( start_publication__lte = now ) | <EOL> models . Q ( start_publication = None ) , <EOL> models . Q ( end_publication__gt = now ) | <EOL> models . Q ( end_publication = None ) , <EOL> status = PUBLISHED , sites = Site . objects . get_current ( ) ) <EOL> class EntryPublishedManager ( models . Manager ) : <EOL> """<STR_LIT>""" <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> return entries_published ( <EOL> super ( EntryPublishedManager , self ) . get_queryset ( ) ) <EOL> def on_site ( self ) : <EOL> """<STR_LIT>""" <EOL> return super ( EntryPublishedManager , self ) . get_queryset ( ) . filter ( <EOL> sites = Site . objects . get_current ( ) ) <EOL> def search ( self , pattern ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . advanced_search ( pattern ) <EOL> except : <EOL> return self . basic_search ( pattern ) <EOL> def advanced_search ( self , pattern ) : <EOL> """<STR_LIT>""" <EOL> from zinnia . search import advanced_search <EOL> return advanced_search ( pattern ) <EOL> def basic_search ( self , pattern ) : <EOL> """<STR_LIT>""" <EOL> lookup = None <EOL> for pattern in pattern . split ( ) : <EOL> query_part = models . Q ( ) <EOL> for field in SEARCH_FIELDS : <EOL> query_part |= models . Q ( ** { '<STR_LIT>' % field : pattern } ) <EOL> if lookup is None : <EOL> lookup = query_part <EOL> else : <EOL> lookup |= query_part <EOL> return self . get_queryset ( ) . filter ( lookup ) <EOL> class EntryRelatedPublishedManager ( models . Manager ) : <EOL> """<STR_LIT>""" <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> now = timezone . now ( ) <EOL> return super ( <EOL> EntryRelatedPublishedManager , self ) . get_queryset ( ) . filter ( <EOL> models . Q ( entries__start_publication__lte = now ) | <EOL> models . Q ( entries__start_publication = None ) , <EOL> models . Q ( entries__end_publication__gt = now ) | <EOL> models . Q ( entries__end_publication = None ) , <EOL> entries__status = PUBLISHED , <EOL> entries__sites = Site . objects . get_current ( ) <EOL> ) . distinct ( ) </s>
