<s> from django . db import models <EOL> from django . core . paginator import Paginator , EmptyPage , PageNotAnInteger <EOL> from wagtail . wagtailcore . models import Page , Orderable <EOL> from wagtail . wagtailcore . fields import RichTextField <EOL> from wagtail . wagtailimages . edit_handlers import ImageChooserPanel <EOL> from wagtail . wagtailimages . models import Image <EOL> from wagtail . wagtailadmin . edit_handlers import ( <EOL> FieldPanel , MultiFieldPanel , InlinePanel <EOL> ) <EOL> from wagtail . wagtailsearch import index <EOL> from wagtail . wagtailsnippets . models import register_snippet <EOL> from wagtail . wagtailsnippets . edit_handlers import SnippetChooserPanel <EOL> from modelcluster . fields import ParentalKey <EOL> from modelcluster . tags import ClusterTaggableManager <EOL> from taggit . models import Tag , TaggedItemBase <EOL> from utils . models import LinkFields , RelatedLink , CarouselItem <EOL> class ProductIndexPageRelatedLink ( Orderable , RelatedLink ) : <EOL> page = ParentalKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> class ProductIndexPage ( Page ) : <EOL> subtitle = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> intro = RichTextField ( blank = True ) <EOL> indexed_fields = ( '<STR_LIT>' , ) <EOL> @ property <EOL> def products ( self ) : <EOL> products = ProductPage . objects . live ( ) . descendant_of ( self ) <EOL> return products <EOL> @ property <EOL> def tag_list ( self ) : <EOL> tag_ids = ProductPageTag . objects . all ( ) . values_list ( '<STR_LIT>' , flat = True ) <EOL> return Tag . objects . filter ( pk__in = tag_ids ) <EOL> def get_context ( self , request ) : <EOL> products = self . products <EOL> tag = request . GET . get ( '<STR_LIT>' ) <EOL> if tag : <EOL> products = products . filter ( tags__name = tag ) <EOL> page = request . GET . get ( '<STR_LIT>' ) <EOL> paginator = Paginator ( products , <NUM_LIT:12> ) <EOL> try : <EOL> products = paginator . page ( page ) <EOL> except PageNotAnInteger : <EOL> products = paginator . page ( <NUM_LIT:1> ) <EOL> except EmptyPage : <EOL> products = paginator . page ( paginator . num_pages ) <EOL> context = super ( ProductIndexPage , self ) . get_context ( request ) <EOL> context [ '<STR_LIT>' ] = products <EOL> return context <EOL> ProductIndexPage . content_panels = [ <EOL> FieldPanel ( '<STR_LIT:title>' , classname = "<STR_LIT>" ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> FieldPanel ( '<STR_LIT>' , classname = "<STR_LIT>" ) , <EOL> InlinePanel ( '<STR_LIT>' , label = "<STR_LIT>" ) , <EOL> ] <EOL> class ProductPageRelatedLink ( Orderable , RelatedLink ) : <EOL> page = ParentalKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> class ProductPageTag ( TaggedItemBase ) : <EOL> content_object = ParentalKey ( <EOL> '<STR_LIT>' , related_name = '<STR_LIT>' <EOL> ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class ProductPage ( Page ) : <EOL> price = models . CharField ( max_length = <NUM_LIT:255> , blank = True ) <EOL> description = RichTextField ( blank = True ) <EOL> tags = ClusterTaggableManager ( through = ProductPageTag , blank = True ) <EOL> image = models . ForeignKey ( <EOL> Image , <EOL> null = True , <EOL> blank = True , <EOL> on_delete = models . SET_NULL , <EOL> related_name = '<STR_LIT:+>' <EOL> ) <EOL> feed_image = models . ForeignKey ( <EOL> Image , <EOL> null = True , <EOL> blank = True , <EOL> on_delete = models . SET_NULL , <EOL> related_name = '<STR_LIT:+>' <EOL> ) <EOL> indexed_fields = ( '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ProductPage . content_panels = [ <EOL> FieldPanel ( '<STR_LIT:title>' , classname = "<STR_LIT:title>" ) , <EOL> FieldPanel ( '<STR_LIT>' , classname = "<STR_LIT>" ) , <EOL> FieldPanel ( '<STR_LIT:description>' , classname = "<STR_LIT>" ) , <EOL> ImageChooserPanel ( '<STR_LIT:image>' ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> InlinePanel ( '<STR_LIT>' , label = "<STR_LIT>" ) , <EOL> ] <EOL> ProductPage . promote_panels = [ <EOL> MultiFieldPanel ( Page . promote_panels , "<STR_LIT>" ) , <EOL> ImageChooserPanel ( '<STR_LIT>' ) , <EOL> ] </s>
