kopia lustrzana https://github.com/rtts/django-simplecms
Updated example project with cache settings. Also, deleted frontend
templates from cms app.main
rodzic
a9b4d5dfb3
commit
ab9dc1621f
|
@ -19,17 +19,17 @@ class SassMiddleware:
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
if settings.DEBUG and request.path.endswith('.css'):
|
if settings.DEBUG and request.path.endswith('.css'):
|
||||||
css_file = request.path.rsplit('/',1)[1]
|
css_file = request.path.rsplit('/',1)[1]
|
||||||
css_path = locate(css_file)
|
sass_file = css_file[:-4]
|
||||||
if css_path:
|
sass_path = locate(sass_file)
|
||||||
sass_path = css_path[:-4]
|
if sass_path and os.path.exists(sass_path):
|
||||||
|
css_path = sass_path + '.css'
|
||||||
map_path = css_path + '.map'
|
map_path = css_path + '.map'
|
||||||
if os.path.exists(sass_path):
|
css = compile(filename=sass_path, output_style='nested')
|
||||||
css = compile(filename=sass_path, output_style='nested')
|
css, mapping = compile(filename=sass_path, source_map_filename=map_path)
|
||||||
css, mapping = compile(filename=sass_path, source_map_filename=map_path)
|
with open(css_path, 'w') as f:
|
||||||
with open(css_path, 'w') as f:
|
f.write(css)
|
||||||
f.write(css)
|
with open(map_path, 'w') as f:
|
||||||
with open(map_path, 'w') as f:
|
f.write(mapping)
|
||||||
f.write(mapping)
|
|
||||||
|
|
||||||
response = self.get_response(request)
|
response = self.get_response(request)
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
{% extends 'cms/admin.html' %}
|
|
|
@ -1 +0,0 @@
|
||||||
{% extends 'cms/base.html' %}
|
|
|
@ -1,80 +0,0 @@
|
||||||
{% load static i18n %}
|
|
||||||
{% get_current_language as lang%}
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="{{lang}}">
|
|
||||||
<head>
|
|
||||||
<title>{% block title %}{% endblock %}</title>
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<link rel="icon" href="{% static 'favicon.png' %}">
|
|
||||||
{% block extrahead %}{% endblock %}
|
|
||||||
</head>
|
|
||||||
<body class="{% block bodyclass %}{% endblock %}">
|
|
||||||
|
|
||||||
<main>
|
|
||||||
{% block main %}
|
|
||||||
|
|
||||||
<header>
|
|
||||||
{% block header %}
|
|
||||||
{% endblock %}
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<nav>
|
|
||||||
{% block nav %}
|
|
||||||
{% if pages %}
|
|
||||||
<ul id="menu">
|
|
||||||
{% for p in pages %}
|
|
||||||
<li><a href="{% if p.slug %}{% url 'cms:page' p.slug %}{% else %}{% url 'cms:page' %}{% endif %}" {% if p.pk == page.pk %}class="current"{% endif %}>{{p.title}}</a></li>
|
|
||||||
{% endfor %}
|
|
||||||
{% if perms.cms_page_create %}
|
|
||||||
<li><a class="edit" href="{% url 'cms:createpage' %}">+ {% trans 'new page' %}</a></li>
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
|
||||||
{% endif %}
|
|
||||||
<button class="hamburger hamburger--collapse" id='hamburger'>
|
|
||||||
<span class="hamburger-box">
|
|
||||||
<span class="hamburger-inner"></span>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
{% endblock %}
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<article>
|
|
||||||
{% block content %}
|
|
||||||
{% endblock %}
|
|
||||||
</article>
|
|
||||||
|
|
||||||
<footer>
|
|
||||||
{% block footer %}
|
|
||||||
{% endblock %}
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
document.addEventListener("DOMContentLoaded", function(event) {
|
|
||||||
var hamburger = document.getElementById('hamburger');
|
|
||||||
var menu = document.getElementById('menu');
|
|
||||||
hamburger.addEventListener('click', function(e) {
|
|
||||||
hamburger.classList.toggle('is-active');
|
|
||||||
menu.classList.toggle('visible');
|
|
||||||
});
|
|
||||||
|
|
||||||
var links = document.querySelectorAll('a');
|
|
||||||
for (var link of links) {
|
|
||||||
var a = new RegExp('/' + window.location.host + '/');
|
|
||||||
if (!a.test(link.href)) {
|
|
||||||
link.addEventListener('click', function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
window.open(this.href, '_blank');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% block extrabody %}{% endblock %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends 'admin.html' %}
|
{% extends 'cms/admin.html' %}
|
||||||
{% load static i18n %}
|
{% load static i18n %}
|
||||||
|
|
||||||
{% block title %}{% trans 'Edit' %} {{form.instance}}{% endblock %}
|
{% block title %}{% trans 'Edit' %} {{form.instance}}{% endblock %}
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="formfield {{field.name}}{% if field.errors %} error{% endif %}" id="formfield_{{field.html_name}}">
|
<div class="formfield {{field.name}}{% if field.errors %} error{% endif %}" id="formfield_{{field.html_name}}">
|
||||||
<div class="errors">
|
|
||||||
{{field.errors}}
|
{% if field.errors %}
|
||||||
</div>
|
<div class="errors">
|
||||||
|
{{field.errors}}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if field.field.widget.input_type == 'checkbox' %}
|
{% if field.field.widget.input_type == 'checkbox' %}
|
||||||
<div class="input">
|
<div class="input">
|
||||||
|
@ -19,8 +22,10 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="helptext">
|
{% if field.help_text %}
|
||||||
{{field.help_text}}
|
<div class="helptext">
|
||||||
</div>
|
{{field.help_text}}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
{% load i18n thumbnail embed_video_tags %}
|
|
||||||
{% load markdown %}
|
|
||||||
|
|
||||||
<section class="{{section.type}} color{{section.color}}">
|
|
||||||
<div class="wrapper">
|
|
||||||
|
|
||||||
{% if section.image %}
|
|
||||||
<div class="image">
|
|
||||||
<img alt="{{section.title}}" src="{% thumbnail section.image 800x800 %}">
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if section.title %}
|
|
||||||
<div class="title">
|
|
||||||
<h1>
|
|
||||||
{{section.title}}
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if section.content %}
|
|
||||||
<div class="content">
|
|
||||||
{{section.content|markdown}}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if section.video %}
|
|
||||||
<div class="video">
|
|
||||||
<div class="iframe">
|
|
||||||
{% video section.video '800x600' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if section.button_text %}
|
|
||||||
<div class="button">
|
|
||||||
<a class="button" href="{{section.button_link}}">{{section.button_text}}</a>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if request.user.is_staff %}
|
|
||||||
<a class="edit" href="edit/{{section.number}}/">{% trans 'edit' %}</a>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</section>
|
|
|
@ -2,6 +2,8 @@ import json
|
||||||
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.views.generic import base, detail, edit
|
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.contrib.auth.mixins import UserPassesTestMixin
|
||||||
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
|
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
|
||||||
|
|
||||||
|
@ -93,6 +95,7 @@ class PageView(detail.DetailView):
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@method_decorator(never_cache, name='dispatch')
|
||||||
class EditPage(UserPassesTestMixin, edit.ModelFormMixin, base.TemplateResponseMixin, base.View):
|
class EditPage(UserPassesTestMixin, edit.ModelFormMixin, base.TemplateResponseMixin, base.View):
|
||||||
'''Base view with nested forms for editing the page and all its sections'''
|
'''Base view with nested forms for editing the page and all its sections'''
|
||||||
model = registry.page_class
|
model = registry.page_class
|
||||||
|
@ -148,6 +151,7 @@ class CreatePage(EditPage):
|
||||||
class UpdatePage(EditPage):
|
class UpdatePage(EditPage):
|
||||||
'''View for editing existing pages'''
|
'''View for editing existing pages'''
|
||||||
|
|
||||||
|
@method_decorator(never_cache, name='dispatch')
|
||||||
class EditSection(UserPassesTestMixin, edit.ModelFormMixin, base.TemplateResponseMixin, base.View):
|
class EditSection(UserPassesTestMixin, edit.ModelFormMixin, base.TemplateResponseMixin, base.View):
|
||||||
model = registry.section_class
|
model = registry.section_class
|
||||||
form_class = SectionForm
|
form_class = SectionForm
|
||||||
|
|
|
@ -83,3 +83,12 @@ DATABASES = {
|
||||||
'NAME': PROJECT_NAME,
|
'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
|
||||||
|
|
|
@ -1,15 +1,79 @@
|
||||||
{% extends 'cms/base.html' %}
|
{% load static i18n %}
|
||||||
{% load static %}
|
{% get_current_language as lang%}
|
||||||
|
|
||||||
{% block title %}Awesome Website{% endblock %}
|
<!DOCTYPE html>
|
||||||
|
<html lang="{{lang}}">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="icon" href="{% static 'favicon.png' %}">
|
||||||
|
<link rel="stylesheet" href="{% static 'main1.scss.css' %}">
|
||||||
|
<link rel="stylesheet" href="{% static 'hamburgers.css' %}">
|
||||||
|
<title>{% block title %}Awesome Website{% endblock %}</title>
|
||||||
|
{% block extrahead %}{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
{% block extrahead %}
|
<header>
|
||||||
<link rel="stylesheet" href="{% static 'hamburgers.css' %}">
|
{% block header %}
|
||||||
<link rel="stylesheet" href="{% static 'main1.scss.css' %}">
|
<h1><a href="/">Awesome Website</a></h1>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
</header>
|
||||||
|
|
||||||
{% block header %}
|
<nav>
|
||||||
<div class="wrapper">
|
{% block nav %}
|
||||||
<h1><a href="/">Awesome Website</a></h1>
|
{% if pages %}
|
||||||
</div>
|
<ul id="menu">
|
||||||
{% endblock %}
|
{% for p in pages %}
|
||||||
|
<li><a href="{% if p.slug %}{% url 'cms:page' p.slug %}{% else %}{% url 'cms:page' %}{% endif %}" {% if p.pk == page.pk %}class="current"{% endif %}>{{p.title}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
{% if perms.cms_page_create %}
|
||||||
|
<li><a class="edit" href="{% url 'cms:createpage' %}">+ {% trans 'new page' %}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
<button class="hamburger hamburger--collapse" id='hamburger'>
|
||||||
|
<span class="hamburger-box">
|
||||||
|
<span class="hamburger-inner"></span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
{% endblock %}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<article>
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
{% block footer %}
|
||||||
|
{% endblock %}
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function(event) {
|
||||||
|
var hamburger = document.getElementById('hamburger');
|
||||||
|
var menu = document.getElementById('menu');
|
||||||
|
hamburger.addEventListener('click', function(e) {
|
||||||
|
hamburger.classList.toggle('is-active');
|
||||||
|
menu.classList.toggle('visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
var links = document.querySelectorAll('a');
|
||||||
|
for (var link of links) {
|
||||||
|
var a = new RegExp('/' + window.location.host + '/');
|
||||||
|
if (!a.test(link.href)) {
|
||||||
|
link.addEventListener('click', function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
window.open(this.href, '_blank');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% block extrabody %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from django.contrib import admin
|
|
||||||
from django.conf.urls.static import static
|
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.views.generic import RedirectView
|
||||||
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
|
|
||||||
admin.site.site_header = settings.PROJECT_NAME.capitalize()
|
admin.site.site_header = settings.PROJECT_NAME.capitalize()
|
||||||
admin.site.site_title = settings.PROJECT_NAME.capitalize()
|
admin.site.site_title = settings.PROJECT_NAME.capitalize()
|
||||||
|
urlpatterns = staticfiles_urlpatterns() + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
urlpatterns = []
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
urlpatterns += staticfiles_urlpatterns()
|
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
|
||||||
|
|
||||||
urlpatterns += [
|
urlpatterns += [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('accounts/', include('django.contrib.auth.urls')),
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
|
|
7
setup.py
7
setup.py
|
@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = 'django-simplecms',
|
name = 'django-simplecms',
|
||||||
version = '1.0.0',
|
version = '1.0.1',
|
||||||
url = 'https://github.com/rtts/django-simplecms',
|
url = 'https://github.com/rtts/django-simplecms',
|
||||||
author = 'Jaap Joris Vens',
|
author = 'Jaap Joris Vens',
|
||||||
author_email = 'jj@rtts.eu',
|
author_email = 'jj@rtts.eu',
|
||||||
|
@ -16,8 +16,9 @@ setup(
|
||||||
'django-extensions',
|
'django-extensions',
|
||||||
'django-embed-video',
|
'django-embed-video',
|
||||||
'easy-thumbnails',
|
'easy-thumbnails',
|
||||||
'psycopg2',
|
|
||||||
'markdown',
|
|
||||||
'libsass',
|
'libsass',
|
||||||
|
'markdown',
|
||||||
|
'psycopg2',
|
||||||
|
'pylibmc',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Ładowanie…
Reference in New Issue