Skip to content

Commit

Permalink
Bug Fix, Individual as String is not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankirstein committed Aug 21, 2015
1 parent 3ab7c3e commit f26b84d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion apps/datasetmanager/dataset_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def from_json(data):
obj = json.loads(data, object_pairs_hook=OrderedDict)
return DatasetData(data=obj)

def validate(self, time_start, time_end):
def validate(self, time_start, time_end, class_id):
if not isinstance(self.data, dict):
raise ValidationError("Data field needs to be a dictionary.")

Expand All @@ -69,6 +69,10 @@ def validate(self, time_start, time_end):
raise ValidationError("Element %d of data.table has not 'row' field." % index)
if 'individual' not in value:
raise ValidationError("Element %d of data.table has not 'individual' field." % index)
if class_id != 7:
if not isinstance(value['individual'], int):
raise ValidationError("Individual of Element %d of data.table is not an integer. "
"Please use class 'custom' to provide strings." % index)
if 'values' not in value:
raise ValidationError("Element %d of data.table has not 'values' field." % index)
if not isinstance(value['values'], dict):
Expand Down
6 changes: 3 additions & 3 deletions apps/datasetmanager/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def field_from_native(self, data, files, field_name, into):
if 'data' not in data:
raise ValidationError("Field 'data' is required.")

dataset = DatasetData(data=data[field_name])
dataset.validate(into['time_start'], into['time_end'])

if 'class_id' not in data:
raise ValidationError('Field class_id is missing.')

dataset = DatasetData(data=data[field_name])
dataset.validate(into['time_start'], into['time_end'], data['class_id'])

if data['class_id'] == 7:
dataset.create_individuals()

Expand Down

0 comments on commit f26b84d

Please # to comment.