Skip to content

Commit

Permalink
Merge pull request #4744 from archesproject/4725_incorrect_prov_flag
Browse files Browse the repository at this point in the history
Allows date and domain list types to accept null values
  • Loading branch information
chiatt authored Apr 3, 2019
2 parents b726f05 + 9705be0 commit 9894a75
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions arches/app/datatypes/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,24 +254,23 @@ class DateDataType(BaseDataType):

def validate(self, value, row_number=None, source=''):
errors = []

date_formats = ['-%Y','%Y','%Y-%m-%d','%B-%m-%d','%Y-%m-%d %H:%M:%S']
valid = False
for mat in date_formats:
if value is not None:
date_formats = ['-%Y','%Y','%Y-%m-%d','%B-%m-%d','%Y-%m-%d %H:%M:%S']
valid = False
for mat in date_formats:
if valid == False:
try:
if datetime.strptime(value, mat):
valid = True
except:
valid = False
if valid == False:
try:
if datetime.strptime(value, mat):
valid = True
except:
valid = False
if valid == False:
if hasattr(settings, 'DATE_IMPORT_EXPORT_FORMAT'):
date_format = settings.DATE_IMPORT_EXPORT_FORMAT
else:
date_format = date_formats

errors.append({'type': 'ERROR', 'message': '{0} {1} is not in the correct format, make sure it is in this format: {2} or set the date format in settings.DATE_IMPORT_EXPORT_FORMAT. This data was not imported.'.format(value, row_number, date_format)})
if hasattr(settings, 'DATE_IMPORT_EXPORT_FORMAT'):
date_format = settings.DATE_IMPORT_EXPORT_FORMAT
else:
date_format = date_formats

errors.append({'type': 'ERROR', 'message': '{0} {1} is not in the correct format, make sure it is in this format: {2} or set the date format in settings.DATE_IMPORT_EXPORT_FORMAT. This data was not imported.'.format(value, row_number, date_format)})

return errors

Expand Down Expand Up @@ -1320,10 +1319,10 @@ def from_rdf(self, json_ld_node):
class DomainListDataType(BaseDomainDataType):
def validate(self, value, row_number=None, source=''):
errors = []

for v in value:
if len(models.Node.objects.filter(config__options__contains=[{"id": v}])) < 1:
errors.append({'type': 'ERROR', 'message': '{0} {1} is not a valid domain id. Please check the node this value is mapped to for a list of valid domain ids. This data was not imported.'.format(v, row_number)})
if value is not None:
for v in value:
if len(models.Node.objects.filter(config__options__contains=[{"id": v}])) < 1:
errors.append({'type': 'ERROR', 'message': '{0} {1} is not a valid domain id. Please check the node this value is mapped to for a list of valid domain ids. This data was not imported.'.format(v, row_number)})
return errors

def transform_import_values(self, value, nodeid):
Expand Down Expand Up @@ -1356,9 +1355,10 @@ def append_to_document(self, document, nodevalue, nodeid, tile, provisional=Fals

def get_display_value(self, tile, node):
new_values = []
for val in tile.data[str(node.nodeid)]:
option = self.get_option_text(node, val)
new_values.append(option)
if tile.data[str(node.nodeid)] is not None:
for val in tile.data[str(node.nodeid)]:
option = self.get_option_text(node, val)
new_values.append(option)
return ','.join(new_values)

def transform_export_values(self, value, *args, **kwargs):
Expand Down

0 comments on commit 9894a75

Please sign in to comment.