Skip to content

Commit

Permalink
Update the example application
Browse files Browse the repository at this point in the history
  • Loading branch information
Batiste Bieler committed Jan 16, 2019
1 parent fb611ad commit 912aeaa
Show file tree
Hide file tree
Showing 39 changed files with 565 additions and 332 deletions.
10 changes: 10 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

This file describe new features and incompatibilities between released version of the CMS.


Release 2.0.3
================

Released the 16th of January 2019.

* Update the example application to contain a blog
example application using the delegation.
* Update gerbi command line to contain the blog

Release 2.0.3
================

Expand Down
6 changes: 3 additions & 3 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ A possible solution is to redefine ``settings.LANGUAGES``. For example you can d

# Default language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'en'

# This is defined here as a do-nothing function because we can't import
# django.utils.translation -- that module depends on the settings.
Expand All @@ -127,8 +127,8 @@ A possible solution is to redefine ``settings.LANGUAGES``. For example you can d
# here is all the languages supported by the CMS
PAGE_LANGUAGES = (
('de', gettext_noop('German')),
('fr-ch', gettext_noop('Swiss french')),
('en-us', gettext_noop('US English')),
('fr', gettext_noop('Français')),
('en', gettext_noop('US English')),
)

# copy PAGE_LANGUAGES
Expand Down
10 changes: 5 additions & 5 deletions doc/settings-list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ A list tuples that defines the languages that pages can be translated into::

PAGE_LANGUAGES = (
('zh-cn', gettext_noop('Chinese Simplified')),
('fr-ch', gettext_noop('Swiss french')),
('en-us', gettext_noop('US English')),
('fr', gettext_noop('Français')),
('en', gettext_noop('US English')),
)


Expand All @@ -80,7 +80,7 @@ Defines which language should be used by default. If
``PAGE_DEFAULT_LANGUAGE`` not specified, then project's
``settings.LANGUAGE_CODE`` is used::

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'en'

PAGE_LANGUAGE_MAPPING
==================================
Expand All @@ -104,8 +104,8 @@ Enable that behavior here by assigning the following function to the
# here is all the languages supported by the CMS
PAGE_LANGUAGES = (
('de', gettext_noop('German')),
('fr-fr', gettext_noop('Swiss french')),
('en-us', gettext_noop('US English')),
('fr-fr', gettext_noop('Français')),
('en', gettext_noop('US English')),
)

# copy PAGE_LANGUAGES
Expand Down
Empty file added example/blog/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions example/blog/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf.urls import url
from blog import views
from django.urls import include, path, re_path

urlpatterns = [
url(r'^category/(?P<tag_id>[0-9]+)$', views.category_view, name='blog_category_view'),
url(r'^$', views.blog_index, name='blog_index')
]
31 changes: 31 additions & 0 deletions example/blog/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.shortcuts import render
from pages.models import Page
from taggit.models import Tag
from django.core.paginator import Paginator

def category_view(request, *args, **kwargs):
context = dict(kwargs)
category = Tag.objects.get(id=kwargs['tag_id'])
page = context['current_page']
blogs = page.get_children_for_frontend().filter(tags__name__in=[category.name])

paginator = Paginator(blogs, 8)
page_index = request.GET.get('page')
blogs = paginator.get_page(page_index)
context['blogs'] = blogs

context['category'] = category.name
return render(request, 'blog-home.html', context)

def blog_index(request, *args, **kwargs):
context = dict(kwargs)
page = context['current_page']
blogs = page.get_children_for_frontend()

paginator = Paginator(blogs, 7)
page = request.GET.get('page')
blogs = paginator.get_page(page)
context['blogs'] = blogs
context['template_name'] = 'blog-home.html'

return render(request, 'blog-home.html', context)
16 changes: 13 additions & 3 deletions example/manage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

example_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(example_dir, '..'))

if __name__ == "__main__":
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
79 changes: 23 additions & 56 deletions example/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Django settings for cms project.
# Django settings for CMS project.
import os
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -13,7 +13,6 @@

MANAGERS = ADMINS

# AUTH_PROFILE_MODULE = 'profiles.Profile'
LOGGING_CONFIG = None

DATABASES = {
Expand All @@ -40,15 +39,12 @@
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
MEDIA_URL = '/media/'

# this is for production
STATIC_ROOT = os.path.join(PROJECT_DIR, 'collect-static/')
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# os.path.join(PROJECT_DIR, 'bootstrap'),
os.path.join(PROJECT_DIR, 'static/'),
)

