From ab9dc1621fb9ae0e57b45c5c98bde1a512840739 Mon Sep 17 00:00:00 2001 From: Jaap Joris Vens Date: Tue, 24 Mar 2020 01:15:17 +0100 Subject: [PATCH] Updated example project with cache settings. Also, deleted frontend templates from cms app. --- cms/middleware.py | 20 +++--- cms/templates/admin.html | 1 - cms/templates/base.html | 1 - cms/templates/cms/base.html | 80 ---------------------- cms/templates/cms/edit.html | 2 +- cms/templates/cms/formfield.html | 17 +++-- cms/templates/cms/sections/section.html | 46 ------------- cms/views.py | 4 ++ example/settings.py | 9 +++ example/templates/base.html | 88 +++++++++++++++++++++---- example/urls.py | 13 +--- setup.py | 7 +- 12 files changed, 118 insertions(+), 170 deletions(-) delete mode 100644 cms/templates/admin.html delete mode 100644 cms/templates/base.html delete mode 100644 cms/templates/cms/base.html delete mode 100644 cms/templates/cms/sections/section.html diff --git a/cms/middleware.py b/cms/middleware.py index 4602f6f..0722fc4 100644 --- a/cms/middleware.py +++ b/cms/middleware.py @@ -19,17 +19,17 @@ class SassMiddleware: def __call__(self, request): if settings.DEBUG and request.path.endswith('.css'): css_file = request.path.rsplit('/',1)[1] - css_path = locate(css_file) - if css_path: - sass_path = css_path[:-4] + sass_file = css_file[:-4] + sass_path = locate(sass_file) + if sass_path and os.path.exists(sass_path): + css_path = sass_path + '.css' map_path = css_path + '.map' - if os.path.exists(sass_path): - css = compile(filename=sass_path, output_style='nested') - css, mapping = compile(filename=sass_path, source_map_filename=map_path) - with open(css_path, 'w') as f: - f.write(css) - with open(map_path, 'w') as f: - f.write(mapping) + css = compile(filename=sass_path, output_style='nested') + css, mapping = compile(filename=sass_path, source_map_filename=map_path) + with open(css_path, 'w') as f: + f.write(css) + with open(map_path, 'w') as f: + f.write(mapping) response = self.get_response(request) return response diff --git a/cms/templates/admin.html b/cms/templates/admin.html deleted file mode 100644 index 43aa1b0..0000000 --- a/cms/templates/admin.html +++ /dev/null @@ -1 +0,0 @@ -{% extends 'cms/admin.html' %} diff --git a/cms/templates/base.html b/cms/templates/base.html deleted file mode 100644 index a63cdac..0000000 --- a/cms/templates/base.html +++ /dev/null @@ -1 +0,0 @@ -{% extends 'cms/base.html' %} diff --git a/cms/templates/cms/base.html b/cms/templates/cms/base.html deleted file mode 100644 index dcfcdee..0000000 --- a/cms/templates/cms/base.html +++ /dev/null @@ -1,80 +0,0 @@ -{% load static i18n %} -{% get_current_language as lang%} - - - - - {% block title %}{% endblock %} - - - - {% block extrahead %}{% endblock %} - - - -
- {% block main %} - -
- {% block header %} - {% endblock %} -
- - - -
- {% block content %} - {% endblock %} -
- -
- {% block footer %} - {% endblock %} -
- - {% endblock %} -
- - - {% block extrabody %}{% endblock %} - - diff --git a/cms/templates/cms/edit.html b/cms/templates/cms/edit.html index 632b8e2..6c9c871 100644 --- a/cms/templates/cms/edit.html +++ b/cms/templates/cms/edit.html @@ -1,4 +1,4 @@ -{% extends 'admin.html' %} +{% extends 'cms/admin.html' %} {% load static i18n %} {% block title %}{% trans 'Edit' %} {{form.instance}}{% endblock %} diff --git a/cms/templates/cms/formfield.html b/cms/templates/cms/formfield.html index 0f6da55..0b79fb1 100644 --- a/cms/templates/cms/formfield.html +++ b/cms/templates/cms/formfield.html @@ -2,9 +2,12 @@ {% else %}
-
- {{field.errors}} -
+ + {% if field.errors %} +
+ {{field.errors}} +
+ {% endif %} {% if field.field.widget.input_type == 'checkbox' %}
@@ -19,8 +22,10 @@
{% endif %} -
- {{field.help_text}} -
+ {% if field.help_text %} +
+ {{field.help_text}} +
+ {% endif %}
{% endif %} diff --git a/cms/templates/cms/sections/section.html b/cms/templates/cms/sections/section.html deleted file mode 100644 index 34f1aee..0000000 --- a/cms/templates/cms/sections/section.html +++ /dev/null @@ -1,46 +0,0 @@ -{% load i18n thumbnail embed_video_tags %} -{% load markdown %} - -
-
- - {% if section.image %} -
- {{section.title}} -
- {% endif %} - - {% if section.title %} -
-

