models.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. from __future__ import unicode_literals
  2. from django.db import models
  3. from django.db.utils import OperationalError
  4. from modelcluster.fields import ParentalKey
  5. from modelcluster.models import ClusterableModel
  6. from wagtail.wagtailcore.models import Page, Orderable, Collection
  7. from wagtail.wagtailsearch import index
  8. from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
  9. from wagtail.wagtailcore.fields import StreamField, RichTextField
  10. from wagtail.wagtailadmin.edit_handlers import (
  11. FieldPanel,
  12. InlinePanel,
  13. FieldRowPanel,
  14. StreamFieldPanel,
  15. MultiFieldPanel,
  16. PageChooserPanel
  17. )
  18. from wagtail.wagtailsnippets.models import register_snippet
  19. from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
  20. from .blocks import BaseStreamBlock
  21. from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
  22. @register_snippet
  23. class People(ClusterableModel):
  24. first_name = models.CharField("First name", max_length=254)
  25. last_name = models.CharField("Last name", max_length=254)
  26. job_title = models.CharField("Job title", max_length=254)
  27. image = models.ForeignKey(
  28. 'wagtailimages.Image',
  29. null=True,
  30. blank=True,
  31. on_delete=models.SET_NULL,
  32. related_name='+'
  33. )
  34. panels = [
  35. FieldPanel('first_name', classname="col6"),
  36. FieldPanel('last_name', classname="col6"),
  37. FieldPanel('job_title'),
  38. ImageChooserPanel('image')
  39. ]
  40. def __str__(self):
  41. return self.first_name + " " + self.last_name
  42. class Meta:
  43. verbose_name = 'Person'
  44. verbose_name_plural = 'People'
  45. class AboutLocationRelationship(Orderable, models.Model):
  46. """
  47. This defines the relationship between the `LocationPage` within the `locations`
  48. app and the About page below allowing us to add locations to the about
  49. section.
  50. """
  51. page = ParentalKey(
  52. 'AboutPage', related_name='location_about_relationship'
  53. )
  54. locations = models.ForeignKey(
  55. 'locations.LocationPage', related_name='about_location_relationship'
  56. )
  57. panels = [
  58. PageChooserPanel('locations')
  59. ]
  60. class AboutPage(Page):
  61. """
  62. The About Page
  63. """
  64. image = models.ForeignKey(
  65. 'wagtailimages.Image',
  66. null=True,
  67. blank=True,
  68. on_delete=models.SET_NULL,
  69. related_name='+',
  70. help_text='Location image'
  71. )
  72. body = StreamField(
  73. BaseStreamBlock(), verbose_name="About page detail", blank=True
  74. )
  75. # We've defined the StreamBlock() within blocks.py that we've imported on
  76. # line 12. Defining it in a different file gives us consistency across the
  77. # site, though StreamFields _can_ be created on a per model basis if you
  78. # have a use case for it
  79. content_panels = Page.content_panels + [
  80. ImageChooserPanel('image'),
  81. StreamFieldPanel('body'),
  82. InlinePanel(
  83. 'location_about_relationship',
  84. label='Locations',
  85. min_num=None
  86. ),
  87. ]
  88. # parent_page_types = [
  89. # 'home.HomePage'
  90. # ]
  91. # Defining what content type can sit under the parent
  92. # The empty array means that no children can be placed under the
  93. # LocationPage page model
  94. subpage_types = []
  95. # api_fields = ['image', 'body']
  96. class GalleryPage(Page):
  97. """
  98. This is a page to list all the locations on the site
  99. """
  100. choices = models.ForeignKey(
  101. Collection,
  102. limit_choices_to=~models.Q(name__in=['Root']),
  103. null=True,
  104. blank=True,
  105. on_delete=models.SET_NULL,
  106. )
  107. image = models.ForeignKey(
  108. 'wagtailimages.Image',
  109. null=True,
  110. blank=True,
  111. on_delete=models.SET_NULL,
  112. related_name='+',
  113. help_text='Location listing image'
  114. )
  115. introduction = models.TextField(
  116. help_text='Text to describe the index page',
  117. blank=True)
  118. content_panels = Page.content_panels + [
  119. FieldPanel('choices'),
  120. ImageChooserPanel('image'),
  121. FieldPanel('introduction')
  122. ]
  123. # parent_page_types = [
  124. # 'home.HomePage'
  125. # ]
  126. # Defining what content type can sit under the parent. Since it's a blank
  127. # array no subpage can be added
  128. subpage_types = [
  129. ]
  130. # api_fields = ['introduction']
  131. class FormField(AbstractFormField):
  132. page = ParentalKey('FormPage', related_name='form_fields')
  133. class FormPage(AbstractEmailForm):
  134. header_image = models.ForeignKey(
  135. 'wagtailimages.Image',
  136. null=True,
  137. blank=True,
  138. on_delete=models.SET_NULL,
  139. related_name='+'
  140. )
  141. body = StreamField(BaseStreamBlock())
  142. thank_you_text = RichTextField(blank=True)
  143. content_panels = AbstractEmailForm.content_panels + [
  144. ImageChooserPanel('header_image'),
  145. StreamFieldPanel('body'),
  146. InlinePanel('form_fields', label="Form fields"),
  147. FieldPanel('thank_you_text', classname="full"),
  148. MultiFieldPanel([
  149. FieldRowPanel([
  150. FieldPanel('from_address', classname="col6"),
  151. FieldPanel('to_address', classname="col6"),
  152. ]),
  153. FieldPanel('subject'),
  154. ], "Email"),
  155. ]