1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-11-01 03:59:02 +01:00

A lot of small bugfixes

This commit is contained in:
Yann 2016-06-30 17:43:49 +02:00
commit dd2f93faea
10 changed files with 34 additions and 27 deletions

Binary file not shown.

View file

@ -110,8 +110,7 @@ class DataHandler(object):
return data_handler.default
elif data_handler is not None and data_handler.nullable:
return None
return RuntimeError("Unable to construct data for field %s", fname)
return cur_value
##@brief Check datas consistency
# @param emcomponent EmComponent : An EmComponent child class instance
@ -184,6 +183,7 @@ class DataField(DataHandler):
# References are fields that stores a reference to another
# editorial object
class Reference(DataHandler):
base_type="ref"
##@brief Instanciation
# @param allowed_classes list | None : list of allowed em classes if None no restriction
@ -249,19 +249,22 @@ class SingleRef(Reference):
##@brief This class represent a data_handler for multiple references to another object
#
# The fields using this data handlers are like SingleRef but can store multiple references in one field
# @note SQL implementation could be tricky
# @note for the moment split on ',' chars
class MultipleRef(Reference):
##
# @param max_item int | None : indicate the maximum number of item referenced by this field, None mean no limit
def __init__(self, max_item = None, **kwargs):
self.max_item = max_item
super().__init__(**kwargs)
def _check_data_value(self, value):
value = value.split(',')
if self.max_item is not None:
if self.max_item < len(value):
return None, FieldValidationError("To many items")
return value, None
## @brief Class designed to handle datas access will fieldtypes are constructing datas
#

View file

@ -20,10 +20,9 @@ class List(MultipleRef):
# @param value *
# @return tuple(value, exception)
def _check_data_value(self, value):
val, expt = super()._check_data_value()
val, expt = super()._check_data_value(value)
if not isinstance(expt, Exception):
val = list(val)
val, expt = super()._check_data_value(value.values())
return val, expt
@ -41,10 +40,9 @@ class Set(MultipleRef):
# @param value *
# @return tuple(value, exception)
def _check_data_value(self, value):
val, expt = super()._check_data_value()
val, expt = super()._check_data_value(value)
if not isinstance(expt, Exception):
val = set(val)
val, expt = super()._check_data_value(value.values())
val = tuple(set(val))
return val, expt
@ -62,9 +60,9 @@ class Map(MultipleRef):
# @param value *
# @return tuple(value, exception)
def _check_data_value(self, value):
val, expt = super()._check_data_value(value)
if not isinstance(value, dict):
return None, FieldValidationError("Values for dict fields should be dict")
val, expt = super()._check_data_value(value.values())
return (
None if isinstance(expt, Exception) else value,
expt)

View file

@ -180,8 +180,11 @@ class LeObject(object):
cls.__name__))
##@return A dict with fieldname as key and datahandler as instance
@classmethod
def fields(cls):
return copy.copy(cls._fields)
def fields(cls, include_ro = False):
if include_ro:
return copy.copy(cls._fields)
else:
return {fname:cls._fields[fname] for fname in cls._fields if not cls._fields[fname].is_internal()}
##@brief Return the list of parents classes
#

View file

@ -188,7 +188,9 @@ class LeFilteredQuery(LeQuery):
other_ds_filters[cur_ds].append(
((rfield, ref_dict), op, value))
#deduplication of std filters
filters_orig = list(set(filters_orig))
if not isinstance(filters_orig, set):
filters_orig = set(filters_orig)
filters_orig = list(filters_orig)
# Sets _query_filter attribute of self query
self._query_filter = (filters_orig, result_rel_filters)
@ -290,9 +292,7 @@ field name" % fieldname)
err_l[field] = ret
continue
field_datahandler = self._target_class.field(field)
# Casting value given datahandler
value, error = field_datahandler._check_data_value(value)
if isinstance(error, Exception):
if isinstance(field_datahandler, Exception):
err_l[field] = error
continue
if ref_field is not None and not field_datahandler.is_reference():
@ -335,6 +335,8 @@ field to use for the relational filter"
else:
rel_filters.append((ret, operator, value))
else:
# Casting value given datahandler
value, error = field_datahandler._check_data_value(value)
res_filters.append((field,operator, value))
if len(err_l) > 0:

View file

@ -25,9 +25,6 @@ def admin_update(request):
obj = dyncode.Object.get(['lodel_id = %d' % lodel_id])
if len(obj) == 0:
raise HttpException(404)
print("WHAT WE GOT AS RESPONSE : ")
for n,o in enumerate(obj):
print("\t",n,o.datas(True))
return get_response('admin/admin_edit.html', obj = obj)
def admin_create(request):

View file

@ -1,4 +1,8 @@
{% extends "base_backend.html" %}
{% import "admin/editable_component.html" as edit %}
{% block title %}- Creating a new {{target.__name__}}{% endblock %}
{% block body %}
{% for fieldname, field in target.fields().items() %}
{{edit.input(fieldname, field) }}
{% endfor %}
{% endblock %}

Binary file not shown.

View file

@ -71,7 +71,7 @@ class LeQueryDatasourceTestCase(unittest.TestCase):
self.assertEqual(call_args[0], cls)
self.assertEqual(
sorted(call_args[1]),
sorted([('lodel_id', '=', '1'), ('alias', '=', '2')]))
sorted([('lodel_id', '=', 1), ('alias', '=', '2')]))
self.assertEqual(call_args[2], [])
self.check_nocall(read = False, exclude = ['delete'])
self.check_nocall(read = True)
@ -87,7 +87,7 @@ class LeQueryDatasourceTestCase(unittest.TestCase):
query.execute()
self.mockwrite.delete.assert_called_once_with(
cls,
[('lodel_id', '=', '1')],
[('lodel_id', '=', 1)],
[(('alias', {cls: 'firstname'}), '=', 'foo')])
self.check_nocall(read = False, exclude = ['delete'])
self.check_nocall(read = True)

View file

@ -13,20 +13,20 @@ class LeFilteredQueryTestCase(unittest.TestCase):
def test_filters(self):
""" Testing FilteredQuery filters handling """
test_datas = [ ( 'lodel_id = 42',
( [('lodel_id','=','42')],
( [('lodel_id','=',42)],
[])),
( 'lodel_id <= 42',
( [('lodel_id','<=','42')],
( [('lodel_id','<=',42)],
[])),
( ['lodel_id <= 42'],
( [('lodel_id','<=','42')],
( [('lodel_id','<=',42)],
[])),
( ('lodel_id <= 42',),
( [('lodel_id','<=','42')],
( [('lodel_id','<=',42)],
[])),
( ['lodel_id <= 42','lodel_id >= 33'],
( [ ('lodel_id','<=','42'),
('lodel_id', '>=','33')],
( [ ('lodel_id','<=',42),
('lodel_id', '>=',33)],
[])),
]
for q_class in self.q_classes:
@ -70,7 +70,7 @@ class LeFilteredQueryTestCase(unittest.TestCase):
'not in',
'like',
'not like']
values = ( '42',
values = ( 42,
'not in',
'in',
'like',