def to_xml_2(form, root): from tao.xml_util import find_or_create, child_element selected_type, selected_filter = form.cleaned_data['filter'].split('-') if selected_filter == NO_FILTER: return filter_parameter = None filter_type = '' units = '' if selected_type == 'D': filter_parameter = DataSetProperty.objects.get(pk=selected_filter) filter_type = filter_parameter.name units = filter_parameter.units elif selected_type == 'B': selected_filter, selected_extension = selected_filter.split('_') filter_parameter = datasets.band_pass_filter(selected_filter) filter_type = str(filter_parameter.filter_id) + '_' + selected_extension units = 'bpunits' rf_elem = find_or_create(root, 'record-filter') child_element(rf_elem, 'module-version', text=RecordFilterForm.MODULE_VERSION) filter_elem = find_or_create(rf_elem, 'filter') child_element(filter_elem, 'filter-attribute', filter_type) filter_min = form.cleaned_data['min'] filter_max = form.cleaned_data['max'] default_filter = form.ui_holder.dataset.default_filter_field if default_filter is not None and filter_parameter.id == default_filter.id and filter_min is None and filter_max is None: filter_min = form.ui_holder.dataset.default_filter_min filter_max = form.ui_holder.dataset.default_filter_max child_element(filter_elem, 'filter-min', text=str(filter_min), units=units) child_element(filter_elem, 'filter-max', text=str(filter_max), units=units)
def to_xml_2(form, root): if form.apply_mock_image: from tao.xml_util import find_or_create, child_element # Prepare the base element. mi_elem = find_or_create(root, 'skymaker', id=FormsGraph.MOCK_IMAGE_ID) child_element(mi_elem, 'module-version', text=Form.MODULE_VERSION) child_element(child_element(mi_elem, 'parents'), 'item', text=FormsGraph.BANDPASS_FILTER_ID) # Create a list element for the images. list_elem = child_element(mi_elem, 'images') # Iterate over the forms, creating entries. Remember there will always # be one extra empty form, so don't include it. assert form.total_form_count() > 0, 'Internal error, this should never happen!' for ii, sub in enumerate(form): sub_elem = child_element(list_elem, 'item') for field, val in sub.cleaned_data.iteritems(): if field[-9:] == 'mag_field': item_id, item_extension = val.split('_') op = datasets.band_pass_filter(item_id) child_element(sub_elem, field, op.filter_id + '_' + item_extension) else: child_element(sub_elem, field, str(val))
def to_xml_2(form, root): apply_sed = form.cleaned_data.get('apply_sed') output_format = form.ui_holder.cleaned_data('output_format', 'supported_formats') if apply_sed: from tao.xml_util import find_or_create, child_element, add_encoding sed_elem = find_or_create(root, 'sed', id=FormsGraph.SED_ID) child_element(sed_elem, 'module-version', text=Form.MODULE_VERSION) # Add a hard-coded connection to the light-cone and the CSV output. elem = child_element(sed_elem, 'parents') child_element(elem, 'item', text=FormsGraph.LIGHT_CONE_ID) child_element(child_element(find_or_create(root, output_format, id=FormsGraph.OUTPUT_ID), 'parents'), 'item', text=FormsGraph.BANDPASS_FILTER_ID) single_stellar_population_model = tao_models.StellarModel.objects.get( pk=form.cleaned_data['single_stellar_population_model']) add_encoding(sed_elem, single_stellar_population_model.encoding) # Create an independant filter module. filter_elem = find_or_create(root, 'filter', id=FormsGraph.BANDPASS_FILTER_ID) child_element(filter_elem, 'module-version', text=Form.MODULE_VERSION) apply_dust = form.cleaned_data['apply_dust'] if apply_dust: dust_elem = find_or_create(root, 'dust', id=FormsGraph.DUST_ID) child_element(dust_elem, 'module-version', text=Form.MODULE_VERSION) child_element(child_element(dust_elem, 'parents'), 'item', text=FormsGraph.SED_ID) selected_dust_model = tao_models.DustModel.objects.get(pk=form.cleaned_data['select_dust_model']) child_element(dust_elem, 'model', text=selected_dust_model.name) # Parent of the dust module is either the SED module or, if selected, the dust module child_element(child_element(filter_elem, 'parents'), 'item', text=FormsGraph.DUST_ID) else: child_element(child_element(filter_elem, 'parents'), 'item', text=FormsGraph.SED_ID) # Find the CSV output element or create it, and get access to # the fields tag. fields_elem = find_or_create(find_or_create(root, output_format, id=FormsGraph.OUTPUT_ID), 'fields') band_pass_filters = form.cleaned_data['band_pass_filters'] if len(band_pass_filters) > 0: bf_elem = child_element(filter_elem, 'bandpass-filters') added = {} selected = {} for item in band_pass_filters: item_id, item_extension = item.split('_') if item_id not in selected: selected[item_id] = [] selected[item_id].append(item_extension) for item in band_pass_filters: item_id, item_extension = item.split('_') op = datasets.band_pass_filter(item_id) if item_id not in added: child_element(bf_elem, 'item', text=op.filter_id, label=op.label, description=op.description, selected=",".join(selected[item_id])) added[item_id] = True child_element(fields_elem, 'item', text=op.filter_id + '_' + item_extension, label=op.label + ' (' + item_extension.capitalize() + ')') else: from tao.xml_util import find_or_create, child_element # No SED module, connect the output to the light-cone module. child_element(child_element(find_or_create(root, output_format, id=FormsGraph.OUTPUT_ID), 'parents'), 'item', text=FormsGraph.LIGHT_CONE_ID)