mirror of
https://github.com/yweber/lodel2.git
synced 2025-10-24 18:09:03 +02:00
Documentation on datasources plugins + confspec updates in validator.py
+ a new validator named 'string', it tries to cast the conf value using str()
This commit is contained in:
parent
bf879a833c
commit
6fb04a69fb
3 changed files with 96 additions and 0 deletions
|
|
@ -183,6 +183,12 @@ def none_val(value):
|
|||
return None
|
||||
raise SettingsValidationError("This settings cannot be set in configuration file")
|
||||
|
||||
def str_val(value):
|
||||
try:
|
||||
str(value)
|
||||
except Exception as e:
|
||||
raise SettingsValidationError("Not able to convert value to string : " + str(e))
|
||||
|
||||
#
|
||||
# Default validators registration
|
||||
#
|
||||
|
|
@ -197,6 +203,11 @@ SettingValidator.register_validator(
|
|||
none_val,
|
||||
'Validate None')
|
||||
|
||||
SettingValidator.register_validator(
|
||||
'string',
|
||||
str_val,
|
||||
'Validate string values')
|
||||
|
||||
SettingValidator.register_validator(
|
||||
'strip',
|
||||
str.strip,
|
||||
|
|
@ -294,5 +305,9 @@ LODEL2_CONF_SPECS = {
|
|||
SettingValidator('list')),
|
||||
'editormode': ( False,
|
||||
SettingValidator('bool')),
|
||||
},
|
||||
'lodel2.datasources.*': {
|
||||
'identifier': ( None,
|
||||
SettingValidator('string'))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
plugins/dummy_datasource/__init__.py
Normal file
0
plugins/dummy_datasource/__init__.py
Normal file
81
plugins/dummy_datasource/confspec.py
Normal file
81
plugins/dummy_datasource/confspec.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
from lodel.settings.validator import SettingValidator
|
||||
|
||||
CONFSPEC = {}
|
||||
|
||||
##@page lodel2_datasources Lodel2 datasources
|
||||
#
|
||||
#@par lodel2_datasources_intro Intro
|
||||
# A single lodel2 website can interact with multiple datasources. This page
|
||||
# aims to describe configuration & organisation of datasources in lodel2.
|
||||
# Each object is attached to a datasource. This association is done in the
|
||||
# editorial model, the datasource is identified by a name.
|
||||
#
|
||||
#@par Datasources declaration
|
||||
# To define a datasource you have to write something like this in confs file :
|
||||
#<pre>
|
||||
#[lodel2.datasources.DATASOURCE_NAME]
|
||||
#identifier = DATASOURCE_FAMILY.SOURCE_NAME
|
||||
#</pre>
|
||||
# See below for DATASOURCE_FAMILY & SOURCE_NAME
|
||||
#
|
||||
#@par Datasources plugins
|
||||
# Each datasource family is a plugin. For example mysql or a mongodb plugins.
|
||||
# Here is the CONFSPEC variable templates for datasources plugins
|
||||
#<pre>
|
||||
#CONFSPEC = {
|
||||
# 'lodel2.datasource.example.*' : {
|
||||
# 'conf1' : VALIDATOR_OPTS,
|
||||
# 'conf2' : VALIDATOR_OPTS,
|
||||
# ...
|
||||
# }
|
||||
#}
|
||||
#</pre>
|
||||
#MySQL example
|
||||
#<pre>
|
||||
#CONFSPEC = {
|
||||
# 'lodel2.datasource.mysql.*' : {
|
||||
# 'host': ( 'localhost',
|
||||
# SettingValidator('host')),
|
||||
# 'db_name': ( 'lodel',
|
||||
# SettingValidator('string')),
|
||||
# 'username': ( None,
|
||||
# SettingValidator('string')),
|
||||
# 'password': ( None,
|
||||
# SettingValidator('string')),
|
||||
# }
|
||||
#}
|
||||
#</pre>
|
||||
#
|
||||
#@par Configuration example
|
||||
#<pre>
|
||||
# [lodel2.datasources.main]
|
||||
# identifier = mysql.Core
|
||||
# [lodel2.datasources.revues_write]
|
||||
# identifier = mysql.Revues
|
||||
# [lodel2.datasources.revues_read]
|
||||
# identifier = mysql.Revues
|
||||
# [lodel2.datasources.annuaire_persons]
|
||||
# identifier = persons_web_api.example
|
||||
# ;
|
||||
# ; Then, in the editorial model you are able to use "main", "revues_write",
|
||||
# ; etc as datasource
|
||||
# ;
|
||||
# ; Here comes the datasources declarations
|
||||
# [lodel2.datasource.mysql.Core]
|
||||
# host = db.core.labocleo.org
|
||||
# db_name = core
|
||||
# username = foo
|
||||
# password = bar
|
||||
# ;
|
||||
# [lodel2.datasource.mysql.Revues]
|
||||
# host = revues.org
|
||||
# db_name = RO
|
||||
# username = foo
|
||||
# password = bar
|
||||
# ;
|
||||
# [lodel2.datasource.persons_web_api.example]
|
||||
# host = foo.bar
|
||||
# username = cleo
|
||||
#</pre>
|
||||
Loading…
Add table
Add a link
Reference in a new issue