models.py 6.1 KB

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