Django CMS manage placeholder in template pages - django

I would enjoy your help on two points :
First, I am creating some default page's templates like :
"Home.html, work-with-us.html" etc.
My aim is to simplify the work of people who will be in charge of the website. They don't have to learn how to manage plugin inside placeholder.
Thus, I created some placeholder like this , example for "workwithus.html" :
{% extends "base.html" %}
{% load cms_tags staticfiles sekizai_tags menu_tags %}
{% block content %}
<div class="container">
<div class="col-xs-12">
{% placeholder "image-full" %}
</div>
<div class="col-md-12">
{% placeholder "text-platform" %}
</div>
</div>
{% endblock content %}
And I managed the plugins this way :
CMS_PLACEHOLDER_CONF = {
'image-full': {
'plugins': ['FilerImagePlugin'],
'name': gettext("Image full page"),
'default_plugins': [
{
'plugin_type': 'FilerImagePlugin',
'values': {
},
},
],
'limits': {
'global': 1,
'FilerImagePlugin': 1,
},
},
etc
The problem is that, I can't use multiple time the same placeholder in the same template. It would be so nice if, when I make a placeholder "img-full-width" I could be able to call it several times.
Do you have any idea about it ? A way to make it more proper than creating "img-full-2", "img-full-3" etc.
Second question :
Is it possible to add more than one default_plugins ? It really annoy me...
Thank you very much in advance guys !

You can have as many plugins as you like as default_plugins
See http://django-cms.readthedocs.org/en/support-3.0.x/reference/configuration.html#placeholder-default-plugins
You can specify the list of default plugins which will be
automagically added when the placeholder will be created (or
rendered).
If you are annoyed with having to redefine CMS_PLACEHOLDER_CONF for each placeholder, you can always define a common config before the CMS_PLACEHOLDER_CONF block:
img_fullwidth_conf = {
'plugins': ['FilerImagePlugin', 'TextPlugin'],
'name': gettext("Image full page"),
'default_plugins': [
{
'plugin_type': 'FilerImagePlugin',
'values': {
},
},
{
'plugin_type': 'TextPlugin',
'values': {
'body': '<p>Write here...</p>'
},
},
],
}
CMS_PLACEHOLDER_CONF = {
'img-full-1': img_fullwidth_conf,
'img-full-2': img_fullwidth_conf,
'img-full-3': img_fullwidth_conf,
}

Related

How do I change default font of Summernote in Django?

So I'm using django-summernote (I'm using Django ver 3.x), and trying to change the default font in the editor. Here's my code.
(part of) forms.py:
from .models import MyModel
class MyInputForm(forms.ModelForm):
contents = SummernoteTextFormField()
class Meta:
model=MyModel
fields=['contents']
widgets = {
'contents': SummernoteInplaceWidget()
}
(part of) my template :
<form method="post" class="form-group">
{% csrf_token %}
<div class="row">
<div class="col col-8">
{{form.contents|as_crispy_field}}
</div>
</div>
</form>
And in case you need to take a look, (part of) my settings.py
SUMMERNOTE_CONFIG = {
'iframe': True,
'lang' : 'ko-KR',
'summernote': {
'width': '100%',
'height': '400px',
'toolbar': [
['style', ['style',]],
['font', ['fontname', 'fontsize', 'bold', 'italic', 'strikethrough', 'clear',]],
['color', ['forecolor', 'backcolor', ]],
['para', ['ul', 'ol', 'height']],
['insert', ['link']],
['misc', ['picture', 'fullscreen', 'codeview', 'print', 'help', ]],
],
},
'js': (
'/static/summernote-ext-print.js',
),
'js_for_inplace': (
'/static/summernote-ext-print.js',
),
'css': (
'//cdnjs.cloudflare.com/ajax/libs/codemirror/5.40.0/theme/base16-dark.min.css',
),
'css_for_inplace': (
'//cdnjs.cloudflare.com/ajax/libs/codemirror/5.40.0/theme/base16-dark.min.css',
),
'codemirror': {
'theme': 'base16-dark',
'mode': 'htmlmixed',
'lineNumbers': 'true',
},
'lazy': False,
}
SUMMERNOTE_THEME = 'bs4'
X_FRAME_OPTIONS = 'SAMEORIGIN'
I have no idea on how or where to write my code for changing the default font.
I would really appreciate your help. Thanks. :)
There is nothing to do with django-summernote. You need to check and initialize the default font-family in your css style or html file. Also, you probably need to check what to display in the dropdown, check the fontNames option
SUMMERNOTE_CONFIG = {
'summernote': {
'fontNames': [...],
},
}
Adding more fonts to the list can be done by:
SUMMERNOTE_CONFIG = {
'summernote': {
'fontNames': ['Spectral', 'Quicksand'],
'fontNamesIgnoreCheck': ['Spectral', 'Quicksand'],
},
}
Summernote tests for fonts in fontNames before adding them to
dropdown. This is a problem while using web fonts. It’s not easy
picking a nice time to check the availability of web fonts. You can
define a list of web fonts to be ignored with the
fontNamesIgnoreCheck.
Reference: https://summernote.org/deep-dive/#custom-fontnames
You shouldn't worry about that. Copy and paste text in any format in the editor, summernote will accept and adjust.

How to access custom fields in a data.home._children loop

I've added a few custom fields in lib/modules/apostrophe-custom-pages/index.js
Specifically, I've added a field for an excerpt, image Singleton for a cover image and another Singleton that will allow users to define an icon to a page.
This is how these images are defined:
{
name: 'icon',
label: 'Icon',
type: 'singleton',
widgetType: 'apostrophe-images',
options:{
limit: 1,
minSize: [200,200],
aspectRatio: [1,1],
},
controls:{
movable:false
},
image: true
},
{
name: 'coverimg',
label: 'Header Image',
type: 'singleton',
widgetType: 'apostrophe-images',
options:{
limit: 1,
minSize: [400,400],
aspectRatio: [1,1],
},
controls:{
movable:false
},
image: true
}
The cover image and the icon I can retrieve while on the page by using: {% set coverimage = apos.images.first(data.page.coverimg) or null %} ,
however, I can't reach the icon in the navigation under data.home._children like so:
{%- for tab in data.home._children -%}
{%- set iconImg = apos.images.all(tab.icon) %}
{{ apos.log(tab) }}
<li>
<a class="sidebar-main-link
{% if data.page and (apos.pages.isAncestorOf(tab, data.page) or tab._id == data.page._id) %}
active
{% endif %}
" href="{{ tab.slug }}">
<div class="icon" style="
backgroung-image: url('{{ apos.attachments.url(image.attachment, { size: 'full'}) }}') "></div>
{{ tab.title }}
</a>
</li>
{% endfor %}
This returns the standard missing.svg image
There is a new tutorial on the apostrophe documentation site which covers this issue in detail.
The short answer is that you must configure the filters option of the apostrophe-pages module to load related pages with more than just very basic information. For performance reasons, this default behavior is not a bad thing, but asking Apostrophe to load just one widget won't slow things down too much.
// in lib/modules/apostrophe-pages/index.js
module.exports = {
// other configuration, then...
filters: {
ancestors: {
children: {
areas: [ 'thumbnail' ]
}
}
}
};

Ansible and Template file inserting values in to the template

I'm having issues at the moment I have a map of some aws subnets with their routing tables like so ( example output via ansible) :
"subnetwork_route_map": [
{
"route_table_id": "rtb-xxxxxx",
"subnet_id": "subnet-xxxxxx"
},
{
"route_table_id": "rtb-xxxxxx",
"subnet_id": "subnet-xxxxxxx"
},
{
"route_table_id": "rtb-xxxxxx",
"subnet_id": "subnet-xxxxxx"
}
]
I wish to insert these values in to a template file and I thought I could do something like this after seeing a few example:
{% for item in subnetwork_route_map %}
{{ item[1]['subnet_id'] }},{{ item[1]['route_table_id'] }}§
{% endfor %}
how ever i'm getting an error when I try this I get an error from ansible:
fatal: [localhost]: FAILED! => {"failed": true, "msg": "dict object has no element 1"}
subnetwork_route_map is a list of dictionaries, item is an individual dictionary, you don't need the [1] part:
{% for item in subnetwork_route_map %}
{{ item['subnet_id'] }},{{ item['route_table_id'] }}§
{% endfor %}

regex to update symfony render tag signature after update

After symfony update the render tag signature has changed (https://github.com/symfony/symfony/blob/master/UPGRADE-2.2.md):
Before:
{% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %}
After:
{% render controller('BlogBundle:Post:list', { 'limit': 2 }), { 'alt': 'BlogBundle:Post:error' } %}
{# Or: #}
{{ render(controller('BlogBundle:Post:list', { 'limit': 2 }), { 'alt': 'BlogBundle:Post:error'}) }}
I'm looking for a way to modify my calls automatically using some regular expression.
Can anyone help?
replace:
\{% render ([^,%]*?), ([^%]*?)%\}
with:
{% render controller(\1), \2%}

How to get django_hitcount app working with Mezzanine blog

Been trying for several hours now.
I set up according to instructions but I can't get it to count hits on a blog post.
/blog/blog_post_detail.html
{% load .. .. .. hitcount_tags %}
.
.
.
.
{% block blog_post_detail_content %}
<script type="text/javascript">
$(document).ready(function() {
{% get_hit_count_javascript for blog_post %}
});
</script>
{% get_hit_count for blog_post %}
.
.
.
{% endblock %}
And in my urls.py I added:
url(r'^blog/ajax/hit/$', update_hit_count_ajax, name='hitcount_update_ajax'),
Looking at page source in browser the javascript does appear to run.
$(document).ready(function() {
var csrf = $('input[name=csrfmiddlewaretoken]').val();
$.post( '/blog/ajax/hit/',
{ csrfmiddlewaretoken: csrf, hitcount_pk : '1' },
function(data, status) {
if (data.status == 'error') {
// do something for error?
}
},
'json');
});
But it's not counting. So I'm not quite sure why it doesn't count a page hit.
Figured it out. In Mezzanine you have to put custom url patterns above the
("^", include("mezzanine.urls")),
pattern otherwise they will be ignored.