2
0

models.py 3.8 KB

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