misc: don't check datasources during bulk import (#42585)
This commit is contained in:
parent
2104bd26dc
commit
eeedc29c44
|
@ -1007,7 +1007,8 @@ class FormDef(StorableObject):
|
|||
return root
|
||||
|
||||
@classmethod
|
||||
def import_from_xml(cls, fd, charset=None, include_id=False, fix_on_error=False):
|
||||
def import_from_xml(cls, fd, charset=None, include_id=False,
|
||||
fix_on_error=False, check_datasources=True):
|
||||
try:
|
||||
tree = ET.parse(fd)
|
||||
except:
|
||||
|
@ -1029,17 +1030,18 @@ class FormDef(StorableObject):
|
|||
if formdef.max_field_id < max_field_id:
|
||||
formdef.max_field_id = max_field_id
|
||||
|
||||
# check if datasources are defined
|
||||
unknown_datasources = set()
|
||||
for field in formdef.fields:
|
||||
data_source = getattr(field, 'data_source', None)
|
||||
if data_source:
|
||||
if isinstance(data_sources.get_object(data_source),
|
||||
data_sources.StubNamedDataSource):
|
||||
unknown_datasources.add(data_source.get('type'))
|
||||
if unknown_datasources:
|
||||
raise FormdefImportError(N_('Unknown datasources'),
|
||||
details=', '.join(sorted(unknown_datasources)))
|
||||
if check_datasources:
|
||||
# check if datasources are defined
|
||||
unknown_datasources = set()
|
||||
for field in formdef.fields:
|
||||
data_source = getattr(field, 'data_source', None)
|
||||
if data_source:
|
||||
if isinstance(data_sources.get_object(data_source),
|
||||
data_sources.StubNamedDataSource):
|
||||
unknown_datasources.add(data_source.get('type'))
|
||||
if unknown_datasources:
|
||||
raise FormdefImportError(N_('Unknown datasources'),
|
||||
details=', '.join(sorted(unknown_datasources)))
|
||||
|
||||
# check if all field id are unique
|
||||
known_field_ids = set()
|
||||
|
|
|
@ -238,12 +238,14 @@ class WcsPublisher(StubWcsPublisher):
|
|||
carddefs = []
|
||||
for f in z.namelist():
|
||||
if os.path.dirname(f) == 'formdefs_xml' and os.path.basename(f):
|
||||
formdef = FormDef.import_from_xml(z.open(f), include_id=True)
|
||||
formdef = FormDef.import_from_xml(z.open(f), include_id=True,
|
||||
check_datasources=False)
|
||||
formdef.store()
|
||||
formdefs.append(formdef)
|
||||
results['formdefs'] += 1
|
||||
if os.path.dirname(f) == 'carddefs_xml' and os.path.basename(f):
|
||||
carddef = CardDef.import_from_xml(z.open(f), include_id=True)
|
||||
carddef = CardDef.import_from_xml(z.open(f), include_id=True,
|
||||
check_datasources=False)
|
||||
carddef.store()
|
||||
carddefs.append(carddef)
|
||||
results['carddefs'] += 1
|
||||
|
|
Loading…
Reference in New Issue