Plna podpora "statickych stranek" (vcetne '/') - flatpages

This commit is contained in:
Tomas Gavenciak 2015-05-27 00:12:41 +02:00
parent 181fce9df5
commit e5f95d5bda
6 changed files with 52 additions and 8 deletions

24
mamweb/admin.py Normal file
View file

@ -0,0 +1,24 @@
from django.contrib import admin
from django.contrib.flatpages.models import FlatPage
# Note: we are renaming the original Admin and Form as we import them!
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld
from django.contrib.flatpages.admin import FlatpageForm as FlatpageFormOld
from django import forms
from ckeditor.widgets import CKEditorWidget
class FlatpageForm(FlatpageFormOld):
content = forms.CharField(widget=CKEditorWidget())
class Meta:
model = FlatPage # this is not automatically inherited from FlatpageFormOld
exclude = []
class FlatPageAdmin(FlatPageAdminOld):
form = FlatpageForm
# We have to unregister the normal admin, and then reregister ours
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)

View file

@ -64,6 +64,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
@ -104,6 +105,8 @@ INSTALLED_APPS = (
'threadedcomments',
'django_comments',
'django.contrib.flatpages',
# MaMweb
'mamweb',
'seminar',
@ -117,7 +120,6 @@ INSTALLED_APPS = (
# 'admin_tools.menu',
# 'admin_tools.dashboard',
'flat',
'django.contrib.admin',
)

View file

@ -21,8 +21,12 @@
<!-- TODO: only on org login -->
<div class="login-bar" style='background: #F80;'>
{% if view.object %}
Objekt {{ view.object }}: {{ view.object }}
{% if view.object.admin_url %}<a href='{{ view.object.admin_url }}'>[admin]</a>{% endif %}
Objekt {{ view.object }}: {{ view.object }}
{% if view.object.admin_url %}<a href='{{ view.object.admin_url }}'>[admin]</a>{% endif %}
{% endif %}
{% if flatpage %}
Stránka <tt>{{ flatpage.url }}</tt> ({{ flatpage.title }})
<a href='{% url 'admin:flatpages_flatpage_change' flatpage.id %}'>[admin]</a>
{% endif %}
</div>
<div class="container">

View file

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block title %}{{ flatpage.title }}{% endblock title %}
{% block content %}
<h2>{{ flatpage.title }}</h2>
<div>
{{ flatpage.content }}
</div>
{% endblock content %}

View file

@ -1,9 +1,13 @@
{% extends "base.html" %}
{% block title %}{{ flatpage.title }}{% endblock title %}
{% block content %}
<div>
<h2>Vítejte na testwebu MaM!</h2>
<div>Toto je stránka podle šablony "home.html"</div>
<p><a href='{% url 'admin:index' %}'>Administrátorské rozhraní</a> (admin/admin)
<h2>{{ flatpage.title }}</h2>
<div>
{{ flatpage.content }}
</div>
{% endblock content %}

View file

@ -19,9 +19,8 @@ urlpatterns = i18n_patterns('',
url(r'^comments_dj/', include('django_comments.urls')),
url(r'^comments_fl/', include('fluent_comments.urls')),
# Obsah
url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'),
# Obsah - flatpages
url(r'^', include('django.contrib.flatpages.urls')), # Pozor: musi byt posledni
)
# This is only needed when using runserver.