<s> from django . db import models <EOL> from datetime import date <EOL> from django . core . paginator import Paginator , EmptyPage , PageNotAnInteger <EOL> from django . http import HttpResponse <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 . wagtailadmin . edit_handlers import ( <EOL> FieldPanel , MultiFieldPanel , InlinePanel <EOL> ) <EOL> from wagtail . wagtailsearch import index <EOL> from modelcluster . fields import ParentalKey <EOL> from utils . models import LinkFields , RelatedLink , CarouselItem <EOL> from . event_utils import export_event <EOL> EVENT_AUDIENCE_CHOICES = ( <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ) <EOL> class EventIndexPageRelatedLink ( Orderable , RelatedLink ) : <EOL> page = ParentalKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> class EventIndexPage ( Page ) : <EOL> intro = RichTextField ( blank = True ) <EOL> search_fields = Page . search_fields + ( <EOL> index . SearchField ( '<STR_LIT>' ) , <EOL> ) <EOL> @ property <EOL> def events ( self ) : <EOL> events = EventPage . objects . live ( ) . descendant_of ( self ) <EOL> events = events . filter ( date_from__gte = date . today ( ) ) <EOL> events = events . order_by ( '<STR_LIT>' ) <EOL> return events <EOL> def get_context ( self , request ) : <EOL> events = self . events <EOL> tag = request . GET . get ( '<STR_LIT>' ) <EOL> if tag : <EOL> events = events . filter ( tags__name = tag ) <EOL> page = request . GET . get ( '<STR_LIT>' ) <EOL> paginator = Paginator ( events , <NUM_LIT:9> ) <EOL> try : <EOL> events = paginator . page ( page ) <EOL> except PageNotAnInteger : <EOL> events = paginator . page ( <NUM_LIT:1> ) <EOL> except EmptyPage : <EOL> events = paginator . page ( paginator . num_pages ) <EOL> context = super ( EventIndexPage , self ) . get_context ( request ) <EOL> context [ '<STR_LIT>' ] = events <EOL> return context <EOL> EventIndexPage . content_panels = [ <EOL> FieldPanel ( '<STR_LIT:title>' , classname = "<STR_LIT>" ) , <EOL> FieldPanel ( '<STR_LIT>' , classname = "<STR_LIT>" ) , <EOL> InlinePanel ( '<STR_LIT>' , label = "<STR_LIT>" ) , <EOL> ] <EOL> EventIndexPage . promote_panels = Page . promote_panels <EOL> class EventPageCarouselItem ( Orderable , CarouselItem ) : <EOL> page = ParentalKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> class EventPageRelatedLink ( Orderable , RelatedLink ) : <EOL> page = ParentalKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> class EventPageSpeaker ( Orderable , LinkFields ) : <EOL> page = ParentalKey ( '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> full_name = models . CharField ( "<STR_LIT:Name>" , max_length = <NUM_LIT:255> , blank = True ) <EOL> image = models . ForeignKey ( <EOL> '<STR_LIT>' , <EOL> null = True , <EOL> blank = True , <EOL> on_delete = models . SET_NULL , <EOL> related_name = '<STR_LIT:+>' <EOL> ) <EOL> @ property <EOL> def name_display ( self ) : <EOL> return self . full_name <EOL> panels = [ <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> ImageChooserPanel ( '<STR_LIT:image>' ) , <EOL> MultiFieldPanel ( LinkFields . panels , "<STR_LIT>" ) , <EOL> ] <EOL> class EventPage ( Page ) : <EOL> date_from = models . DateField ( "<STR_LIT>" ) <EOL> date_to = models . DateField ( <EOL> "<STR_LIT>" , <EOL> null = True , <EOL> blank = True , <EOL> help_text = "<STR_LIT>" <EOL> ) <EOL> time_from = models . TimeField ( "<STR_LIT>" , null = True , blank = True ) <EOL> time_to = models . TimeField ( "<STR_LIT>" , null = True , blank = True ) <EOL> audience = models . CharField ( max_length = <NUM_LIT:255> , choices = EVENT_AUDIENCE_CHOICES , null = True , blank = True ) <EOL> location = models . CharField ( max_length = <NUM_LIT:255> , null = True , blank = True ) <EOL> body = RichTextField ( blank = True ) <EOL> cost = models . CharField ( max_length = <NUM_LIT:255> , null = True , blank = True ) <EOL> signup_link = models . URLField ( blank = True ) <EOL> feed_image = models . ForeignKey ( <EOL> '<STR_LIT>' , <EOL> null = True , <EOL> blank = True , <EOL> on_delete = models . SET_NULL , <EOL> related_name = '<STR_LIT:+>' <EOL> ) <EOL> search_fields = Page . search_fields + ( <EOL> index . SearchField ( '<STR_LIT>' ) , <EOL> index . SearchField ( '<STR_LIT:location>' ) , <EOL> index . SearchField ( '<STR_LIT:body>' ) , <EOL> ) <EOL> @ property <EOL> def event_index ( self ) : <EOL> return self . get_ancestors ( ) . type ( EventIndexPage ) . last ( ) <EOL> def serve ( self , request ) : <EOL> if "<STR_LIT>" in request . GET : <EOL> if request . GET [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> response = HttpResponse ( <EOL> export_event ( self , '<STR_LIT>' ) , <EOL> content_type = '<STR_LIT>' , <EOL> ) <EOL> content_dispo = '<STR_LIT>' + self . slug + '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = content_dispo <EOL> return response <EOL> else : <EOL> message = '<STR_LIT>' + request . GET [ '<STR_LIT>' ] <EOL> return HttpResponse ( message , content_type = '<STR_LIT>' ) <EOL> else : <EOL> return super ( EventPage , self ) . serve ( request ) <EOL> EventPage . content_panels = [ <EOL> FieldPanel ( '<STR_LIT:title>' , classname = "<STR_LIT>" ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> FieldPanel ( '<STR_LIT:location>' ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> FieldPanel ( '<STR_LIT>' ) , <EOL> InlinePanel ( '<STR_LIT>' , label = "<STR_LIT>" ) , <EOL> FieldPanel ( '<STR_LIT:body>' , classname = "<STR_LIT>" ) , <EOL> InlinePanel ( '<STR_LIT>' , label = "<STR_LIT>" ) , <EOL> InlinePanel ( '<STR_LIT>' , label = "<STR_LIT>" ) , <EOL> ] <EOL> EventPage . promote_panels = Page . promote_panels + [ <EOL> ImageChooserPanel ( '<STR_LIT>' ) , <EOL> ] </s>
