models.py 3.9 KB

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