|
| 1 | +from django.db import models |
| 2 | + |
| 3 | +from wagtail.models import Page |
| 4 | +from wagtail.fields import RichTextField, StreamField |
| 5 | +from wagtail.admin.panels import FieldPanel, MultiFieldPanel, PageChooserPanel |
| 6 | +from wagtail.blocks import CharBlock, StreamBlock, StructBlock, URLBlock, RichTextBlock, PageChooserBlock |
| 7 | +from modelcluster.fields import ParentalKey, ParentalManyToManyField |
| 8 | + |
| 9 | + |
| 10 | +class EventOwnerPage(Page): |
| 11 | + max_count = 1 |
| 12 | + |
| 13 | + event_location_title = models.CharField(default="Event Location") |
| 14 | + join_event_title = models.CharField(default="Join This Event") |
| 15 | + rsvp_button_text = models.CharField(default="RSVP") |
| 16 | + more_events_title = models.CharField(default="More Events") |
| 17 | + view_all_events_text = models.CharField(default="View all Events") |
| 18 | + view_all_events_url = models.URLField(blank=True) |
| 19 | + event_read_more_text = models.CharField(default="Read more") |
| 20 | + |
| 21 | + content_panels = Page.content_panels + [ |
| 22 | + FieldPanel('event_location_title'), |
| 23 | + FieldPanel('join_event_title'), |
| 24 | + FieldPanel('rsvp_button_text'), |
| 25 | + FieldPanel('more_events_title'), |
| 26 | + FieldPanel('view_all_events_text'), |
| 27 | + FieldPanel('view_all_events_url'), |
| 28 | + FieldPanel('event_read_more_text'), |
| 29 | + ] |
| 30 | + |
| 31 | + |
| 32 | +class IndividualEventPage(Page): |
| 33 | + parent_page_type = [ |
| 34 | + 'projects.ProjectOwnerPage' |
| 35 | + ] |
| 36 | + |
| 37 | + start_date_time = models.DateTimeField() |
| 38 | + end_date_time = models.DateTimeField() |
| 39 | + |
| 40 | + image = models.ForeignKey( |
| 41 | + "wagtailimages.Image", |
| 42 | + null=True, |
| 43 | + blank=True, |
| 44 | + on_delete=models.SET_NULL, |
| 45 | + related_name="+", |
| 46 | + help_text="Image to represent the event" |
| 47 | + ) |
| 48 | + intro = RichTextField(blank=True) |
| 49 | + extended_description = StreamField([ |
| 50 | + ('text_block', RichTextBlock(features=[ |
| 51 | + 'h1', 'h2', 'h3', 'h4', 'bold', 'italic', 'link', 'ol', 'ul', 'hr', 'document-link', 'image', 'embed', 'code', 'blockquote' |
| 52 | + ])) |
| 53 | + ], use_json_field=True, null=True) |
| 54 | + |
| 55 | + event_location = models.CharField(blank=True) |
| 56 | + rsvp_description = RichTextField(blank=True, help_text="If this field is empty, the RSVP description will not appear.") |
| 57 | + rsvp_link = models.URLField(blank=True, help_text="If this field is empty, the RSVP button will not appear. If both RSVP Description and Link are empty, the RSVP section will be hidden.") |
| 58 | + |
| 59 | + more_events = StreamField([ |
| 60 | + ('event', PageChooserBlock(page_type="events.IndividualEventPage")) |
| 61 | + ], use_json_field=True, null=True, blank=True) |
| 62 | + |
| 63 | + content_panels = Page.content_panels + [ |
| 64 | + MultiFieldPanel([ |
| 65 | + FieldPanel('start_date_time'), |
| 66 | + FieldPanel('end_date_time'), |
| 67 | + ], heading="Date and Time"), |
| 68 | + MultiFieldPanel([ |
| 69 | + FieldPanel('image'), |
| 70 | + FieldPanel('intro'), |
| 71 | + FieldPanel('extended_description'), |
| 72 | + ], heading="Body"), |
| 73 | + MultiFieldPanel([ |
| 74 | + FieldPanel('event_location'), |
| 75 | + FieldPanel('rsvp_description'), |
| 76 | + FieldPanel('rsvp_link'), |
| 77 | + FieldPanel('more_events'), |
| 78 | + ], heading="Sidebar") |
| 79 | + ] |
0 commit comments