2
0

models.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. """
  2. Create or customize your page models here.
  3. """
  4. from modelcluster.fields import ParentalKey
  5. from wagtailcrx.forms import CoderedFormField
  6. from wagtailcrx.models import (
  7. CoderedArticlePage,
  8. CoderedArticleIndexPage,
  9. CoderedEmail,
  10. CoderedFormPage,
  11. CoderedWebPage
  12. )
  13. from django.db import models
  14. from wagtail.admin.edit_handlers import FieldPanel
  15. from wagtail.core.fields import RichTextField
  16. from wagtail.images import get_image_model_string
  17. from wagtail.images.edit_handlers import ImageChooserPanel
  18. class ArticlePage(CoderedArticlePage):
  19. """
  20. Article, suitable for news or blog content.
  21. """
  22. class Meta:
  23. verbose_name = 'Article'
  24. ordering = ['-first_published_at']
  25. # Only allow this page to be created beneath an ArticleIndexPage.
  26. parent_page_types = ['website.ArticleIndexPage']
  27. template = 'wagtailcrx/pages/article_page.html'
  28. search_template = 'wagtailcrx/pages/article_page.search.html'
  29. class ArticleIndexPage(CoderedArticleIndexPage):
  30. """
  31. Shows a list of article sub-pages.
  32. """
  33. class Meta:
  34. verbose_name = 'Article Landing Page'
  35. # Override to specify custom index ordering choice/default.
  36. index_query_pagemodel = 'website.ArticlePage'
  37. # Only allow ArticlePages beneath this page.
  38. subpage_types = ['website.ArticlePage']
  39. template = 'wagtailcrx/pages/article_index_page.html'
  40. class FormPage(CoderedFormPage):
  41. """
  42. A page with an html <form>.
  43. """
  44. class Meta:
  45. verbose_name = 'Form'
  46. template = 'wagtailcrx/pages/form_page.html'
  47. class FormPageField(CoderedFormField):
  48. """
  49. A field that links to a FormPage.
  50. """
  51. class Meta:
  52. ordering = ['sort_order']
  53. page = ParentalKey('FormPage', related_name='form_fields')
  54. class FormConfirmEmail(CoderedEmail):
  55. """
  56. Sends a confirmation email after submitting a FormPage.
  57. """
  58. page = ParentalKey('FormPage', related_name='confirmation_emails')
  59. class WebPage(CoderedWebPage):
  60. """
  61. General use page with featureful streamfield and SEO attributes.
  62. Template renders all Navbar and Footer snippets in existence.
  63. """
  64. class Meta:
  65. verbose_name = 'Web Page'
  66. template = 'wagtailcrx/pages/web_page.html'
  67. class CupcakesIndexPage(CoderedWebPage):
  68. """
  69. Landing page for Cupcakes
  70. """
  71. class Meta:
  72. verbose_name = "Cupcakes Landing Page"
  73. # Override to specify custom index ordering choice/default.
  74. index_query_pagemodel = 'website.CupcakesPage'
  75. # Only allow CupcakesPages beneath this page.
  76. subpage_types = ['website.CupcakesPage']
  77. template = 'website/pages/cupcakes_index_page.html'
  78. class CupcakesPage(CoderedWebPage):
  79. """
  80. Custom page for individual cupcakes
  81. """
  82. class Meta:
  83. verbose_name = "Cupcakes Page"
  84. # Only allow this page to be created beneath an CupcakesIndexPage.
  85. parent_page_types = ['website.CupcakesIndexPage']
  86. template = "website/pages/cupcakes_page.html"
  87. # The name of the cucpake will be in the page title
  88. description = RichTextField(
  89. verbose_name="Cupcake Description",
  90. null=True,
  91. blank=True,
  92. default=""
  93. )
  94. photo = models.ForeignKey(
  95. get_image_model_string(),
  96. null=True,
  97. blank=True,
  98. on_delete=models.SET_NULL,
  99. related_name='+',
  100. verbose_name='Cupcake Photo',
  101. )
  102. DAYS_CHOICES = (
  103. ("Weekends Only", "Weekends Only"),
  104. ("Monday-Friday", "Monday-Friday"),
  105. ("Tuesday/Thursday", "Tuesday/Thursday"),
  106. ("Seasonal", "Seasonal"),
  107. )
  108. days_available = models.CharField(
  109. choices=DAYS_CHOICES,
  110. max_length=20,
  111. default=""
  112. )
  113. # Add custom fields to the body
  114. body_content_panels = CoderedWebPage.body_content_panels + [
  115. FieldPanel("description"),
  116. FieldPanel("photo"),
  117. FieldPanel("days_available"),
  118. ]