New template tag: {% edit %} which generates a simple edit link for the

current section
main
Jaap Joris Vens 2020-03-21 20:24:07 +01:00
rodzic 3cc1f9ec08
commit 98b1a61af1
16 zmienionych plików z 65 dodań i 72 usunięć

Wyświetl plik

@ -1,2 +0,0 @@
/*# sourceMappingURL=cms.scss.css.map */

Wyświetl plik

@ -1,9 +0,0 @@
{
"version": 3,
"file": "cms.css",
"sources": [
"cms.scss"
],
"names": [],
"mappings": ""
}

Wyświetl plik

@ -7,8 +7,6 @@
<title>{% block title %}{% endblock %}</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{% static 'cms/cms.scss.css' %}">
<link rel="stylesheet" href="{% static 'cms/hamburgers.css' %}">
<link rel="icon" href="{% static 'favicon.png' %}">
{% block extrahead %}{% endblock %}
</head>

Wyświetl plik

@ -5,6 +5,7 @@
{% block content %}
{% for section in sections %}
<div id="{{section.title|slugify}}"></div>
{% include_section section %}
{% endfor %}

Wyświetl plik

@ -1,12 +1,40 @@
from django import template
from markdown import markdown as md
from django import template
from django.shortcuts import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
MARKDOWN_EXTENSIONS = ['extra', 'smarty']
register = template.Library()
@register.simple_tag(takes_context=True)
def eval(context, expr):
'''USE WITH CAUTION!!!
This template tag runs its argument through Django's templating
system using the current context, placing all power into the
hands of the content editors.
Also, it applies Markdown.
'''
result = template.Template(expr).render(context)
return mark_safe(md(result, extensions=MARKDOWN_EXTENSIONS))
@register.simple_tag(takes_context=True)
def edit(context):
'''Renders a simple link to edit the current section'''
if context['request'].user.has_perms('cms_section_change'):
slug = context['section'].page.slug
number = context['section'].number
url = reverse('cms:updatesection', args=[slug, number]) if slug else reverse('cms:updatesection', args=[number])
return mark_safe(f'<a class="edit" href="{url}">{_("edit")}</a>')
return ''
@register.tag('include_section')
def do_include(parser, token):
'''Renders the section with its own context
'''
'''Renders the section with its own context'''
_, section = token.split_contents()
return IncludeSectionNode(section)

Wyświetl plik

@ -1,20 +0,0 @@
from markdown import markdown as md
from django import template
from django.utils.safestring import mark_safe
MARKDOWN_EXTENSIONS = ['extra', 'smarty']
register = template.Library()
@register.simple_tag(takes_context=True)
def eval(context, expr):
'''USE WITH CAUTION!!!
This template tag runs its argument through Django's templating
system using the current context, placing all power into the
hands of the content editors.
Also, it applies Markdown.
'''
result = template.Template(expr).render(context)
return mark_safe(md(result, extensions=MARKDOWN_EXTENSIONS))

Wyświetl plik

@ -22,7 +22,7 @@ a {
a.button, button.button {
cursor: pointer;
font-family: $titlefont
font-family: $titlefont;
font-size: 1.5em;
line-height: 1.25;
border-radius: 5px;
@ -60,7 +60,7 @@ a.edit {
section a.edit {
position: absolute;
bottom: 0;
right: 1em;
left: 1em;
}
table {
@ -199,16 +199,8 @@ div.edit {
right: 1em;
bottom: 1em;
z-index: 1000;
button {
padding: 0;
outline: none;
background: none;
border: none;
}
img {
width: 75px;
height: auto;
}
}

Wyświetl plik

@ -10,6 +10,24 @@ a {
a:hover {
text-decoration: underline; }
a.button, button.button {
cursor: pointer;
font-family: sans-serif;
font-size: 1.5em;
line-height: 1.25;
border-radius: 5px;
display: inline-block;
text-decoration: none;
border: none;
padding: 5px 20px;
background: #3573a8;
color: white;
box-sizing: border-box; }
a.button:hover, button.button:hover {
color: #3573a8;
background: white;
box-shadow: inset 0 0 0 2px #3573a8; }
h1, h2, h3, h4, h5, h6 {
margin: .5em 0;
font-family: sans-serif; }
@ -39,7 +57,7 @@ a.edit {
section a.edit {
position: absolute;
bottom: 0;
right: 1em; }
left: 1em; }
table {
border-collapse: collapse; }
@ -145,14 +163,8 @@ div.edit {
right: 1em;
bottom: 1em;
z-index: 1000; }
div.edit button {
padding: 0;
outline: none;
background: none;
border: none; }
div.edit img {
width: 75px;
height: auto; }
width: 75px; }
section {
clear: both;

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -1,4 +1,4 @@
{% load i18n %}
{% load i18n cms %}
<section class="contact">
<div class="wrapper">
<div class="title">
@ -16,7 +16,5 @@
</div>
</div>
{% if perms.cms_section_change %}
<a class="edit" href="{% url 'cms:updatesection' section.number %}">{% trans 'edit' %}</a><br>
{% endif %}
{% edit %}
</section>

Wyświetl plik

@ -1,4 +1,4 @@
{% load thumbnail i18n %}
{% load thumbnail i18n cms %}
<section class="images">
<div class="images">
@ -9,7 +9,5 @@
{% endfor %}
</div>
{% if perms.cms_section_change %}
<a class="edit" href="{% url 'cms:updatesection' section.number %}">{% trans 'edit' %}</a><br>
{% endif %}
{% edit %}
</section>

Wyświetl plik

@ -1,4 +1,4 @@
{% load eval i18n %}
{% load i18n cms %}
<section class="text">
<div class="wrapper">
@ -13,7 +13,5 @@
</div>
</div>
{% if perms.cms_section_change %}
<a class="edit" href="{% url 'cms:updatesection' section.number %}">{% trans 'edit' %}</a><br>
{% endif %}
{% edit %}
</section>

Wyświetl plik

@ -1,4 +1,4 @@
{% load embed_video_tags i18n %}
{% load embed_video_tags i18n cms %}
<section class="video">
{% if section.video %}
@ -9,7 +9,5 @@
</div>
{% endif %}
{% if perms.cms_section_change %}
<a class="edit" href="{% url 'cms:updatesection' section.number %}">{% trans 'edit' %}</a><br>
{% endif %}
{% edit %}
</section>

Wyświetl plik

@ -4,6 +4,7 @@
{% block title %}Awesome Website{% endblock %}
{% block extrahead %}
<link rel="stylesheet" href="{% static 'app/hamburgers.css' %}">
<link rel="stylesheet" href="{% static 'app/main1.scss.css' %}">
{% endblock %}