def validate_element_data(cls, request, element_name): """overriding the base class method""" if element_name.lower() not in [el_name.lower() for el_name in cls.get_supported_element_names()]: err_msg = "{} is nor a supported metadata element for NetCDF file type" err_msg = err_msg.format(element_name) return {'is_valid': False, 'element_data_dict': None, "errors": err_msg} element_name = element_name.lower() if element_name == 'variable': form_data = {} for field_name in VariableValidationForm().fields: try: # when the request comes from the UI, the variable attributes have a prefix of # '-' matching_key = [key for key in request.POST if '-' + field_name in key][0] except IndexError: if field_name in request.POST: matching_key = field_name else: continue form_data[field_name] = request.POST[matching_key] element_form = VariableValidationForm(form_data) elif element_name == 'originalcoverage': element_form = OriginalCoverageForm(data=request.POST) elif element_name == 'coverage' and 'start' not in request.POST: element_form = CoverageSpatialForm(data=request.POST) else: # here we are assuming temporal coverage element_form = CoverageTemporalForm(data=request.POST) if element_form.is_valid(): return {'is_valid': True, 'element_data_dict': element_form.cleaned_data} else: return {'is_valid': False, 'element_data_dict': None, "errors": element_form.errors}
def validate_element_data(cls, request, element_name): """overriding the base class method""" if element_name.lower() not in [el_name.lower() for el_name in cls.get_supported_element_names()]: err_msg = "{} is nor a supported metadata element for Geo Raster file type" err_msg = err_msg.format(element_name) return {'is_valid': False, 'element_data_dict': None, "errors": err_msg} element_name = element_name.lower() if element_name == 'bandinformation': form_data = {} for field_name in BandInfoValidationForm().fields: matching_key = [key for key in request.POST if '-' + field_name in key][0] form_data[field_name] = request.POST[matching_key] element_form = BandInfoValidationForm(form_data) elif element_name == 'coverage' and 'start' not in request.POST: element_form = CoverageSpatialForm(data=request.POST) else: # element_name must be coverage # here we are assuming temporal coverage element_form = CoverageTemporalForm(data=request.POST) if element_form.is_valid(): return {'is_valid': True, 'element_data_dict': element_form.cleaned_data} else: return {'is_valid': False, 'element_data_dict': None, "errors": element_form.errors}
def validate_element_data(cls, request, element_name): """overriding the base class method""" if element_name.lower() not in [el_name.lower() for el_name in cls.get_supported_element_names()]: err_msg = "{} is nor a supported metadata element for Generic file type" err_msg = err_msg.format(element_name) return {'is_valid': False, 'element_data_dict': None, "errors": err_msg} element_name = element_name.lower() if element_name == "coverage": if 'type' in request.POST: if request.POST['type'].lower() == 'point' or request.POST['type'].lower() == 'box': element_form = CoverageSpatialForm(data=request.POST) else: element_form = CoverageTemporalForm(data=request.POST) else: element_form = CoverageTemporalForm(data=request.POST) else: element_form = CoverageTemporalForm(data=request.POST) if element_form.is_valid(): return {'is_valid': True, 'element_data_dict': element_form.cleaned_data} else: return {'is_valid': False, 'element_data_dict': None, "errors": element_form.errors}
def validate_element_data(cls, request, element_name): """overriding the base class method""" if element_name.lower() not in [ el_name.lower() for el_name in cls.get_supported_element_names() ]: err_msg = "{} is nor a supported metadata element for Generic file type" err_msg = err_msg.format(element_name) return { 'is_valid': False, 'element_data_dict': None, "errors": err_msg } element_name = element_name.lower() if element_name == "coverage": if 'type' in request.POST: if request.POST['type'].lower( ) == 'point' or request.POST['type'].lower() == 'box': element_form = CoverageSpatialForm(data=request.POST) else: element_form = CoverageTemporalForm(data=request.POST) else: element_form = CoverageTemporalForm(data=request.POST) else: element_form = CoverageTemporalForm(data=request.POST) if element_form.is_valid(): return { 'is_valid': True, 'element_data_dict': element_form.cleaned_data } else: return { 'is_valid': False, 'element_data_dict': None, "errors": element_form.errors }