The application’s model objects
Abstract base entity class.
Return an Unicode, possibly HTML-decorated, caption of the entity.
Parameters: | html – either None (the default) or a boolean value |
---|
If html is None or True then the result may be an HTML representation of the entity, otherwise it is plain text.
Perform any check before an new instance is inserted
Perform any check before updating the instance
Delete this instance from the database.
Update entity with given data.
Mixin class for globally unique identified entities.
Last update timestamp.
This module implements some utilities, mainly related to importing and exporting tourneys data in a portable format.
Scarry used an INI file and we had several drawbacks with it, mainly because sending them with e-mail would result in data corruption.
SoL uses YAML instead, by default compressing the outcome with gzip.
Save insertions, changes and deletions to the database.
Parameters: |
|
---|---|
Return type: | a tuple of three lists, respectively inserted, modified and deleted record IDs, grouped in a dictionary keyed on PK name. |
Dump almost everything in a ZIP file.
Parameters: |
|
---|---|
Return type: | a buffer containing the ZIP archive |
This function builds a ZIP archive containing both a standard .sol dump made with dump_sol() named everything.sol with all registered tourneys and all registered players (that is, not just those who actually played) and two subdirectories portraits and emblems, respectively containing the images associated to the players and to the clubs.
If location is given, it may be either the full path name of the output file where the backup will be written or the path of a directory. In the latter case the file name will be automatically computed using current time, giving something like sol-backup_2014-02-03T14:35:12.zip.
When keep_only_if_changed is ``True` (the default) and location is a directory, the newly generated backup will be compared with the previous one (if there is at least one, of course) and if nothing has changed it will be removed.
Restore everything from a backup.
Parameters: |
|
---|---|
Return type: | the sequence of loaded tourneys |
This reads the ZIP created by backup() and loads its content into the database, writing the images in the right place (pre-existing images won’t be overwritten, though).
Load the archive exported from SoL.
Parameters: |
|
---|---|
Return type: | the sequence of loaded tourneys |
If content is not specified, it will be loaded with urlopen() from the given url.
Dump tourneys as a YAML document.
Parameters: |
|
---|---|
Return type: | a YAML formatted string |
Simple helper functions.
Force a string to be a unicode instance.
Parameters: | s – any value |
---|---|
Return type: | str |
If s is not already an unicode string, it is assumed it’s an utf-8 encoded string, a thus converted to unicode and returned. Otherwise s is returned as is:
>>> assert asunicode(None) is None
>>> assert not isinstance(asunicode(b'ascii'), bytes)
Normalize the case of a string, removing spurious spaces.
Parameters: |
|
---|---|
Return type: | unicode |
>>> assert normalize(None) is None
>>> print(normalize('lele gaifax'))
Lele Gaifax
>>> print(normalize('LELE'))
Lele
>>> print(normalize('LeLe', title=False))
LeLe
Given a sequence of items, concatenate them in a nice way.
Parameters: |
|
---|---|
Return type: | unicode |
If elts is empty returns an empty unicode string; if it contains a single element, returns the stringified element; otherwise returns a unicode string composed by all but the last elements stringified and joined by a comma, followed by the localized version of and followed by the last element stringified:
>>> print(njoin([1,2,3]))
1, 2 and 3
>>> print(njoin([1,2]))
1 and 2
>>> print(njoin([1]))
1
>>> assert njoin([]) == u''
>>> print(njoin([1,2], stringify=lambda x: str(x*10)))
10 and 20
Given the name of a primary key, return the mapped entity.
Parameters: | pkname – the name of a primary key |
---|---|
Return type: | a mapped class |
Given the name of a primary key, return the related table.
Parameters: | pkname – the name of a primary key |
---|---|
Return type: | a SQLAlchemy table |