<s> from django . utils import timezone <EOL> from django . contrib . sites . models import get_current_site <EOL> from django . conf import settings <EOL> from haystack . query import SearchQuerySet <EOL> from opps . views . generic . list import ListView <EOL> from opps . containers . models import Container <EOL> from opps . channels . models import Channel <EOL> from . models import Tag <EOL> USE_HAYSTACK = getattr ( settings , '<STR_LIT>' , False ) <EOL> class TagList ( ListView ) : <EOL> model = Container <EOL> def get_template_list ( self , domain_folder = "<STR_LIT>" ) : <EOL> templates = [ ] <EOL> list_name = '<STR_LIT>' <EOL> if self . request . GET . get ( '<STR_LIT>' ) and self . __class__ . __name__ not in settings . OPPS_PAGINATE_NOT_APP : <EOL> templates . append ( '<STR_LIT>' . format ( domain_folder , <EOL> list_name ) ) <EOL> templates . append ( '<STR_LIT>' . format ( domain_folder , list_name ) ) <EOL> return templates <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( TagList , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . kwargs [ '<STR_LIT>' ] <EOL> site = get_current_site ( self . request ) <EOL> context [ '<STR_LIT>' ] = Channel . objects . get_homepage ( site ) <EOL> return context <EOL> def get_queryset ( self ) : <EOL> self . site = get_current_site ( self . request ) <EOL> self . long_slug = '<STR_LIT>' <EOL> self . tag = self . kwargs [ '<STR_LIT>' ] <EOL> if USE_HAYSTACK : <EOL> return self . get_queryset_from_haystack ( ) <EOL> return self . get_queryset_from_db ( ) <EOL> def get_queryset_from_haystack ( self ) : <EOL> models = Container . get_children_models ( ) <EOL> sqs = SearchQuerySet ( ) . models ( * models ) . filter ( <EOL> tags = self . tag ) . order_by ( '<STR_LIT>' ) <EOL> sqs . model = Container <EOL> return sqs <EOL> def get_queryset_from_db ( self ) : <EOL> tags = Tag . objects . filter ( slug = self . tag ) . values_list ( '<STR_LIT:name>' ) or [ ] <EOL> tags_names = [ ] <EOL> if tags : <EOL> tags_names = [ i [ <NUM_LIT:0> ] for i in tags ] <EOL> ids = [ ] <EOL> for tag in tags_names : <EOL> result = self . containers = self . model . objects . filter ( <EOL> site_domain = self . site , <EOL> tags__contains = tag , <EOL> date_available__lte = timezone . now ( ) , <EOL> published = True <EOL> ) <EOL> if result . exists ( ) : <EOL> ids . extend ( [ i . id for i in result ] ) <EOL> ids = list ( set ( ids ) ) <EOL> self . containers = self . model . objects . filter ( id__in = ids ) <EOL> return self . containers </s>
