mirror of
https://github.com/yweber/lodel2.git
synced 2026-03-04 03:02:01 +01:00
Modification to be less dependent to django + logging in db wrapper
This commit is contained in:
parent
3ce6e1774e
commit
ebdb512500
6 changed files with 49 additions and 6 deletions
|
|
@ -5,6 +5,9 @@ from Database.sqlsettings import SQLSettings as sqlsettings
|
|||
from django.conf import settings
|
||||
import re
|
||||
|
||||
import logging as logger #TODO hack to replace the standarts use of logging in django
|
||||
logger.getLogger().setLevel('DEBUG')
|
||||
|
||||
class SqlWrapper(object):
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -155,8 +158,9 @@ class SqlWrapper(object):
|
|||
try:
|
||||
table.create(self.get_write_engine())
|
||||
return True
|
||||
except:
|
||||
except Exception as e:
|
||||
# TODO Ajuster le code d'erreur à retourner
|
||||
logger.warning("Error creating table : "+str(e))
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -187,8 +191,9 @@ class SqlWrapper(object):
|
|||
table.drop(db, checkfirst=True)
|
||||
db.close()
|
||||
return True
|
||||
except:
|
||||
except Exception as e:
|
||||
# TODO ajuster le code d'erreur
|
||||
logger.warning("Error droping table : "+str(e))
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -277,8 +282,9 @@ class SqlWrapper(object):
|
|||
sqlresult = self.execute(update_object, sqlsettings.ACTION_TYPE_WRITE)
|
||||
updated_lines_count = sqlresult.rowcount
|
||||
|
||||
except DataError:
|
||||
except DataError as e:
|
||||
# TODO Voir si on garde "-1" ou si on place un "None" ou un "False"
|
||||
logger.warning("Error updating database : "+str(e))
|
||||
updated_lines_count = -1
|
||||
|
||||
return updated_lines_count
|
||||
|
|
@ -369,7 +375,8 @@ class SqlWrapper(object):
|
|||
records = sqlresult.fetchall()
|
||||
for record in records:
|
||||
selected_lines.append(dict(zip(record.keys(), record)))
|
||||
except:
|
||||
except Exception as e:
|
||||
logger.debug("Error selecting in database : "+str(e))
|
||||
selected_lines = None
|
||||
|
||||
return selected_lines
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
"""
|
||||
|
||||
from Lodel.utils.mlstring import MlString
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger('Lodel2.EditorialModel')
|
||||
|
||||
class EmComponent(object):
|
||||
|
||||
|
|
@ -14,6 +17,7 @@ class EmComponent(object):
|
|||
@exception TypeError
|
||||
"""
|
||||
def __init__(self, id_or_name):
|
||||
logger.debug('Instanciation : '+str(id_or_name))
|
||||
if self is EmComponent:
|
||||
raise EnvironmentError('Abstract class')
|
||||
if type(id_or_name) is int:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.test import TestCase
|
||||
#from django.test import TestCase
|
||||
from unittest import TestCase
|
||||
from EditorialModel.lib.component import EmComponent
|
||||
|
||||
class ComponentTestCase(TestCase):
|
||||
|
|
@ -6,3 +7,4 @@ class ComponentTestCase(TestCase):
|
|||
def test_component_instanciate_with_numeric_id(self):
|
||||
testComp = EmComponent(2)
|
||||
self.assertEqual(testComp.id, 2)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,28 @@ TEMPLATE_DEBUG = True
|
|||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'django': {
|
||||
'handlers': ['console'],
|
||||
'propagate': True,
|
||||
'level': 'DEBUG',
|
||||
},
|
||||
'Lodel2.database': {
|
||||
'handlers': ['console'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': True,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# Application definition
|
||||
|
||||
|
|
@ -55,7 +77,6 @@ WSGI_APPLICATION = 'Lodel.wsgi.application'
|
|||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
|
|
|
|||
3
runtest
Executable file
3
runtest
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
python -m unittest
|
||||
6
test.py
Normal file
6
test.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.conf import settings
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger('Lodel2.Database')
|
||||
|
||||
logger.debug('Foobar')
|
||||
Loading…
Add table
Add a link
Reference in a new issue