zoom.tools module¶
zoom.tools
-
zoom.tools.ensure_listy(obj)¶ ensure object is wrapped in a list if it can’t behave like one
>>> ensure_listy('not listy') ['not listy']
>>> ensure_listy(['already listy']) ['already listy']
>>> ensure_listy([]) []
-
zoom.tools.first_day_of_last_month(any_date)¶ Returns the first day of last month for any date
>>> first_day_of_last_month(datetime.date(2016, 1, 21)) datetime.date(2015, 12, 1)
-
zoom.tools.first_day_of_next_month(any_date)¶ returns the first day of next month for any date
>>> first_day_of_next_month(datetime.date(2016, 2, 1)) datetime.date(2016, 3, 1)
-
zoom.tools.first_day_of_the_month(any_date)¶ returns the first day of the month for any date
>>> first_day_of_the_month(datetime.date(2016, 12, 31)) datetime.date(2016, 12, 1)
-
zoom.tools.get_markdown_converter()¶ Return a configured markdown converter
>>> markdown("a [[wikilink]] test") '<p>a <a class="wikilink" href="wikilink.html">wikilink</a> test</p>'
>>> markdown("a [[wikilink.html]] test") '<p>a [[wikilink.html]] test</p>'
-
zoom.tools.get_template(template_name='default', theme='default')¶ Get site page template
-
zoom.tools.hide_helpers(content)¶ prevent helper requests from being filled
-
zoom.tools.home(view=None)¶ Redirect to application home.
-
zoom.tools.how_long(time1, time2)¶ Returns a string that describes the difference between two times.
>>> import time >>> now = now()
>>> how_long(now, now) 'a moment'
>>> how_long(now, now + one_minute / 3) '20 seconds'
>>> how_long(now, now + one_hour / 3) '20 minutes'
>>> how_long(now, now + one_day / 3) '8 hours'
>>> how_long(now, now + one_day) '1 day'
>>> how_long(now, now + 2 * one_day) '2 days'
>>> how_long(now, now + 15 * one_day) '2 weeks'
>>> how_long(now, now + 35 * one_day) 'over a month'
>>> how_long(now, now + 65 * one_day) 'over 2 months'
>>> how_long(now, now + 361 * one_day) 'almost a year'
>>> how_long(now, now + 20 * one_minute) '20 minutes'
>>> how_long(now, now + 2 * 365 * one_day) 'almost two years'
>>> how_long(now, now + 3.25 * 365 * one_day) 'over 3 years'
>>> how_long(now, now + 1.25 * 365 * one_day) 'over a year'
>>> how_long(today(), tomorrow(today())) '1 day'
>>> how_long(today(), now + one_week) '7 days'
>>> how_long(now, time.time()) 'a moment'
>>> failed = False >>> try: ... how_long(now, None) ... except TypeError: ... failed = True >>> failed True
-
zoom.tools.how_long_ago(anytime, since=None)¶ Returns a string that describes the difference between any time and now.
>>> now = now()
>>> how_long_ago(now - datetime.timedelta(1) * 2) '2 days ago'
>>> how_long_ago(now + 20 * one_minute) '19 minutes from now'
>>> how_long_ago(now - 20 * one_minute) '20 minutes ago'
>>> how_long_ago(now - 20 * one_minute, now - 10 * one_minute) '10 minutes ago'
-
zoom.tools.htmlquote(text)¶ Encodes text for raw use in HTML.
>>> htmlquote(u"<'&\">") '<'&">'
>>> htmlquote("<'&\">") '<'&">'
-
zoom.tools.is_listy(obj)¶ test to see if an object will iterate like a list
>>> is_listy([1,2,3]) True
>>> is_listy(set([3,4,5])) True
>>> is_listy((3,4,5)) True
>>> is_listy(dict(a=1, b=2)) False
>>> is_listy('123') False
-
zoom.tools.last_day_of_last_month(any_date)¶ Returns the first day of last month for any date
>>> last_day_of_last_month(datetime.date(2016, 1, 21)) datetime.date(2015, 12, 31)
-
zoom.tools.last_day_of_next_month(any_date)¶ returns the last day of next month for any date
>>> last_day_of_next_month(datetime.date(2016, 2, 1)) datetime.date(2016, 3, 31)
-
zoom.tools.last_day_of_the_month(any_date)¶ returns the last day of the month for any date
>>> last_day_of_the_month(datetime.date(2016, 2, 1)) datetime.date(2016, 2, 29)
>>> last_day_of_the_month(datetime.datetime(2016, 2, 1, 1, 1, 1)) datetime.date(2016, 2, 29)
-
zoom.tools.last_month(any_date)¶ Returns date range for last month for any date
>>> last_month(datetime.date(2016, 1, 21)) (datetime.date(2015, 12, 1), datetime.date(2015, 12, 31))
-
zoom.tools.load(pathname, encoding='utf-8')¶ Read a file and return the contents
-
zoom.tools.load_content(pathname, *args, **kwargs)¶ Load a content file and use it to format parameters
-
zoom.tools.load_template(name, default=None)¶ Load a template from the theme folder.
Templates usually have .html file extensions and this module will assume that’s what is desired unless otherwise specified.
-
zoom.tools.markdown(content)¶ Transform content with markdown
>>> markdown('this **is** bold') '<p>this <strong>is</strong> bold</p>'
-
zoom.tools.next_month(any_date)¶ Returns date range for next month for any date
>>> next_month(datetime.date(2016, 1, 21)) (datetime.date(2016, 2, 1), datetime.date(2016, 2, 29))
-
zoom.tools.now()¶ Return the current datetime
-
zoom.tools.redirect_to(*args, **kwargs)¶ Return a redirect response for a URL.
-
zoom.tools.restore_helpers(content)¶ Restores content helpers to their usual form
-
zoom.tools.this_month(any_date)¶ Returns date range for last month for any date
>>> this_month(datetime.date(2016, 1, 21)) (datetime.date(2016, 1, 1), datetime.date(2016, 1, 31))
-
zoom.tools.today()¶ Return the current date
>>> today() == datetime.date.today() True
-
zoom.tools.tomorrow(any_date=None)¶ Return date for tomorrow
>>> tomorrow(datetime.date(2017, 12, 3)) datetime.date(2017, 12, 4)
>>> tomorrow(datetime.date(2016, 12, 31)) datetime.date(2017, 1, 1)
-
zoom.tools.unisafe(val)¶ safely convert to unicode
>>> unisafe(None) ''
>>> unisafe(b'123') '123'
>>> unisafe( ... b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81' ... b'\xa1\xe3\x81\xaf\xe4\xb8\x96\xe7\x95\x8c' ... ) 'こんにちは世界'
>>> unisafe(1) '1'
-
zoom.tools.websafe(content)¶ Return htmlquoted version of content
>>> websafe(b'This could be <problematic>') 'This could be <problematic>'
-
zoom.tools.yesterday(any_date=None)¶ Return date for yesterday
>>> yesterday(datetime.date(2017, 12, 4)) datetime.date(2017, 12, 3)
>>> yesterday(datetime.date(2017, 1, 1)) datetime.date(2016, 12, 31)
-
zoom.tools.zoompath(*args)¶ Returns the location of a standard Zoom asset