lino.utils¶
lino.utils
(the top-level module) contains a few often-used
function for general use. It has also many subpackages and submodules.
This middleware is automatically being installed on every Lino site. |
|
Extends the possibilities for defining choices for fields of a Django model. |
|
Defines some utilities to inspect Python code. |
|
This defines the |
|
Turns a list of items into an endless loop. |
|
Some general utilities for dates. |
|
A collection of tools for generating fictive people and addresses. |
|
Copyright (c) 2009, Sean Creeley All rights reserved. |
|
YAML serializer. |
|
What's the format of a Clipper .dbf file? http://www.the-oasis.net/clipper-12.html#ss12.4 |
|
Just a shortcut and encapsulation. Instead of writing::. |
|
Some diagnostic utilities. |
|
Two TestCase classes for writing tests be run using Django's test runner (i.e. |
|
Defines Lino's Python serializer and deserializer. |
|
This module contains mainly a utility function |
|
Defines the |
|
This is used only when libtidy is not available. |
|
Defines the |
|
This defines the |
|
http://code.activestate.com/recipes/496882/ Author: Michael Palmer 13 Jul 2006 a regex-based JavaScript code compression kludge |
|
A framework for generating Javascript from Python. |
|
This is for writing fixtures that import data from an MS-Access database ( |
|
Defines the |
|
Generic support for Multilingual database content. |
|
A collection of tools around multi-table inheritance. |
|
OdsReader uses odfpy to extract data from an .ods document (OpenOffice.org spreadsheet). |
|
An extended |
|
Preliminary implementation of the Unicode Collation Algorithm. |
|
See Quantities. |
|
The |
|
Just a copy & paste of the |
|
Send an email to a configurable list of addresses when a configurable database item has been changed. |
|
A middleware for sending SQL statements to the Lino logger. |
|
Defines some TestCase classes that are meant for writing general Python test cases (not Django test cases, which are defined in |
|
This is taken from Helio Perroni Filho's answer at https://stackoverflow.com/questions/328356/extracting-text-from-html-file-using-python/3987802#3987802 |
|
Functions
|
|
|
raise an Exception if the given string is not |
|
Doesn't work. |
|
Doesn't work. |
|
Convert the given string into a camel-case string. |
|
|
|
Supports also dates before 1900. |
|
Compute a date using a "reference date" and an offset. |
|
|
|
|
|
Convert the hexadecimal representation of a string to the original string. |
|
"Inline If" : an |
|
Return True if the specified value is a string. |
|
Check whether the given string can be used as a Python identifier. |
|
Returns True if the specified object is iterable. |
|
Returns True if the specified string s is either None, or contains only ASCII characters, or is a validly encoded unicode string. |
|
Remove any empty item (None or ''), call unicode on each and join the remaining word using a single space. |
Return the last day of the month of the given date. |
|
|
Convert Decimal to a money formatted string. |
|
A simplistic replacement for the puts function of clint which has the problem of not supporting unicode strings. |
|
Convert a string to its hexadecimal representation. |
|
Thanks to nickl in Stackoverflow |
When we want unicode strings (e.g. |
|
|
Return the number of workdays (Monday to Friday) between the given two dates. |
Classes
Dictionary-like helper object. |
|
|
Naive representation of a potentially incomplete gregorian date. |
|
|
A dictionary of sums to be collected using an arbitrary key. |
- class lino.utils.AttrDict¶
Bases:
dict
Dictionary-like helper object.
See usage example in Lino utilities
- define(*args)¶
args must be a series of names followed by the value
- resolve(name, default=None)¶
return an attribute with dotted name
- lino.utils.date_offset(ref, days=0, **offset)¶
Compute a date using a "reference date" and an offset.
Usage examples in Manipulating dates and time.
- lino.utils.iif(condition, true_value, false_value=None)¶
"Inline If" : an
if
statement as a function.Examples in Lino utilities.
- lino.utils.last_day_of_month(d)¶
Return the last day of the month of the given date.
Examples in Manipulating dates and time.
Thanks to stackoverflow.com.
- lino.utils.isiterable(x)¶
Returns True if the specified object is iterable.
- lino.utils.is_string(s)¶
Return True if the specified value is a string.
- lino.utils.isidentifier(s)¶
Check whether the given string can be used as a Python identifier.
- lino.utils.ispure(s)¶
Returns True if the specified string s is either None, or contains only ASCII characters, or is a validly encoded unicode string.
- lino.utils.join_words(*words)¶
Remove any empty item (None or ''), call unicode on each and join the remaining word using a single space.
TODO: move this to etgen.html ?
See examples in Lino utilities.
- lino.utils.d2iso(d)¶
Supports also dates before 1900.
- lino.utils.call_optional_super(cls, self, name, *args, **kw)¶
Doesn't work. See 20110914.
- lino.utils.call_on_bases(cls, name, *args, **kw)¶
Doesn't work. See 20110914. This is necessary because we want to call setup_report on the model and all base classes of the model. We cannot use super() for this because the setup_report method is optional.
- lino.utils.str2hex(s)¶
Convert a string to its hexadecimal representation.
See examples in About formatting.
- lino.utils.hex2str(value)¶
Convert the hexadecimal representation of a string to the original string.
See also
str2hex()
.Examples in About formatting.
- class lino.utils.IncompleteDate(year, month, day)¶
Bases:
object
Naive representation of a potentially incomplete gregorian date.
Where incomplete means that maybe only the year is known and day and month is unknown or similarly otherwise. Such a date may not always be convertible to
datetime.date
.Some examples are in Manipulating dates and time.
- classmethod parse(s)¶
Parse the given string and return an
IncompleteDate
object.Examples in Manipulating dates and time.
- get_age(today)¶
Return age in years as integer.
- lino.utils.moneyfmt(value, places=2, curr='', sep=',', dp='.', pos='', neg='-', trailneg='')¶
Convert Decimal to a money formatted string.
places: required number of places after the decimal pointcurr: optional currency symbol before the sign (may be blank)sep: optional grouping separator (comma, period, space, or blank)dp: decimal point indicator (comma or period)only specify as blank when places is zeropos: optional sign for positive numbers: '+', space or blankneg: optional sign for negative numbers: '-', '(', space or blanktrailneg: optional trailing minus indicator: '-', ')', space or blankSee examples in About formatting.
- lino.utils.unicode_string(x)¶
When we want unicode strings (e.g. translated exception messages) to appear in an Exception, we must first encode them using a non-strict errorhandler. Because the message of an Exception may not be a unicode string.
- lino.utils.workdays(start, end)¶
Return the number of workdays (Monday to Friday) between the given two dates. Is not aware of holidays.
Both dates start and end are included. For example if you specify a Monday as start and Monday of the following week as end, then you get 6 (not 5). See examples in: Manipulating dates and time.
- lino.utils.camelize(s)¶
Convert the given string into a camel-case string.
Usage examples in About formatting.
- lino.utils.uncamel(s)¶
Thanks to nickl in Stackoverflow
Usage examples in About formatting.
- lino.utils.puts(s)¶
A simplistic replacement for the puts function of clint which has the problem of not supporting unicode strings.
This method is meant for issuing to the interactive console messages which do not need to be logged because they just give information about what's going on.
Currently this just prints the string to stdout using
print
. I prefer to use this over a plainprint
statement because I guess that there will be problems (mainly thinking about the fact that writing to stdout is considered an error in a wsgi application).
- class lino.utils.SumCollector¶
Bases:
object
A dictionary of sums to be collected using an arbitrary key.
This is also included in the default context used by the Jinja renderer (
lino.modlib.jinja
) when rendering templates, which makes it a more complete solution for a problem asked also elsewhere, e.g. on Stackoverflow.See examples in Lino utilities.
- collect(k, value)¶
Add the given value to the sum at the given key k.