Browse Source

Updating to wagtail-cache 0.4 to fix caching issues (#108)

Vince Salvino 6 years ago
parent
commit
e01040aff4
2 changed files with 17 additions and 4 deletions
  1. 15 3
      coderedcms/models/page_models.py
  2. 2 1
      setup.py

+ 15 - 3
coderedcms/models/page_models.py

@@ -46,6 +46,7 @@ from wagtail.contrib.forms.forms import WagtailAdminFormPageForm
 from wagtail.images.edit_handlers import ImageChooserPanel
 from wagtail.images.edit_handlers import ImageChooserPanel
 from wagtail.contrib.forms.models import FormSubmission
 from wagtail.contrib.forms.models import FormSubmission
 from wagtail.search import index
 from wagtail.search import index
+from wagtailcache.cache import WagtailCacheMixin
 
 
 from coderedcms import schema, utils
 from coderedcms import schema, utils
 from coderedcms.blocks import (
 from coderedcms.blocks import (
@@ -90,13 +91,14 @@ class CoderedTag(TaggedItemBase):
         verbose_name = _('CodeRed Tag')
         verbose_name = _('CodeRed Tag')
     content_object = ParentalKey('coderedcms.CoderedPage', related_name='tagged_items')
     content_object = ParentalKey('coderedcms.CoderedPage', related_name='tagged_items')
 
 
-class CoderedPage(Page, metaclass=CoderedPageMeta):
+class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
     """
     """
     General use page with caching, templating, and SEO functionality.
     General use page with caching, templating, and SEO functionality.
     All pages should inherit from this.
     All pages should inherit from this.
     """
     """
     class Meta:
     class Meta:
         verbose_name = _('CodeRed Page')
         verbose_name = _('CodeRed Page')
+
     # Do not allow this page type to be created in wagtail admin
     # Do not allow this page type to be created in wagtail admin
     is_creatable = False
     is_creatable = False
 
 
@@ -108,9 +110,11 @@ class CoderedPage(Page, metaclass=CoderedPageMeta):
     # ajax_template = ''
     # ajax_template = ''
     # search_template = ''
     # search_template = ''
 
 
+
     ###############
     ###############
     # Content fields
     # Content fields
     ###############
     ###############
+
     cover_image = models.ForeignKey(
     cover_image = models.ForeignKey(
         'wagtailimages.Image',
         'wagtailimages.Image',
         null=True,
         null=True,
@@ -120,6 +124,7 @@ class CoderedPage(Page, metaclass=CoderedPageMeta):
         verbose_name=_('Cover image'),
         verbose_name=_('Cover image'),
     )
     )
 
 
+
     ###############
     ###############
     # Index fields
     # Index fields
     ###############
     ###############
@@ -165,6 +170,7 @@ class CoderedPage(Page, metaclass=CoderedPageMeta):
         help_text=_('Used to categorize your pages.')
         help_text=_('Used to categorize your pages.')
     )
     )
 
 
+
     ###############
     ###############
     # Layout fields
     # Layout fields
     ###############
     ###############
@@ -1242,11 +1248,14 @@ class CoderedFormPage(CoderedWebPage):
 
 
         context = self.get_context(request)
         context = self.get_context(request)
         context['form_submission'] = form_submission
         context['form_submission'] = form_submission
-        return render(
+        response = render(
             request,
             request,
             self.get_landing_page_template(request),
             self.get_landing_page_template(request),
             context
             context
         )
         )
+        # Never cache form landing response, due to content changing with same URL.
+        response['Cache-Control'] = 'no-cache'
+        return response
 
 
     def serve_submissions_list_view(self, request, *args, **kwargs):
     def serve_submissions_list_view(self, request, *args, **kwargs):
         """
         """
@@ -1270,11 +1279,14 @@ class CoderedFormPage(CoderedWebPage):
 
 
         context = self.get_context(request)
         context = self.get_context(request)
         context['form'] = form
         context['form'] = form
-        return render(
+        response = render(
             request,
             request,
             self.get_template(request),
             self.get_template(request),
             context
             context
         )
         )
+        # Never cache form pages, due to content changing with same URL, and CSRF token.
+        response['Cache-Control'] = 'no-cache'
+        return response
 
 
     preview_modes = [
     preview_modes = [
         ('form', _('Form')),
         ('form', _('Form')),

+ 2 - 1
setup.py

@@ -47,7 +47,7 @@ setup(
         'icalendar==4.0.*',
         'icalendar==4.0.*',
         'wagtail==2.4.*',
         'wagtail==2.4.*',
         'wagtailfontawesome>=1.1.3,<2.0',
         'wagtailfontawesome>=1.1.3,<2.0',
-        'wagtail-cache==0.3.*',
+        'wagtail-cache==0.4.*',
         'wagtail-import-export>=0.1,<0.2'
         'wagtail-import-export>=0.1,<0.2'
     ],
     ],
     extras_require={
     extras_require={
@@ -55,6 +55,7 @@ setup(
             'pylint-django',
             'pylint-django',
             'sphinx',
             'sphinx',
             'twine',
             'twine',
+            'wheel'
         ]
         ]
     },
     },
     entry_points="""
     entry_points="""