combo/combo/manager/templatetags/cells.py

37 lines
1.5 KiB
Python

# 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 template
from django.core.urlresolvers import reverse
register = template.Library()
@register.simple_tag(takes_context=True)
def cell_form(context, cell):
context['url'] = reverse('combo-manager-page-edit-cell', kwargs={
'page_pk': cell.page.id, 'cell_reference': cell.get_reference()})
form_class = cell.get_default_form_class()
if form_class:
context['form'] = form_class(instance=cell, prefix='c%s' % cell.get_reference())
else:
context['form'] = None
context['cell'] = cell
cell_form_template = template.loader.get_template('combo/manager_edit_cell_block.html')
with context.push():
context = context.flatten()
context.update(cell.get_extra_manager_context())
return cell_form_template.render(context)