def view_job(request, id): job = Job.objects.get(id=id) # xml_string = job.parameters ui_holder = UIModulesHolder(UIModulesHolder.XML, xml_parse(job.parameters.encode('utf-8'))) forms = ui_holder.forms() return render(request, 'jobs/view.html', { 'id': id, 'user': request.user, 'job': job, 'ui_holder': ui_holder, 'forms': forms, 'forms_size': len(forms)+1, })
def _get_summary_as_text(id): def get_bandpass_filter(bp_filter_id): suffix = '' if bp_filter_id.endswith('_apparent'): bp_filter_id = bp_filter_id[:-len('apparent')-1] suffix = 'apparent' elif bp_filter_id.endswith('_absolute'): bp_filter_id = bp_filter_id[:-len('absolute')-1] suffix = 'absolute' obj = BandPassFilter.objects.get(id=bp_filter_id) return obj.label + ' (' + suffix.capitalize() + ')' def format_redshit(redshift): whole_digits = int(redshift) return round(redshift, max(5-whole_digits, 0)) def display_range(label, min, max): if max is not None and min is not None: return min + ' ' + u'\u2264' + ' ' + label + ' ' + u'\u2264' + ' ' + max elif max is None: return min + ' ' + u'\u2264' + ' ' + label else: return label + ' ' + u'\u2264' + ' ' + max def display_selection(filter_id, min, max): if filter_id.startswith('D-'): filter_id = filter_id[2:] obj = DataSetProperty.objects.get(id=filter_id) return display_range(obj.label + ' (' + obj.units + ')', min, max) elif filter_id.startswith('B-'): # bandpass filter_id looks like B-12_apparent filter_id = filter_id[2:] filter_label = get_bandpass_filter(filter_id) return display_range(filter_label, min, max) else: return 'No Filter' job = Job.objects.get(pk=id) ui_holder = UIModulesHolder(UIModulesHolder.XML, xml_parse(job.parameters.encode('utf-8'))) if ui_holder.job_type == UIModulesHolder.SQL_JOB: txt_template = loader.get_template('jobs/sql_job-summary.txt') query = ui_holder.raw_data('sql_job', 'query') dataset = ui_holder.dataset simulation = dataset.simulation galaxy_model = dataset.galaxy_model output_properties = [] for output_property in ui_holder.raw_data('sql_job', 'output_properties'): output_properties = output_properties + [(output_property['label'], output_property['units'])] output_format = '' for x in output_formats(): if x['value'] == (ui_holder.raw_data('output_format', 'supported_formats')): output_format = x['text'] context = Context({ 'query': query, 'dark_matter_simulation': simulation, 'simulation_details': html2text.html2text(simulation.details), 'galaxy_model': galaxy_model, 'galaxy_model_details': html2text.html2text(galaxy_model.details), 'output_properties': output_properties, 'output_format': output_format,}) else: geometry = ui_holder.raw_data('light_cone', 'catalogue_geometry') dataset = ui_holder.dataset simulation = dataset.simulation galaxy_model = dataset.galaxy_model output_properties = [] for output_property_id in ui_holder.raw_data('light_cone', 'output_properties'): output_property = DataSetProperty.objects.get(id=output_property_id) units = html2text.html2text(output_property.units).rstrip() output_properties = output_properties + [(output_property, units)] # output_properties = [(DataSetProperty.objects.get(id=output_property_id), html2text.html2text(getattr(DataSetProperty.objects.get(id=output_property_id), 'units')).rstrip()) for output_property_id in ui_holder.raw_data('light_cone', 'output_properties')] output_format = '' for x in output_formats(): if x['value'] == (ui_holder.raw_data('output_format', 'supported_formats')): output_format = x['text'] txt_template = loader.get_template('jobs/light_cone_job-summary.txt') context = Context({ 'catalogue_geometry': geometry, 'dark_matter_simulation': simulation, 'simulation_details': html2text.html2text(simulation.details), 'galaxy_model': galaxy_model, 'galaxy_model_details': html2text.html2text(galaxy_model.details), 'output_properties': output_properties, 'record_filter': display_selection(ui_holder.raw_data('record_filter', 'filter'), ui_holder.raw_data('record_filter', 'min'), ui_holder.raw_data('record_filter', 'max')), 'output_format': output_format, }) if geometry == 'light-cone': ra_opening_angle = ui_holder.raw_data('light_cone', 'ra_opening_angle') dec_opening_angle = ui_holder.raw_data('light_cone', 'dec_opening_angle') context['ra_opening_angle'] = ra_opening_angle context['dec_opening_angle'] = dec_opening_angle context['redshift_min'] = ui_holder.raw_data('light_cone', 'redshift_min') context['redshift_max'] = ui_holder.raw_data('light_cone', 'redshift_max') context['number_of_light_cones'] = ui_holder.raw_data('light_cone', 'number_of_light_cones') context['light_cone_type'] = ui_holder.raw_data('light_cone', 'light_cone_type') else: snapshot = Snapshot.objects.get(id=ui_holder.raw_data('light_cone', 'snapshot')).redshift context['box_size'] = ui_holder.raw_data('light_cone', 'box_size') context['snapshot'] = format_redshit(snapshot) if ui_holder.raw_data('sed', 'apply_sed'): single_stellar_population_model = StellarModel.objects.get(id=ui_holder.raw_data('sed', 'single_stellar_population_model')) band_pass_ids = ui_holder.raw_data('sed', 'band_pass_filters') context['apply_sed'] = True context['ssp_name'] = single_stellar_population_model context['ssp_description'] = html2text.html2text(single_stellar_population_model.description) context['band_pass_filters'] = [get_bandpass_filter(band_pass_id) for band_pass_id in band_pass_ids] if ui_holder.raw_data('sed', 'apply_dust'): dust_model = DustModel.objects.get(id=ui_holder.raw_data('sed', 'select_dust_model')) context['dust_label'] = dust_model context['dust_model_details'] = html2text.html2text(dust_model.details) else: context['dust_label'] = 'None' else: context['apply_sed'] = False if ui_holder.raw_data('mock_image', 'apply_mock_image'): context['number_of_images'] = ui_holder.raw_data('mock_image', 'TOTAL_FORMS') images = [] for i in xrange(0, context['number_of_images']): image = {} image['fov_dec'] = ui_holder.raw_data('mock_image', '%d-fov_dec' % i) image['sub_cone'] = ui_holder.raw_data('mock_image', '%d-sub_cone' % i) image['height'] = ui_holder.raw_data('mock_image', '%d-height' % i) image['origin_ra'] = ui_holder.raw_data('mock_image', '%d-origin_ra' % i) image['min_mag'] = ui_holder.raw_data('mock_image', '%d-min_mag' % i) image['origin_dec'] = ui_holder.raw_data('mock_image', '%d-origin_dec' % i) image['width'] = ui_holder.raw_data('mock_image', '%d-width' % i) image['z_min'] = ui_holder.raw_data('mock_image', '%d-z_min' % i) image['max_mag'] = ui_holder.raw_data('mock_image', '%d-max_mag' % i) image['z_max'] = ui_holder.raw_data('mock_image', '%d-z_max' % i) image['fov_ra'] = ui_holder.raw_data('mock_image', '%d-fov_ra' % i) image['format'] = ui_holder.raw_data('mock_image', '%d-format' % i) mag_fields = ui_holder.raw_data('mock_image','%d-mag_field' % i).split('_') mag_field = BandPassFilter.objects.get(pk=mag_fields[0]).label mag_field += ' (%s)' % mag_fields[1].title() image['mag_field'] = mag_field images.append(image) context['images'] = images else: context['number_of_images'] = None return txt_template.render(context)
def index(request): user = request.user if not user.check_disk_usage_within_quota(): message = ( "Please reduce your disk usage below " + user.display_user_disk_quota() + ". " 'If you would like additional quota, please <a href="' + reverse("support_page") + '">submit</a> ' "a request with the reason for the request." ) messages.info(request, mark_safe(message)) # return jobs.index(request) return redirect(reverse("job_index")) if request.method == "POST": if len(request.FILES) > 0: parameter_file = request.FILES.itervalues().next() ui_holder = UIModulesHolder(UIModulesHolder.POST) try: if parameter_file.content_type != "text/xml": raise Exception("Wrong mime-type") params_ui_holder = UIModulesHolder(UIModulesHolder.XML, xml_parse(parameter_file.read())) message = "Parameter file '%s' uploaded successfully." % parameter_file.name messages.info(request, message) return render( request, "mock_galaxy_factory/index.html", { "forms": ui_holder.forms(), "ui_holder": params_ui_holder, "TAB_SUMMARY_ID": settings.MODULE_INDICES["summary"], }, ) except: message = "Failed to process parameter file: '%s'." % parameter_file.name messages.error(request, message) return render( request, "mock_galaxy_factory/index.html", { "forms": ui_holder.forms(), # 'ui_holder': params_ui_holder, "TAB_SUMMARY_ID": settings.MODULE_INDICES["summary"], }, ) elif "survey_presets" in request.POST: preset = SurveyPreset.objects.get(pk=request.POST.get("survey_presets")) params_ui_holder = UIModulesHolder(UIModulesHolder.XML, xml_parse(preset.parameters.encode())) ui_holder = UIModulesHolder(UIModulesHolder.POST) message = "Survey Preset '%s' loaded successfully." % preset.name messages.info(request, message) return render( request, "mock_galaxy_factory/index.html", { "forms": ui_holder.forms(), "ui_holder": params_ui_holder, "TAB_SUMMARY_ID": settings.MODULE_INDICES["summary"], }, ) else: ui_holder = UIModulesHolder(UIModulesHolder.POST, request.POST) response_dict = {} response_dict["job_submitted"] = False if ui_holder.validate(): UserModel = get_user_model() user = UserModel.objects.get(username=request.user.username) job_description = request.POST.get("job-description") response_dict["job_id"] = workflow.save(user, ui_holder, job_description).pk messages.info(request, _(settings.INITIAL_JOB_MESSAGE % models.initial_job_status().lower())) response_dict["job_submitted"] = True response_dict["next_page"] = reverse("job_index") else: response_dict["errors"] = ui_holder.errors # Simple answer the errors dictionary # If the dictionary is empty, the client knows the job was created successfully response = json.dumps(response_dict) callback = request.GET.get("callback", None) if callback is not None: response = "%s(%s)" % (callback, response) return HttpResponse(response, mimetype="application/json") # Assume GET ui_holder = UIModulesHolder(UIModulesHolder.POST) return render( request, "mock_galaxy_factory/index.html", { "forms": ui_holder.forms(), # 'forms_size' : len(ui_holder.forms())+1, "TAB_SUMMARY_ID": settings.MODULE_INDICES["summary"], }, )