2020-01-02 02:33:41 +00:00
|
|
|
# Django Simple CMS
|
2019-03-27 15:49:14 +00:00
|
|
|
|
2020-03-22 19:23:41 +00:00
|
|
|
***A super simple but very extensible content management system for
|
|
|
|
Django websites.***
|
2019-12-27 13:55:52 +00:00
|
|
|
|
2020-03-22 18:57:48 +00:00
|
|
|
SimpleCMS provides the reusable Django app `cms` which contains
|
|
|
|
everything you need to create websites that can be easily edited by
|
|
|
|
end users.
|
|
|
|
|
|
|
|
## How does it work?
|
|
|
|
|
|
|
|
Contrary to 'regular' Django websites, SimpleCMS allows you to write a
|
|
|
|
view for each *section*, rather than for each *page* on your website.
|
|
|
|
On which pages these sections appear, and in which order, is left to
|
|
|
|
the content editor rather than the programmer. After authenticating,
|
2020-03-22 19:23:41 +00:00
|
|
|
the user can use the "Edit" interface to fill the website with various
|
|
|
|
types of content.
|
2020-03-22 18:57:48 +00:00
|
|
|
|
|
|
|
Here's an example `views.py` of an app using SimpleCMS:
|
|
|
|
|
|
|
|
from cms.views import SectionView
|
|
|
|
from cms.decorators import section_view
|
|
|
|
|
|
|
|
@section_view
|
|
|
|
class HelloWorld(SectionView):
|
|
|
|
verbose_name = 'Hello world section'
|
|
|
|
fields = ['content']
|
|
|
|
template_name = 'hello.html'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super()get_context_data(**kwargs)
|
|
|
|
context['message'] = 'Hello World!'
|
2020-03-22 19:23:41 +00:00
|
|
|
return context
|
2020-03-22 18:57:48 +00:00
|
|
|
|
|
|
|
And here is the contents of `hello.html`:
|
|
|
|
|
|
|
|
<section type="helloworld">
|
|
|
|
<h1>{{message}}</h1>
|
|
|
|
{{section.content}}
|
|
|
|
</section>
|
|
|
|
|
2020-03-22 19:23:41 +00:00
|
|
|
Everytime a section needs to be rendered, SimpleCMS will call the
|
|
|
|
appropriate section view and insert the rendered result into the final
|
|
|
|
rendered page.
|
2020-03-22 18:57:48 +00:00
|
|
|
|
2020-03-22 20:19:12 +00:00
|
|
|
But that's not all! SimpleCMS is easily extendable. You can add custom
|
|
|
|
fields to your Page and Section models. You can even add one-to-many
|
|
|
|
fields by defining new models with a foreign key to the Section model,
|
|
|
|
and the Edit interface will automagically show the user nested
|
|
|
|
formsets to edit the related instances! For a complete example see the
|
|
|
|
included `example` app.
|
|
|
|
|
2020-03-22 18:57:48 +00:00
|
|
|
## The "Edit" Interface
|
|
|
|
|
|
|
|
Somewhat like the Django Admin site, SimpleCMS comes with its own
|
|
|
|
editing environment, albeit much simpler and only suitable for editing
|
|
|
|
pages and sections. After authenticating, the content editor can click
|
|
|
|
the "edit" button on any page of the website to alter, add or
|
|
|
|
rearrange sections.
|
|
|
|
|
|
|
|
For each section, the section type can be selected from a dropdown
|
|
|
|
menu. As you can see in `views.py` above, each section type comes with
|
|
|
|
its own list of editable fields. Client-side javascript will hide/show
|
|
|
|
the relevant fields based on the selected section type. All sections
|
|
|
|
are stored in the same database table.
|
|
|
|
|
|
|
|
## Batteries included!
|
|
|
|
|
2020-07-11 17:09:01 +00:00
|
|
|
SimpleCMS includes a variety of useful template tags, default *Page*
|
|
|
|
and *Section* models, and all the other boilerplate code needed for
|
|
|
|
new projects.
|
2020-03-22 18:57:48 +00:00
|
|
|
|
|
|
|
One notable inclusion is the `eval` template tag. It will pass its
|
|
|
|
argument first through Django's templating system and then through
|
|
|
|
Markdown, making for instance the following possible. (Disclaimer: use
|
|
|
|
with caution!)
|
|
|
|
|
|
|
|
Welcome to **{% now 'Y' %}!**
|
|
|
|
|
|
|
|
Another useful feature is the automatic compilation of `SCSS` files to
|
|
|
|
`CSS` files using a custom middleware.
|
2019-12-27 13:55:52 +00:00
|
|
|
|
2020-01-02 02:33:41 +00:00
|
|
|
## Installation
|
2019-12-27 13:55:52 +00:00
|
|
|
|
2020-01-02 02:33:41 +00:00
|
|
|
Use the provided helper command `simplecms` to quickly setup a new
|
|
|
|
project:
|
2019-12-27 13:55:52 +00:00
|
|
|
|
2020-03-22 18:57:48 +00:00
|
|
|
$ pip install https://github.com/rtts/django-simplecms.git
|
|
|
|
$ simplecms mysite
|
|
|
|
|
|
|
|
After the project files have been created, initialize the database and
|
|
|
|
create a superuser:
|
|
|
|
|
|
|
|
$ cd mysite
|
|
|
|
$ sudo su postgres -c "createuser mysite; createdb -O mysite mysite"
|
|
|
|
$ ./manage.py migrate
|
|
|
|
$ ./manage.py createsuperuser
|
|
|
|
|
|
|
|
Finally, run the development server and visit
|
|
|
|
http://localhost:8000/login/ in your browser to log in!
|
|
|
|
|
|
|
|
$ ./manage.py runserver
|
2020-03-22 19:23:41 +00:00
|
|
|
|
|
|
|
## Getting help or contributing
|
|
|
|
|
2020-07-11 17:09:01 +00:00
|
|
|
I'd love to hear from you! If you have any questions or contributions,
|
|
|
|
don't hesitate to contact me via jj [at] rtts.eu.
|