- {{section.title}} -

-
- {% endif %} - - {% if section.content %} -
- {{section.content|markdown}} -
- {% endif %} - - {% if section.video %} -
-
- {% video section.video '800x600' %} -
-
- {% endif %} - - {% if section.button_text %} - - {% endif %} - - {% if request.user.is_staff %} - {% trans 'edit' %} - {% endif %} - -
-
diff --git a/cms/views.py b/cms/views.py index 54edabd..a33733c 100644 --- a/cms/views.py +++ b/cms/views.py @@ -2,6 +2,8 @@ import json from django.shortcuts import redirect from django.views.generic import base, detail, edit +from django.utils.decorators import method_decorator +from django.views.decorators.cache import never_cache from django.contrib.auth.mixins import UserPassesTestMixin from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseBadRequest @@ -93,6 +95,7 @@ class PageView(detail.DetailView): }) return context +@method_decorator(never_cache, name='dispatch') class EditPage(UserPassesTestMixin, edit.ModelFormMixin, base.TemplateResponseMixin, base.View): '''Base view with nested forms for editing the page and all its sections''' model = registry.page_class @@ -148,6 +151,7 @@ class CreatePage(EditPage): class UpdatePage(EditPage): '''View for editing existing pages''' +@method_decorator(never_cache, name='dispatch') class EditSection(UserPassesTestMixin, edit.ModelFormMixin, base.TemplateResponseMixin, base.View): model = registry.section_class form_class = SectionForm diff --git a/example/settings.py b/example/settings.py index 50ceed2..f24250b 100644 --- a/example/settings.py +++ b/example/settings.py @@ -83,3 +83,12 @@ DATABASES = { 'NAME': PROJECT_NAME, } } +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', + 'LOCATION': '127.0.0.1:11211', + 'KEY_PREFIX': PROJECT_NAME, + } +} +if DEBUG: + CACHE_MIDDLEWARE_SECONDS = 0 diff --git a/example/templates/base.html b/example/templates/base.html index 35770c1..c10f8fa 100644 --- a/example/templates/base.html +++ b/example/templates/base.html @@ -1,15 +1,79 @@ -{% extends 'cms/base.html' %} -{% load static %} +{% load static i18n %} +{% get_current_language as lang%} -{% block title %}Awesome Website{% endblock %} + + + + + + + + + {% block title %}Awesome Website{% endblock %} + {% block extrahead %}{% endblock %} + + + {% block main %} -{% block extrahead %} - - -{% endblock %} +
+ {% block header %} +

Awesome Website

+ {% endblock %} +
-{% block header %} -
-

Awesome Website

-
-{% endblock %} + + +
+ {% block content %} + {% endblock %} +
+ + + + {% endblock %} + + {% block extrabody %}{% endblock %} + + diff --git a/example/urls.py b/example/urls.py index 7607420..03df706 100644 --- a/example/urls.py +++ b/example/urls.py @@ -1,20 +1,13 @@ from django.conf import settings +from django.contrib import admin from django.urls import path, include -from django.contrib import admin from django.conf.urls.static import static -from django.contrib.staticfiles.urls import staticfiles_urlpatterns -from django.contrib import admin from django.views.generic import RedirectView +from django.contrib.staticfiles.urls import staticfiles_urlpatterns admin.site.site_header = settings.PROJECT_NAME.capitalize() admin.site.site_title = settings.PROJECT_NAME.capitalize() - -urlpatterns = [] - -if settings.DEBUG: - urlpatterns += staticfiles_urlpatterns() - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - +urlpatterns = staticfiles_urlpatterns() + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += [ path('admin/', admin.site.urls), path('accounts/', include('django.contrib.auth.urls')), diff --git a/setup.py b/setup.py index 751ba92..36a4081 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup( name = 'django-simplecms', - version = '1.0.0', + version = '1.0.1', url = 'https://github.com/rtts/django-simplecms', author = 'Jaap Joris Vens', author_email = 'jj@rtts.eu', @@ -16,8 +16,9 @@ setup( 'django-extensions', 'django-embed-video', 'easy-thumbnails', - 'psycopg2', - 'markdown', 'libsass', + 'markdown', + 'psycopg2', + 'pylibmc', ], )