def test_galaxy_model_choices(self): from tao.datasets import galaxy_model_choices self.assertEqual(0, len(galaxy_model_choices(1))) s1 = SimulationFactory.create(id=1) s2 = SimulationFactory.create(id=2) g1 = GalaxyModelFactory.create(id=1, name='boo') g2 = GalaxyModelFactory.create(id=2, name='aoo') g3 = GalaxyModelFactory.create(id=3, name='coo') DataSetFactory.create(simulation=s1, galaxy_model=g1) DataSetFactory.create(simulation=s2, galaxy_model=g2) DataSetFactory.create(simulation=s1, galaxy_model=g3) self.assertEqual([ (2, u'aoo', {}), (1, u'boo', {}), (3, u'coo', {}) ], galaxy_model_choices(s1.id))
def __init__(self, *args, **kwargs): self.ui_holder = args[0] super(Form, self).__init__(*args[1:], **kwargs) if self.is_bound: # We need to load the valid choices for validation gmid = self.data[self.prefix + '-galaxy_model'] sid = self.data[self.prefix + '-dark_matter_simulation'] dataset_id = tao_models.DataSet.objects.get(galaxy_model_id=gmid, simulation_id=sid).pk dms_choices = datasets.dark_matter_simulation_choices() gm_choices = datasets.galaxy_model_choices(sid) snapshot_choices = datasets.snapshot_choices(dataset_id) if self.data[self.prefix + '-catalogue_geometry'] == 'light-cone' and \ self.prefix + '-light_cone_type' in self.data and \ self.data[self.prefix + '-light_cone_type'] == 'random' and\ self.prefix + '-rng_seeds' in self.data: self.fields['rng_seeds'].initial = self.data[self.prefix + '-rng_seeds'] elif self.data[self.prefix + '-catalogue_geometry'] == 'box' and \ self.prefix + '-rng_seed' in self.data: self.fields['rng_seed'].initial = self.data[self.prefix + '-rng_seed'] else: # The choices should be empty, since they are loaded in the wizard # output_choices is here until Carlos sets up the View Model sid = datasets.dark_matter_simulation_choices()[0][0] dataset_id = datasets.galaxy_model_choices(sid)[0][0] dms_choices = [] gm_choices = [] snapshot_choices = [(None, None, {"data-bind" : "value: $data, text: catalogue.modules.light_cone.format_redshift($data.fields.redshift)"})] objs = datasets.output_choices(dataset_id) output_choices = [(x.id, x.label) for x in objs] self.fields['dark_matter_simulation'] = ChoiceFieldWithOtherAttrs(choices=dms_choices) # AKG: I think that galaxy_model and dark_matter_simulation should follow the snapshot pattern. # Still to be determined self.fields['galaxy_model'] = ChoiceFieldWithOtherAttrs(choices=gm_choices) self.fields['snapshot'] = ChoiceFieldWithOtherAttrs(required=False, label='Redshift', choices=snapshot_choices) self.fields['number_of_light_cones'] = forms.IntegerField(label=_('Select the number of light-cones:'), required=False, initial='1', widget=SpinnerWidget) self.fields['output_properties'] = bf_fields.forms.MultipleChoiceField(required=True, choices=output_choices, widget=TwoSidedSelectWidget) for field_name in Form.SEMIREQUIRED_FIELDS: self.fields[field_name].semirequired = True self.context = { 'simulations': tao_models.Simulation.objects.all(), 'data_sets': tao_models.DataSet.objects.select_related('galaxy_model').all(), } # Knockout.js data bindings self.fields['catalogue_geometry'].widget.attrs['data-bind'] = 'options: catalogue_geometries, value: catalogue_geometry, optionsText: function(i) { return i.name }' self.fields['dark_matter_simulation'].widget.attrs['data-bind'] = 'options: dark_matter_simulations, value: dark_matter_simulation, optionsText: function(i) { return i.fields.name}, event: {change: function() { box_size(dark_matter_simulation().fields.box_size); }}' self.fields['galaxy_model'].widget.attrs['data-bind'] = 'options: galaxy_models, value: galaxy_model, optionsText: function(i) { return i.fields.name }' self.fields['ra_opening_angle'].widget.attrs['data-bind'] = 'value: ra_opening_angle' self.fields['dec_opening_angle'].widget.attrs['data-bind'] = 'value: dec_opening_angle' self.fields['box_size'].widget.attrs['data-bind'] = 'value: box_size' self.fields['snapshot'].widget.attrs['data-bind'] = 'foreach: snapshots, value: snapshot' self.fields['redshift_min'].widget.attrs['data-bind'] = 'value: redshift_min' self.fields['redshift_max'].widget.attrs['data-bind'] = 'value: redshift_max' self.fields['light_cone_type'].widget.attrs['data-bind'] = 'checked: light_cone_type' self.fields['number_of_light_cones'].widget.attrs['spinner_bind'] = 'spinner: number_of_light_cones, spinnerOptions: {max: maximum_number_of_light_cones}, error_check: number_of_light_cones, error_check_nopop: true' self.fields['number_of_light_cones'].widget.attrs['spinner_message'] = "html: number_of_light_cones_msg()" self.fields['output_properties'].widget.attrs['ko_data'] = {'widget':'output_properties_widget','value':'output_properties'} self.fields['rng_seed'].widget.attrs['data-bind'] = 'value: rng_seed' self.fields['rng_seeds'].widget.attrs['data-bind'] = 'options: rng_seeds, selectedOptions: rng_seeds'