public: add public rendering of pages

This commit is contained in:
Frédéric Péters 2014-12-07 21:24:27 +01:00
parent 39193c7214
commit 144a20d59b
6 changed files with 75 additions and 3 deletions

View File

@ -50,6 +50,12 @@ class CellBase(models.Model):
class TextCell(CellBase):
text = RichTextField(_('Text'), null=True)
def render(self):
from django.utils.safestring import mark_safe
return mark_safe(self.text)
class FortuneCell(CellBase):
pass
def render(self):
import subprocess
return subprocess.check_output(['fortune'])

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Combo</title>
</head>
<body>
<h1>{{ title }}</h1>
{% for cell in cells %}
<div>{{ cell.render }}</div>
{% endfor %}
</body>
</html>

23
combo/public/urls.py Normal file
View File

@ -0,0 +1,23 @@
# combo - content management system
# Copyright (C) 2014 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls import patterns, url, include
from . import views
urlpatterns = patterns('combo.publicviews',
(r'', views.page),
)

View File

@ -1,3 +1,31 @@
from django.shortcuts import render
# combo - content management system
# Copyright (C) 2014 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Create your views here.
from django.shortcuts import get_object_or_404, render
from combo.data.models import CellBase, Page
def page(request):
parts = [x for x in request.path_info.strip('/').split('/') if x]
if not parts:
parts = ['index']
page = get_object_or_404(Page, slug=parts[0])
ctx = {
'title': page.title,
'cells': CellBase.objects.filter(page_id=page.id
).order_by('order').select_subclasses()
}
return render(request, 'combo/page_template.html', ctx)

View File

@ -40,6 +40,7 @@ INSTALLED_APPS = (
'gadjo',
'combo.data',
'combo.manager',
'combo.public',
)
MIDDLEWARE_CLASSES = (

View File

@ -2,6 +2,7 @@ from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^manage/', include('combo.manager.urls')),
url(r'', include('combo.public.urls')),
)
from django.contrib.staticfiles.urls import staticfiles_urlpatterns