Beispiel #1
0
 def get_context_data(self, *args, **kwargs):
     context = super().get_context_data(*args, **kwargs)
     context['form'] = AddProductToGroupForm()
     service_class = get_service_class(self.object.facility)
     context['data_products'] = service_class().all_data_products(
         self.object)
     newest_image = None
     for data_product in context['data_products']['saved']:
         newest_image = data_product if (not newest_image or data_product.modified > newest_image.modified) and \
             data_product.get_file_extension() == '.fits' else newest_image
     if newest_image:
         context['image'] = newest_image.get_image_data()
     data_timestamp = self.get_object().scheduled_end if self.get_object().scheduled_end \
         else self.get_object().created
     data_product_upload_form = DataProductUploadForm(
         initial={
             'observation_record':
             self.get_object(),
             'observation_timestamp':
             data_timestamp,
             'facility':
             self.get_object().facility,
             'referrer':
             reverse('tom_observations:detail',
                     args=(self.get_object().id, ))
         },
         hide_target_fields=True)
     context['data_product_form'] = data_product_upload_form
     return context
Beispiel #2
0
    def get_context_data(self, *args, **kwargs):
        """
        Adds a number of items to the context object for this view, including the form for adding resulting
        ``DataProduct`` objects to a ``DataProductGroup``, the ``DataProduct`` objects associated with the
        ``ObservationRecord``, and the most recent image from this ``ObservationRecord``. It also populates the
        ``DataProductUploadForm`` hidden fields with initial data.

        :returns: context dictionary
        :rtype: dict
        """
        context = super().get_context_data(*args, **kwargs)
        context['form'] = AddProductToGroupForm()
        service_class = get_service_class(self.object.facility)
        context['editable'] = isinstance(service_class(),
                                         BaseManualObservationFacility)
        context['data_products'] = service_class().all_data_products(
            self.object)
        context['can_be_cancelled'] = self.object.status not in service_class(
        ).get_terminal_observing_states()
        newest_image = None
        for data_product in context['data_products']['saved']:
            newest_image = data_product if (not newest_image or data_product.modified > newest_image.modified) and \
                data_product.get_file_extension() == '.fits' else newest_image
        if newest_image:
            context['image'] = newest_image.get_image_data()
        data_product_upload_form = DataProductUploadForm(
            initial={
                'observation_record':
                self.get_object(),
                'referrer':
                reverse('tom_observations:detail',
                        args=(self.get_object().id, ))
            })
        context['data_product_form'] = data_product_upload_form
        return context
Beispiel #3
0
 def get_context_data(self, *args, **kwargs):
     context = super().get_context_data(*args, **kwargs)
     data_product_upload_form = DataProductUploadForm(
         initial={
             'target': self.get_object(),
             'referrer': reverse('tom_targets:detail', args=(self.get_object().id,))
         },
         hide_target_fields=False
     )
     context['data_product_form'] = data_product_upload_form
     return context
Beispiel #4
0
def upload_dataproduct(context):
    model_instance = context.get('object', None)
    object_key = ''
    if type(model_instance) == Target:
        object_key = 'target'
    elif type(model_instance) == ObservationRecord:
        object_key = 'observation_record'
    form = context.get(
        'data_product_form',
        DataProductUploadForm(initial={object_key: model_instance}))
    user = context.get('user', None)
    return {'data_product_form': form, 'user': user}
Beispiel #5
0
def upload_dataproduct(context, obj):
    user = context['user']
    initial = {}
    if isinstance(obj, Target):
        initial['target'] = obj
        initial['referrer'] = reverse('tom_targets:detail', args=(obj.id, ))
    elif isinstance(obj, ObservationRecord):
        initial['observation_record'] = obj
        initial['referrer'] = reverse('tom_observations:detail',
                                      args=(obj.id, ))
    form = DataProductUploadForm(initial=initial)
    if not settings.TARGET_PERMISSIONS_ONLY:
        if user.is_superuser:
            form.fields['groups'].queryset = Group.objects.all()
        else:
            form.fields['groups'].queryset = user.groups.all()
    return {'data_product_form': form}
Beispiel #6
0
    def get_context_data(self, *args, **kwargs):
        """
        Adds the ``DataProductUploadForm`` to the context and prepopulates the hidden fields.

        :returns: context object
        :rtype: dict
        """
        context = super().get_context_data(*args, **kwargs)
        data_product_upload_form = DataProductUploadForm(
            initial={
                'target':
                self.get_object(),
                'referrer':
                reverse('tom_targets:detail', args=(self.get_object().id, ))
            })
        context['data_product_form'] = data_product_upload_form
        return context
Beispiel #7
0
 def test_form_photometry_valid(self):
     form = DataProductUploadForm(self.photometry_form_data, self.file_data)
     self.assertTrue(form.is_valid())
Beispiel #8
0
 def test_form_spectroscopy_valid(self):
     form = DataProductUploadForm(self.spectroscopy_form_data,
                                  self.file_data)
     self.assertTrue(form.is_valid())
Beispiel #9
0
 def test_form_photometry_with_facility(self):
     self.photometry_form_data['observation_timestamp_0'] = date(2019, 6, 1)
     self.photometry_form_data['observation_timestamp_1'] = time(12, 0, 0)
     form = DataProductUploadForm(self.photometry_form_data, self.file_data)
     self.assertFalse(form.is_valid())
Beispiel #10
0
 def test_form_photometry_with_timestamp(self):
     self.photometry_form_data['facility'] = 'LCO'
     form = DataProductUploadForm(self.photometry_form_data, self.file_data)
     self.assertFalse(form.is_valid())
Beispiel #11
0
 def test_form_spectroscopy_no_facility(self):
     self.spectroscopy_form_data.pop('facility')
     form = DataProductUploadForm(self.spectroscopy_form_data,
                                  self.file_data)
     self.assertFalse(form.is_valid())
Beispiel #12
0
 def test_form_spectroscopy_no_timestamp(self):
     self.spectroscopy_form_data.pop('observation_timestamp_0')
     self.spectroscopy_form_data.pop('observation_timestamp_1')
     form = DataProductUploadForm(self.spectroscopy_form_data,
                                  self.file_data)
     self.assertFalse(form.is_valid())