2014-12-08 10:20:23 +01:00
|
|
|
# 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/>.
|
|
|
|
|
2015-02-17 16:20:02 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2015-04-15 15:37:33 +02:00
|
|
|
import datetime
|
|
|
|
|
2014-12-08 10:20:23 +01:00
|
|
|
from django import template
|
2015-05-11 16:26:11 +02:00
|
|
|
from django.template import RequestContext
|
|
|
|
|
2015-02-17 16:20:02 +01:00
|
|
|
from combo.public.menu import get_menu_context
|
2015-04-17 21:50:04 +02:00
|
|
|
from combo.utils import NothingInCacheException
|
2014-12-08 10:20:23 +01:00
|
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
|
|
|
@register.inclusion_tag('combo/placeholder.html', takes_context=True)
|
|
|
|
def placeholder(context, placeholder_name):
|
|
|
|
context['cells'] = [x for x in context['page_cells'] if
|
2015-02-16 17:09:04 +01:00
|
|
|
x.placeholder == placeholder_name and x.is_relevant(context)]
|
2014-12-08 10:20:23 +01:00
|
|
|
return context
|
2014-12-13 11:25:53 +01:00
|
|
|
|
|
|
|
@register.simple_tag(takes_context=True)
|
|
|
|
def render_cell(context, cell):
|
2015-04-17 21:50:04 +02:00
|
|
|
try:
|
|
|
|
return cell.render(context)
|
|
|
|
except NothingInCacheException:
|
|
|
|
return template.loader.get_template('combo/deferred-cell.html').render(context)
|
2015-01-02 20:56:09 +01:00
|
|
|
|
|
|
|
@register.inclusion_tag('combo/menu.html', takes_context=True)
|
2015-02-18 11:22:03 +01:00
|
|
|
def show_menu(context, level=0, current_page=None, depth=1, reduce_depth=False):
|
|
|
|
if reduce_depth:
|
|
|
|
depth -= 1
|
2015-05-11 16:26:11 +02:00
|
|
|
new_context = RequestContext(context['request'], {
|
|
|
|
'page': context['page'],
|
|
|
|
'request': context['request']})
|
|
|
|
return get_menu_context(new_context, level=level, current_page=current_page,
|
2015-02-18 11:22:03 +01:00
|
|
|
depth=depth)
|
2015-04-15 15:37:33 +02:00
|
|
|
|
|
|
|
@register.filter(name='strptime')
|
|
|
|
def strptime(date_string, date_format):
|
|
|
|
try:
|
|
|
|
return datetime.datetime.strptime(date_string, date_format)
|
|
|
|
except ValueError:
|
|
|
|
return None
|