First steps with django cms

29
PYCON UK 2014 FIRST STEPS WITH DJANGO CMS by Iacopo Spalletti @yakkys

Transcript of First steps with django cms

Page 1: First steps with django cms

PYCON UK 2014

FIRST STEPSWITH DJANGO CMS

by

Iacopo Spalletti

@yakkys

Page 2: First steps with django cms

WHO AM I?Founder and Lead developer @NephilaIt

django CMS core developer 

django CMS installer author

Page 3: First steps with django cms

DJANGO CMS

FIRST LOOKBRIEF OVERVIEW OF DJANGO CMS

FEATURESFEEL FREE TO COME TO THE BOOTH OR

AT THE SPRINTS FOR MORE

Page 4: First steps with django cms

WHAT'S DJANGO CMS?'JUST' A CMS FOR DJANGO (APPARENTLY)

With a twist!

Page 5: First steps with django cms

DJANGO CMS

HOW IS DIFFERENT?IT'S LIMITED (BY DESIGN)

YOU CANNOT "EXTEND" A PAGE

Page 6: First steps with django cms

DJANGO CMS

WHY IS THAT?WHY NOT?

WE HAVE DJANGO MODELS!

GOOD DJANGO CITIZEN

 

Page 7: First steps with django cms

DJANGO CMS

CONTRIBUTING FEATURESdjango CMS provides features that your applications

can use

Page 8: First steps with django cms

BASIC CONCEPTSPAGE

PLACEHOLDER

PLUGIN

APPHOOK

FRONTEND EDITOR

Page 9: First steps with django cms

LIVES IN A LIVE AND DRAFT VERSION

DEFINED BY THE TEMPLATE APPLIED TO IT

PAGETHE BUILDING BLOCK OF THE CMS

Page 10: First steps with django cms

PLACEHOLDERACTIVE AREAS WITHIN YOUR PAGES

PLUGIN CONTAINERS

DEFINED IN THE TEMPLATES

JUST A TEMPLATETAG

Page 11: First steps with django cms

PLACEHOLDER

HOW TO DEFINE APLACEHOLDER?

{% placeholder "first_placeholder" %}

Page 12: First steps with django cms

PLACEHOLDER

THERE IS MOREclass MyModel(models.Model):    name = models.CharField(max_length=200)    abstract = models.TextField()    content = PlaceholderField()

Composition, not inheritance

Page 13: First steps with django cms

PLUGINPlaceholder = Container

Plugin = Content

Page 14: First steps with django cms

PLUGIN

WHAT'S A PLUGIN?A content

A bridge towards other Django applications

Page 15: First steps with django cms

PLUGIN

WRITING PLUGIN IS EASYclass MyPlugin(CMSPluginBase):    name = _('My plugin')    render_template = 'myapp/myplugin.html'

Page 16: First steps with django cms

PLUGIN

1. PLUGIN CLASSclass MyPlugin(CMSPluginBase):    name = _('My plugin')    model = MyPluginModel    render_template = 'myapp/myplugin.html'        def render(self, context, instance, placeholder):         newslist = News.objects.all().order_by('­date')         context.update({              'instance': instance,              'news_list': newslist[:instance.posts]         })         return context

Plugin = ModelAdmin + template + get_context_data

Page 17: First steps with django cms

PLUGIN

2. THE PLUGIN MODELIt's the plugin configuration

class MyPluginModel(CMSPlugin):     title = models.CharField(max_length=200)     posts = models.PositiveIntegerField()

Page 18: First steps with django cms

PLUGIN

3. THE TEMPLATETemplate is a standard Django template fragment to

which the plugin generated context is provided

<div class="news_list"><h2>{{ instance.title }}</h2>    {% for news in news_list %}        <a href="{{ news.get_absolute_url }}">             {{ news.title }}</a><br>    {% endfor %}</div>

Page 19: First steps with django cms

APPHOOKIs a bridge between the CMS and other Django

applications

In rough terms, it appends the application URLConf to

the page tree

Page 20: First steps with django cms

It wraps the URLCon in a class

APPHOOK

SOME CODEclass MyApp(CMSApp):    name = _("My App")    urls = ["apps.my_app.urls"]    menus = [MyMenu]

apphook_pool.register(MyApp)

Page 21: First steps with django cms

APPHOOK

THAT'S ALL :)

Page 22: First steps with django cms

FRONTEND EDITORWARNING!

IT'S ADDICTIVE!

Page 23: First steps with django cms

FRONTEND EDITOR

WHAT'S IT?NEW IN DJANGO CMS 3

ADMIN OUTSIDE THE ADMIN

Page 24: First steps with django cms

FRONTEND EDITOR

FOLLOW THE WHITE PONY

Page 25: First steps with django cms

FRONTEND EDITOR

TOOLBARCOMPLETE

SIMPLE

DYNAMIC

CUSTOMIZABLE

Page 26: First steps with django cms

FRONTEND EDITOR

ANCHE NEI VOSTRI MODELEVERY MODEL CAN BE FRONTEND-ENABLED

{% render_model instance "abstract" %}

{% render_model_block instance %}<h3>{{ instance.title }}</h3><div class="date">{{ instance.date }}</{% endrender_model_block %}

Page 27: First steps with django cms

SHAMELESS PLUG!

Page 28: First steps with django cms
Page 29: First steps with django cms

GRAZIE!SEE YOU TOMORROW!

DJANGO CMS SPRINT

And tips and support to use django CMS

Iacopo Spalletti

[email protected]

@yakkys