general: add initial template support
This commit is contained in:
parent
65b198f953
commit
e1c198794b
|
@ -27,6 +27,7 @@ from model_utils.managers import InheritanceManager
|
|||
class Page(models.Model):
|
||||
title = models.CharField(_('Title'), max_length=50)
|
||||
slug = models.SlugField()
|
||||
template_name = models.CharField(max_length=50)
|
||||
|
||||
|
||||
class CellBase(models.Model):
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# 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 import forms
|
||||
from django.conf import settings
|
||||
|
||||
from combo.data.models import Page
|
||||
|
||||
class PageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Page
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PageForm, self).__init__(*args, **kwargs)
|
||||
templates = [(x[0], x[1]['name']) for x in settings.COMBO_PUBLIC_TEMPLATES.items()]
|
||||
templates.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
self.fields['template_name'].widget = forms.Select(choices=templates)
|
|
@ -4,10 +4,15 @@
|
|||
|
||||
{% block appbar %}
|
||||
<h2>Page - {{ object.title }}</h2>
|
||||
<a rel="popup" href="{% url 'combo-manager-page-edit' pk=object.id %}">edit</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div id="meta">
|
||||
<label>Current template: </label> {{ object.template_name }}
|
||||
</div>
|
||||
|
||||
<div id="available-cells">
|
||||
<h2>Available cells</h2>
|
||||
<ul>
|
||||
|
|
|
@ -25,6 +25,8 @@ urlpatterns = patterns('combo.views',
|
|||
url(r'^pages/add/$', views.page_add, name='combo-manager-page-add'),
|
||||
url(r'^pages/(?P<pk>\w+)/$', views.page_view,
|
||||
name='combo-manager-page-view'),
|
||||
url(r'^pages/(?P<pk>\w+)/edit$', views.page_edit,
|
||||
name='combo-manager-page-edit'),
|
||||
url(r'^pages/(?P<page_pk>\w+)/add-cell-to-(?P<ph_key>\w+)/(?P<cell_type>\w+)/$', views.page_add_cell,
|
||||
name='combo-manager-page-add-cell'),
|
||||
url(r'^pages/(?P<page_pk>\w+)/cell/(?P<cell_pk>\w+)/$', views.page_edit_cell,
|
||||
|
|
|
@ -25,6 +25,8 @@ from django.views.generic import (TemplateView, RedirectView, DetailView,
|
|||
|
||||
from combo.data.models import Page, CellBase
|
||||
|
||||
from .forms import PageForm
|
||||
|
||||
|
||||
class HomepageView(TemplateView):
|
||||
template_name = 'combo/manager_home.html'
|
||||
|
@ -42,10 +44,25 @@ pages_list = PagesListView.as_view()
|
|||
class PageAddView(CreateView):
|
||||
model = Page
|
||||
template_name = 'combo/page_add.html'
|
||||
form_class = PageForm
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('combo-manager-page-view', kwargs={'pk': self.object.id})
|
||||
|
||||
page_add = PageAddView.as_view()
|
||||
|
||||
|
||||
class PageEditView(UpdateView):
|
||||
model = Page
|
||||
template_name = 'combo/page_add.html'
|
||||
form_class = PageForm
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('combo-manager-page-view', kwargs={'pk': self.object.id})
|
||||
|
||||
page_edit = PageEditView.as_view()
|
||||
|
||||
|
||||
class PageView(DetailView):
|
||||
model = Page
|
||||
template_name = 'combo/page_view.html'
|
||||
|
@ -55,7 +72,7 @@ class PageView(DetailView):
|
|||
context['cell_types'] = CellBase.get_cell_content_types()
|
||||
cells = CellBase.objects.filter(page_id=self.object.id
|
||||
).order_by('order').select_subclasses()
|
||||
template = 'standard'
|
||||
template = self.object.template_name
|
||||
placeholders = []
|
||||
combo_template = settings.COMBO_PUBLIC_TEMPLATES.get(template)
|
||||
for placeholder_key, placeholder in combo_template['placeholders'].items():
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# 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 import settings
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from combo.data.models import CellBase, Page
|
||||
|
@ -28,4 +29,5 @@ def page(request):
|
|||
'page_cells': CellBase.objects.filter(page_id=page.id
|
||||
).order_by('order').select_subclasses()
|
||||
}
|
||||
return render(request, 'combo/page_template.html', ctx)
|
||||
template_name = settings.COMBO_PUBLIC_TEMPLATES[page.template_name]['template']
|
||||
return render(request, template_name, ctx)
|
||||
|
|
|
@ -96,7 +96,8 @@ CKEDITOR_UPLOAD_PATH = os.path.join(BASE_DIR, 'uploads/ckeditor')
|
|||
|
||||
COMBO_PUBLIC_TEMPLATES = {
|
||||
'standard': {
|
||||
'template': 'page_template.html',
|
||||
'name': 'Standard',
|
||||
'template': 'combo/page_template.html',
|
||||
'placeholders': {
|
||||
'content': {
|
||||
'name': 'Content',
|
||||
|
|
Loading…
Reference in New Issue