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):
|
||||
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
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
{% block title %}{% trans 'Edit' %} {{form.instance}}{% endblock %}
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
{% else %}
|
||||
<div class="formfield {{field.name}}{% if field.errors %} error{% endif %}" id="formfield_{{field.html_name}}">
|
||||
<div class="errors">
|
||||
{{field.errors}}
|
||||
</div>
|
||||
|
||||
{% if field.errors %}
|
||||
<div class="errors">
|
||||
{{field.errors}}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if field.field.widget.input_type == 'checkbox' %}
|
||||
<div class="input">
|
||||
|
@ -19,8 +22,10 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="helptext">
|
||||
{{field.help_text}}
|
||||
</div>
|
||||
{% if field.help_text %}
|
||||
<div class="helptext">
|
||||
{{field.help_text}}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% 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.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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,15 +1,79 @@
|
|||
{% extends 'cms/base.html' %}
|
||||
{% load static %}
|
||||
{% load static i18n %}
|
||||
{% 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 %}
|
||||
<link rel="stylesheet" href="{% static 'hamburgers.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'main1.scss.css' %}">
|
||||
{% endblock %}
|
||||
<header>
|
||||
{% block header %}
|
||||
<h1><a href="/">Awesome Website</a></h1>
|
||||
{% endblock %}
|
||||
</header>
|
||||
|
||||
{% block header %}
|
||||
<div class="wrapper">
|
||||
<h1><a href="/">Awesome Website</a></h1>
|
||||
</div>
|
||||
{% endblock %}
|
||||
<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 %}
|
||||
<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.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')),
|
||||
|
|
7
setup.py
7
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',
|
||||
],
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue