Introduction to Django CMS

58
Django CMS Pim Van Heuven Think Wize (@twPim_)

Transcript of Introduction to Django CMS

Django CMSPim Van Heuven

Think Wize (@twPim_)

Why?• New Think Wize website

• Request to build a website

• Another request to build a website

• And another one …

• Django experience

Building websites• Realistic budget

• Increasing baseline demands:

• Responsive

• Components: text and images, carousel, contact form, map, analytics, newsletter, blog…

• Ability to make small edits

• Build yourself not really effective for most

Contents

• Short introduction to Django CMS

• Making sense of the Django CMS installer

• Plugins

Django CMS

Stack

• Python + relational database + webserver

• Django

• Django admin

• Django CMS

• Content mode (front-end editing)

• Structure mode

• Admin

• Wizards

Website

CMS toolbar

Content mode

double click!

Content mode

Structure mode

Structure mode

Admin

Wizards

Django CMSinstaller

installer

Django CMS installer• https://github.com/nephila/djangocms-installer

• pip install djangocms-installer

• virtualenv projectenv

• source env/bin/activate

• mkdir project

• cd project

• djangocms -f -p . website

Versions

django CMS version (choices: 2.4, 3.0, 3.1, stable,develop) [default stable]: stable

Django version (choices: 1.4, 1.5, 1.6, 1.7, 1.8, stable) [default stable]: stable

Database configurationURLs

Database configuration (in URL format) [default sqlite://localhost/project.db]:

sqlite://localhost/project.db postgres://user:password@host:port/name mysql://user:passwordl@host:port/name

i18n / i10n

• i18n = internationalisation

• translations

• i10n = localisation

• date and number formats

Activate Django I18N / L10N setting (choices: yes, no) [default yes]: yes

Reversion

Install and configure reversion support (choices: yes, no) default yes]: yes

Reversion

• undo / redo changes

• views history

View history…

Languages

Languages to enable. Option can be provided multiple times, or as a comma separated list. Only language codes supported by Django can be used here: nl, en

Optional default time zone [default Europe/Brussels]:Activate Django timezone support (choices: yes, no) [default yes]: yes

Pages

• Usage: manage.py cms copy-lang <lang_from> <lang_to>

• urlpatterns = i18n_patterns('', …

CMS permission management

Activate CMS permission management (choices: yes, no) [default yes]: no

CMS permissions

page global permissions

Page permissions

Bootstrap theme

Use Twitter Bootstrap Theme (choices: yes, no) [default no]: yes

Bootstrap

templates & placeholders

• html pages:

• base.html

• feature.html

• menu.html

• page.htmlCMS_TEMPLATES = ( ## Customize this ('page.html', 'Page'), ('feature.html', 'Page with Feature'))

template

Structure mode

Placeholders

• placeholder

• static placeholder

Placeholders

• cms_template

• placeholders

• plugins

page.html

{% extends "base.html" %}{% load cms_tags %}

{% block title %}{% page_attribute "page_title" %}{% endblock title %}

{% block content %} {% placeholder "content" %}{% endblock content %}

no bootstrap

no bootstrap• templates:

• base.html

• fullwidth.html

• sidebar_left.html

• sidebar_right.html

CMS_TEMPLATES = ( ## Customize this ('fullwidth.html', 'Fullwidth'), ('sidebar_left.html', 'Sidebar Left'), ('sidebar_right.html', 'Sidebar Right'))

sidebar_left.html{% extends "base.html" %}{% load cms_tags %}

{% block title %}{% page_attribute "page_title" %}{ % endblock title %}

{% block content %} <div class="sidebar"> {% placeholder "sidebar" %} </div> <div class="content"> {% placeholder "content" %} </div>{% endblock content %}

Custom template

Use custom template set [default no]: no

(Use custom template set [default no]: ~/djangocms/defaulttemplates/)

Load a starting page with examples after installation (english language only). Choose "no" if you use a custom template set. (choices: yes, no) [default no]: yes

Plugins

Plugins• Must have

• djangocms-admin-style

• djangocms-text-ckeditor

• easy_thumbnails

• django-filer

Plugins• Aldryn

• newsblog

• bootstrap3

• aldryn_people

• aldryn_events

• aldryn_mailchimp

Plugins• taggit, taggit_autosuggest

• testimony

• cmsplugin_contact

• google_analytics

• image_gallery

Advanced topics

apps.py

class CmspluginFilerImageConfig(AppConfig): name = 'cmsplugin_filer_image' verbose_name = "Image sizes"

class FilerConfig(AppConfig): name = 'filer' verbose_name = "Files and images"

aldryn_search• solr

• haystack

• manage.py build_solr_schema

• manage.py rebuild_index

• django cms apphook

cms_wizards.py

newsblog_article_wizard = NewsBlogArticleWizard( title=_(u"New news/blog article"), weight=200, form=CreateNewsBlogArticleForm, description=_(u"Create a new news/blog article."))

wizard_pool.register(newsblog_article_wizard)

templatetag

from django import templateregister = template.Library()

@register.filterdef specialplugin(field): if field in ['TextPlugin', 'FilerImagePlugin', 'LinkPlugin']: return True else: return False

templatetagtemplates/cms/toolbar/dragitem_menu.html

{% for module in module_list %} {% for p in module.list %}

{% if p.value|specialplugin %} <div class="cms-submenu-item">

<a style="background:#dff0d8" data-rel="add" href="{{ p.value }}">{{ p.name }}</a> </div>

{% endif %} {% endfor %}{% endfor %}

Conclusion• Django CMS: The open-source CMS used by

thousands of websites since 2007

• Effective way to build websites whether you need the "content management" part or not

• Values technical quality and usability

• Recommended