2017-07-06 21:07:38 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2013-05-03 01:12:03 -05:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2021-02-15 12:57:35 -06:00
|
|
|
# Copyright © 2010-2021 Lance Edgar
|
2013-05-03 01:12:03 -05:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
2017-07-06 23:47:56 -05:00
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
2013-05-03 01:12:03 -05:00
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2017-07-06 23:47:56 -05:00
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
2013-05-03 01:12:03 -05:00
|
|
|
#
|
2017-07-06 23:47:56 -05:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
2013-05-03 01:12:03 -05:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
2013-09-01 09:27:47 -05:00
|
|
|
Template Context Helpers
|
2013-05-03 01:12:03 -05:00
|
|
|
"""
|
|
|
|
|
2017-07-06 21:07:38 -05:00
|
|
|
from __future__ import unicode_literals, absolute_import
|
2014-11-18 23:00:24 -06:00
|
|
|
|
2020-08-22 12:25:02 -05:00
|
|
|
import os
|
2013-05-03 01:12:03 -05:00
|
|
|
import datetime
|
|
|
|
from decimal import Decimal
|
|
|
|
|
2017-07-19 01:42:18 -05:00
|
|
|
from rattail.time import localtime, make_utc
|
2020-03-18 13:15:11 -05:00
|
|
|
from rattail.util import (pretty_quantity, pretty_hours, hours_as_decimal,
|
|
|
|
OrderedDict)
|
2020-08-09 14:03:28 -05:00
|
|
|
from rattail.db.util import maxlen
|
2016-12-14 12:32:41 -06:00
|
|
|
|
2017-07-06 21:07:38 -05:00
|
|
|
from webhelpers2.html import *
|
|
|
|
from webhelpers2.html.tags import *
|
2013-05-03 01:12:03 -05:00
|
|
|
|
2021-02-15 12:57:35 -06:00
|
|
|
from tailbone.util import (csrf_token, get_csrf_token,
|
|
|
|
pretty_datetime, raw_datetime,
|
|
|
|
route_exists)
|
2013-05-03 01:12:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
def pretty_date(date):
|
2013-07-05 12:52:47 -05:00
|
|
|
"""
|
|
|
|
Render a human-friendly date string.
|
|
|
|
"""
|
|
|
|
if not date:
|
|
|
|
return ''
|
2013-05-03 01:12:03 -05:00
|
|
|
return date.strftime('%a %d %b %Y')
|
2017-07-06 21:07:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
def render_attrs(**attrs):
|
|
|
|
"""
|
|
|
|
Convenience wrapper to replace the deprecated
|
|
|
|
`webhelpers.html.builder.format_attrs()`
|
|
|
|
"""
|
|
|
|
HTML.optimize_attrs(attrs)
|
|
|
|
return HTML.render_attrs(attrs)
|