STATICFILES_FINDERS = (
Expand All @@ -59,9 +55,7 @@

FIXTURE_DIRS = [os.path.join(PROJECT_DIR, 'fixtures')]

# Make this unique, and don't share it with anybody.
SECRET_KEY = '*xq7m@)*f2awoj!spa0(jibsrz9%c0d=e(g)v*!17y(vx0ue_3'

SECRET_KEY = 'WARNING: set a proper secure key before going to production'

_TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
Expand Down Expand Up @@ -94,7 +88,7 @@
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'example.urls'
ROOT_URLCONF = 'urls'

CACHES = {
'default': {
Expand All @@ -113,48 +107,54 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
# 'grappelli',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.humanize',
'taggit',
'sorl.thumbnail',
'pages',
'pages.plugins.jsonexport',
'pages.plugins.pofiles',
'mptt',
'rest_framework',
# 'ckeditor', # if commented a fallback widget will be used
'haystack'
'haystack',
'django.contrib.admin',
'django.contrib.sites',
]

PAGE_TAGGING = False
PAGE_TAGGING = True

# Default language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'en'

# This is defined here as a do-nothing function because we can't import
# django.utils.translation -- that module depends on the settings.
gettext_noop = lambda s: s # noqa

# languages you want to translate into the CMS.
PAGE_LANGUAGES = (
('de', gettext_noop('German')),
('fr-ch', gettext_noop('Swiss french')),
('en-us', gettext_noop('US English')),
('en', gettext_noop('English')),
('de', gettext_noop('Deutsch')),
('fr', gettext_noop('Français')),
)

PAGE_USE_LANGUAGE_PREFIX = True

ALLOWED_HOSTS = ['0.0.0.0', '192.168.1.50', '127.0.0.1']

# You should add here all language you want to accept as valid client
# language. By default we copy the PAGE_LANGUAGES constant and add some other
# similar languages.
languages = list(PAGE_LANGUAGES)
languages.append(('fr-fr', gettext_noop('French')))
languages.append(('fr', gettext_noop('Français')))
languages.append(('fr-be', gettext_noop('Belgium french')))
LANGUAGES = languages


PAGE_DEFAULT_TEMPLATE = 'index.html'

PAGE_TEMPLATES = (
('index.html', 'Default template'),
('blog-post.html', 'Blog post'),
('blog-home.html', 'Blog home'),
)

PAGE_API_ENABLED = True
Expand Down Expand Up @@ -182,39 +182,6 @@
COVERAGE_HTML_REPORT = True
COVERAGE_BRANCH_COVERAGE = False

if 'ckeditor' in INSTALLED_APPS:
CKEDITOR_UPLOAD_PATH = 'uploads'

# ##################################
# Your ckeditor configurations

# Docs
# http://docs.ckeditor.com/#!/api/CKEDITOR.config
#
# If some button doesn't show up, it could help to explicitly allow some
# content related to the buttons with the allowedContent.
# ref. http://docs.ckeditor.com/#!/guide/dev_allowed_content_rules

CKEDITOR_CONFIGS = {
'default': {
'width': 600,
'height': 300,
# 'language': 'en', # it not defined, the widget is localized with
# the browser default value
'toolbar': [
['Bold', 'Italic', 'Underline', 'Strike', 'Subscript'],
['Source', '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
]
},
'minimal': {
'width': 600,
'toolbar': [
['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', '-',
'Link', 'Unlink'],
],
},
}

try:
from local_settings import * # noqa
except ImportError:
Expand Down
57 changes: 57 additions & 0 deletions example/static/cms/blog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

.blog-lead-image {
text-align: center;
}

.blog-lead-image img {
width: 100%;
max-width: 500px;
}

.blog-home .card img {
width: 100%;
border-top-left-radius: 2px;
border-top-right-radius: 2px;
}

.blog-home .card {
min-width: 25%;
max-width: calc(33% - 30px);
}

.blog-meta {
margin-bottom: 0;
font-size: 14px;
}

.blog-home .card:first-child {
min-width: 75%;
max-width: 100%;
flex-direction: row;
}
.blog-home .card:first-child .blog-lead-image {
width: 33%;
flex-shrink: 0;
}

.blog-post .blog-lead-image {
margin-bottom: 30px;
}

@media (max-width: 768px) {
.blog-home .card, .blog-home .card:first-child {
min-width: 33%;
max-width: 45%;
flex-direction: column;
}
.blog-home .card:first-child .blog-lead-image {
width: 100%;
flex-shrink: 1;
}
}

@media (max-width: 576px) {
.blog-home .card, .blog-home .card:first-child {
max-width: 100%;
}
}

0 comments on commit 912aeaa

Please sign in to comment.