Skip to content

Commit e999a4d

Browse files
committed
add example, based on django-fluent-blogs
1 parent 16627fc commit e999a4d

File tree

23 files changed

+864
-0
lines changed

23 files changed

+864
-0
lines changed

example/__init__.py

Whitespace-only changes.

example/example_fluent_pages/__init__.py

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from os.path import join, dirname
2+
from example_standalone.settings import *
3+
4+
INSTALLED_APPS += (
5+
# Add fluent pages with a simple page type:
6+
'fluent_pages',
7+
#'fluent_pages.pagetypes.fluentpage',
8+
'fluent_pages.pagetypes.flatpage',
9+
10+
# Add the page type for adding the "faq" root to the page tree.
11+
'fluent_faq.pagetypes.faqpage',
12+
13+
# fluent-pages dependencies:
14+
'polymorphic',
15+
'polymorphic_tree',
16+
)
17+
18+
ROOT_URLCONF = 'example_fluent_pages.urls'
19+
20+
if django.VERSION >= (1, 8):
21+
TEMPLATES[0]['DIRS'] = [
22+
join(dirname(__file__), "templates"),
23+
]
24+
else:
25+
TEMPLATE_DIRS = (
26+
join(dirname(__file__), "templates"),
27+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% extends "fluent_pages/base.html" %}
2+
{# template layout is essentially the same, reuse it. #}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends "theme1/base.html" %}{% load fluent_pages_tags %}
2+
3+
{% block headtitle %}{% block title %}{% endblock %} - Blog example{% endblock %}
4+
5+
{% block menu %}
6+
{% render_menu %}
7+
{% endblock %}
8+
9+
{# map the blocks #}
10+
{% block main %}
11+
<div id="content">
12+
{% block content %}{% endblock %}
13+
</div>
14+
{% endblock %}

example/example_fluent_pages/urls.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import fluent_pages.urls
2+
#import form_designer.urls
3+
import taggit_selectize.urls
4+
import tinymce.urls
5+
6+
from django.conf.urls import include, url
7+
from django.contrib import admin
8+
admin.autodiscover()
9+
10+
urlpatterns = [
11+
url(r'^admin/apps/tinymce/', include(tinymce.urls)),
12+
url(r'^admin/apps/tags/', include(taggit_selectize.urls)),
13+
url(r'^admin/', include(admin.site.urls)),
14+
15+
#url(r'^forms/', include(form_designer.urls)),
16+
17+
# Not including fluent_faq.urls.
18+
# Instead, create a "faqpage" in the page tree.
19+
# all URLs will be displayed there.
20+
url(r'', include(fluent_pages.urls)),
21+
]

example/example_multilingual/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.conf import settings
2+
3+
4+
def multilingual(request):
5+
lang_list = settings.PARLER_LANGUAGES.get(settings.SITE_ID, ())
6+
return {
7+
'MULTILINGUAL_LANGUAGES': [item['code'] for item in lang_list],
8+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from os.path import join, dirname
2+
from example_standalone.settings import *
3+
4+
PARLER_DEFAULT_LANGUAGE_CODE = 'en' # defaults to LANGUAGE_CODE
5+
6+
if django.VERSION >= (1, 8):
7+
TEMPLATES[0]['DIRS'] = [
8+
join(dirname(__file__), "templates"),
9+
]
10+
TEMPLATES[0]['OPTIONS']['context_processors'] += [
11+
'example_multilingual.context_processors.multilingual',
12+
]
13+
else:
14+
TEMPLATE_DIRS = (
15+
join(dirname(__file__), "templates"),
16+
)
17+
18+
TEMPLATE_CONTEXT_PROCESSORS += (
19+
'example_multilingual.context_processors.multilingual',
20+
)
21+
22+
SITE_ID = 1
23+
24+
PARLER_LANGUAGES = {
25+
# site ID 1:
26+
1: (
27+
{'code': 'en'},
28+
{'code': 'fr'},
29+
{'code': 'de'},
30+
{'code': 'es'},
31+
{'code': 'nl'},
32+
),
33+
'default': {
34+
'hide_untranslated': False, # being explicit here.
35+
'fallback': 'en', # defaults to PARLER_DEFAULT_LANGUAGE_CODE or LANGUAGE_CODE
36+
}
37+
}
38+
39+
# NOTE: this middleware is not required, you can also use our own variation to set the frontend language.
40+
MIDDLEWARE_CLASSES += (
41+
'django.middleware.locale.LocaleMiddleware',
42+
)
43+
44+
ROOT_URLCONF = 'example_multilingual.urls'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{% load i18n parler_tags %}
2+
3+
<div id="sidecol">
4+
<div id="todo" class="postit">
5+
<div class="text">
6+
7+
<p>Set visitor language:</p>
8+
<form method="post" action="{% url 'set_language' %}">{# old Django versions: url 'django.views.i18n.set_language' #}
9+
{% csrf_token %}
10+
11+
<select name="language" onchange="this.form.next.value = this.options[this.selectedIndex].getAttribute('data-next-url') || '';">
12+
{% for code in MULTILINGUAL_LANGUAGES %}
13+
{% get_language_info for code as lang %}
14+
<option value="{{ code }}" {% if LANGUAGE_CODE == code %} selected="selected"{% endif %}
15+
{# when the current page displays a blog entry, make sure the correct URL will be used in switching languages #}
16+
{% if entry %}{% objectlanguage entry code %}data-next-url="{{ object.url }}"{% endobjectlanguage %}{% endif %}>
17+
18+
{{ lang.name }}
19+
</option>
20+
{% endfor %}
21+
</select>
22+
23+
<input type="hidden" name="next" value=""/>
24+
<input type="submit" value="Set!"/>
25+
</form>
26+
<p>
27+
(note that slugs may change between translations)
28+
</p>
29+
30+
31+
</div>
32+
</div>
33+
</div>

example/example_multilingual/urls.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import django.conf.urls.i18n
2+
from django.conf.urls import include, url
3+
from example_standalone.urls import urlpatterns
4+
5+
# Nothing needs to be changed for multilingual support really.
6+
# It depends on the way your project is structured;
7+
# whether you use i18n_patterns(), the LocaleMiddleware
8+
# or separate settings per domain name with a different LANGUAGE_CODE set.
9+
10+
urlpatterns = [
11+
url('^i18n/', include(django.conf.urls.i18n)),
12+
] + urlpatterns

example/example_standalone/__init__.py

Whitespace-only changes.
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Django settings for example project.
2+
from os.path import join, dirname, realpath
3+
import django
4+
5+
# Add parent path,
6+
# Allow starting the app without installing the module.
7+
import sys
8+
sys.path.insert(0, dirname(dirname(dirname(realpath(__file__)))))
9+
10+
DEBUG = True
11+
12+
ADMINS = (
13+
# ('Your Name', '[email protected]'),
14+
)
15+
16+
MANAGERS = ADMINS
17+
18+
DATABASES = {
19+
'default': {
20+
'ENGINE': 'django.db.backends.sqlite3',
21+
'NAME': dirname(dirname(__file__)) + '/demo.db',
22+
}
23+
}
24+
25+
TIME_ZONE = 'Europe/Amsterdam'
26+
LANGUAGE_CODE = 'en' # Important when switching to multilingual support!
27+
SITE_ID = 1
28+
29+
USE_I18N = True
30+
USE_L10N = True
31+
USE_TZ = True
32+
33+
MEDIA_ROOT = join(dirname(__file__), "media")
34+
MEDIA_URL = '/media/'
35+
STATIC_ROOT = join(dirname(__file__), "static")
36+
STATIC_URL = '/static/'
37+
38+
STATICFILES_DIRS = ()
39+
STATICFILES_FINDERS = (
40+
'django.contrib.staticfiles.finders.FileSystemFinder',
41+
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
42+
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
43+
)
44+
45+
# Make this unique, and don't share it with anybody.
46+
SECRET_KEY = '-#@bi6bue%#1j)6+4b&#i0g-*xro@%f@_#zwv=2-g_@n3n_kj5'
47+
48+
if django.VERSION >= (1, 8):
49+
TEMPLATES = [
50+
{
51+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
52+
'APP_DIRS': True,
53+
'DIRS': [
54+
join(dirname(__file__), "templates"),
55+
],
56+
'OPTIONS': {
57+
'context_processors': [
58+
'django.contrib.auth.context_processors.auth',
59+
'django.template.context_processors.request',
60+
'django.template.context_processors.static',
61+
'django.contrib.messages.context_processors.messages',
62+
'django.contrib.auth.context_processors.auth',
63+
'django.contrib.messages.context_processors.messages',
64+
]
65+
},
66+
},
67+
]
68+
69+
else:
70+
# List of callables that know how to import templates from various sources.
71+
TEMPLATE_LOADERS = (
72+
'django.template.loaders.filesystem.Loader',
73+
'django.template.loaders.app_directories.Loader',
74+
)
75+
76+
TEMPLATE_CONTEXT_PROCESSORS = (
77+
'django.core.context_processors.i18n',
78+
'django.core.context_processors.media',
79+
'django.core.context_processors.request',
80+
'django.core.context_processors.static',
81+
'django.contrib.auth.context_processors.auth',
82+
'django.contrib.messages.context_processors.messages',
83+
)
84+
85+
TEMPLATE_DIRS = (
86+
join(dirname(__file__), "templates"),
87+
)
88+
89+
MIDDLEWARE_CLASSES = (
90+
'django.middleware.common.CommonMiddleware',
91+
'django.contrib.sessions.middleware.SessionMiddleware',
92+
'django.middleware.csrf.CsrfViewMiddleware',
93+
'django.contrib.auth.middleware.AuthenticationMiddleware',
94+
'django.contrib.messages.middleware.MessageMiddleware',
95+
)
96+
97+
ROOT_URLCONF = 'example_standalone.urls'
98+
99+
INSTALLED_APPS = (
100+
'django.contrib.auth',
101+
'django.contrib.contenttypes',
102+
'django.contrib.sessions',
103+
'django.contrib.sites',
104+
'django.contrib.messages',
105+
'django.contrib.staticfiles',
106+
'django.contrib.admin',
107+
'django.contrib.admindocs',
108+
109+
# Site theme.
110+
# Placed above all other apps, to override third party apps
111+
'theme1',
112+
113+
# FAQ module
114+
'fluent_faq',
115+
116+
# Contents plugins
117+
'fluent_contents',
118+
'fluent_contents.plugins.code',
119+
#'fluent_contents.plugins.disquswidgets',
120+
#'fluent_contents.plugins.formdesignerlink',
121+
'fluent_contents.plugins.gist',
122+
'fluent_contents.plugins.googledocsviewer',
123+
'fluent_contents.plugins.iframe',
124+
'fluent_contents.plugins.markup',
125+
'fluent_contents.plugins.oembeditem',
126+
'fluent_contents.plugins.rawhtml',
127+
#'fluent_contents.plugins.sharedcontent',
128+
'fluent_contents.plugins.text',
129+
#'fluent_contents.plugins.twitterfeed',
130+
131+
# Other (optional) dependencies
132+
'categories_i18n', # default 'categories' app, can be changed.
133+
'django_wysiwyg', # for 'text' plugin
134+
#'disqus', # for 'disqus' plugin
135+
#'form_designer', # for 'formdesignerlink' plugin
136+
'mptt', # for categories_i18n
137+
'parler', # provides the multilingual support.
138+
'slug_preview', # nicer slugs in the admin.
139+
'taggit', # optional tagging support.
140+
'taggit_selectize', # optional autocompletion support for tags
141+
'tinymce', # Used by 'text' plugin, see DJANGO_WYSIWYG_FLAVOR
142+
)
143+
144+
if django.VERSION < (1, 7):
145+
INSTALLED_APPS += (
146+
# For DB upgrades
147+
'south',
148+
)
149+
else:
150+
TEST_RUNNER = 'django.test.runner.DiscoverRunner' # silence system checks
151+
152+
DJANGO_WYSIWYG_FLAVOR = 'tinymce_advanced'
153+
154+
LOGGING = {
155+
'version': 1,
156+
'disable_existing_loggers': False,
157+
'filters': {
158+
'require_debug_false': {
159+
'()': 'django.utils.log.RequireDebugFalse'
160+
}
161+
},
162+
'handlers': {
163+
'mail_admins': {
164+
'level': 'ERROR',
165+
'filters': ['require_debug_false'],
166+
'class': 'django.utils.log.AdminEmailHandler'
167+
}
168+
},
169+
'loggers': {
170+
'django.request': {
171+
'handlers': ['mail_admins'],
172+
'level': 'ERROR',
173+
'propagate': True,
174+
},
175+
}
176+
}
177+
178+
#DISQUS_API_KEY = ''
179+
#DISQUS_WEBSITE_SHORTNAME = ''

example/example_standalone/urls.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fluent_faq.urls
2+
#import form_designer.urls
3+
import tinymce.urls
4+
import taggit_selectize.urls
5+
6+
from django.conf.urls import include, url
7+
from django.contrib import admin
8+
9+
admin.autodiscover()
10+
11+
urlpatterns = [
12+
url(r'^admin/apps/tinymce/', include(tinymce.urls)),
13+
url(r'^admin/apps/tags/', include(taggit_selectize.urls)),
14+
url(r'^admin/', include(admin.site.urls)),
15+
16+
#url(r'^forms/', include(form_designer.urls)),
17+
18+
url(r'', include(fluent_faq.urls)),
19+
]

example/manage-fluent-pages.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_fluent_pages.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

example/manage-multilingual.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_multilingual.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

0 commit comments

Comments
 (0)