2017-07-06 21:07:38 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2013-05-02 23:12:03 -07:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2023-01-12 15:19:46 -06:00
|
|
|
# Copyright © 2010-2023 Lance Edgar
|
2013-05-02 23:12:03 -07: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-02 23:12:03 -07: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-02 23:12:03 -07: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-02 23:12:03 -07:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
2013-09-01 07:27:47 -07:00
|
|
|
Template Context Helpers
|
2013-05-02 23:12:03 -07:00
|
|
|
"""
|
|
|
|
|
2020-08-22 12:25:02 -05:00
|
|
|
import os
|
2013-05-02 23:12:03 -07:00
|
|
|
import datetime
|
|
|
|
from decimal import Decimal
|
2023-05-05 00:18:16 -05:00
|
|
|
from collections import OrderedDict
|
2013-05-02 23:12:03 -07:00
|
|
|
|
2017-07-19 01:42:18 -05:00
|
|
|
from rattail.time import localtime, make_utc
|
2023-05-05 00:18:16 -05:00
|
|
|
from rattail.util import pretty_quantity, pretty_hours, hours_as_decimal
|
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-02 23:12:03 -07:00
|
|
|
|
2021-02-15 12:57:35 -06:00
|
|
|
from tailbone.util import (csrf_token, get_csrf_token,
|
|
|
|
pretty_datetime, raw_datetime,
|
2022-12-24 14:56:12 -06:00
|
|
|
render_markdown,
|
2023-01-12 15:19:46 -06:00
|
|
|
route_exists,
|
|
|
|
get_liburl)
|
2013-05-02 23:12:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
def pretty_date(date):
|
2013-07-05 10:52:47 -07:00
|
|
|
"""
|
|
|
|
Render a human-friendly date string.
|
|
|
|
"""
|
|
|
|
if not date:
|
|
|
|
return ''
|
2013-05-02 23:12:03 -07: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)
|