Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kstep/ajenti-models
Ajenti models plugin: bindable models framework for Ajenti templates
https://github.com/kstep/ajenti-models
Last synced: about 2 months ago
JSON representation
Ajenti models plugin: bindable models framework for Ajenti templates
- Host: GitHub
- URL: https://github.com/kstep/ajenti-models
- Owner: kstep
- Created: 2014-03-30T20:51:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-03T16:04:43.000Z (over 10 years ago)
- Last Synced: 2024-10-11T23:47:40.292Z (2 months ago)
- Language: Python
- Size: 195 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ajenti-models
=============Ajenti models plugin: bindable models framework for Ajenti templates
Model object is a dict-like object, so it can be bound with `` tag, as well as with `` tag
or used in collections. Though it is not a true dict (it doesn't inherit from `dict` class).It can consume raw data on instance creation and normalize them, e.g. make sure some fields are valid numbers
(even if they are provided as strings), or datetimes (in disguise of datetime formatted as string or unix timestamp).
Good live examples are in [transmission][] and [mpd][] plugins.[transmission]: http://github.com/kstep/ajenti-transmission
[mpd]: http://github.com/kstep/ajenti-mpdAlso it supports some syntax sugar in templates: you can use `` syntax to show
first non-empty field available. E.g. `` will bind model's title field if it's present,
or name field otherwise.If field is missing from model's input, it's value can be taken from `_defaults` class property.
It can also normalize key names with either mappings from `_keymap` class property or by overriding `_mapkey()`
method for complex cases. By default all fields are cast to lower case and converted to word_separated_with_underscores
format from CamelCaseFormat.Example:
```python
from ajenti.plugins.models.api import *@public
class Song(Model):
_casts = {
'date': timestamp,
'last_modified': timestamp,
'pos': int,
'id': int,
'time': timedelta,
'genre': lambda g: ', '.join(set(g)) if isinstance(g, list) else g,'title': fixutf8,
'album': fixutf8,
'artist': fixutf8,
}
_defaults = {
'time': None,
}def _init(self):
if 'name' in self:
self.time = u'\u221E'
self.icon = 'signal'
self.is_stream = Trueelif 'title' in self:
self.icon = 'music'
self.is_stream = False
```