1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-10-21 08:39:03 +02:00

Lodel: first draft of Settings class

This commit is contained in:
ArnAud 2015-11-20 14:04:41 +01:00
commit d854b468e0
4 changed files with 41 additions and 4 deletions

2
.gitignore vendored
View file

@ -2,6 +2,6 @@
.venv .venv
.git .git
.idea .idea
settings.py settings_local.py
doc doc
.*.swp .*.swp

View file

@ -1,6 +1,6 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
import settings from Lodel.settings import Settings
## @brief Manages the accesses to a MySQL datasource ## @brief Manages the accesses to a MySQL datasource
class MySQL(object): class MySQL(object):
@ -11,7 +11,7 @@ class MySQL(object):
field_lodel_id = 'lodel_id' field_lodel_id = 'lodel_id'
class_table_prefix = 'class_' class_table_prefix = 'class_'
objects_table_name = 'object' objects_table_name = 'object'
connections = settings.DATABASE_CONNECTIONS connections = Settings.get("datasource")
## @brief indicates if we want ON DELETE CASCADE on foreign keys ## @brief indicates if we want ON DELETE CASCADE on foreign keys
# @todo implementation in migration handler # @todo implementation in migration handler
fk_on_delete_cascade = False fk_on_delete_cascade = False

37
Lodel/settings.py Normal file
View file

@ -0,0 +1,37 @@
#-*- coding: utf-8 -*-
import settings_local
class Settings:
# List of accepted settings
datasource = None
@staticmethod
# @throw AttributeError if the setting is not defined in this class
def get(attribute):
value = None
# find the value in settings itself, if not set search in settings_local
value = getattr(Settings, attribute)
if value is None:
try:
value = getattr(settings_local, attribute)
except AttributeError:
pass
if value is not None:
try:
func = getattr(Settings, attribute + '_args')
value = func(value)
except AttributeError:
pass
return value
@staticmethod
# @throw AttributeError if the setting is not defined in this class
def set(attribute, value):
setattr(Settings, attribute, value)
@staticmethod
def datasource_args(value):
return value

View file

@ -2,7 +2,7 @@
import pymysql import pymysql
DATABASE_CONNECTIONS = { datasource = {
'default': { 'default': {
'module': pymysql, 'module': pymysql,
'host': '127.0.0.1', 'host': '127.0.0.1',