models.py 5.6 KB

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