fairdm.core.measurement.forms#

Forms for creating and editing measurements.

Module Contents#

Classes#

MeasurementFormMixin

Mixin giving measurement model forms autocomplete fields for dataset and sample, and the location input.

MeasurementForm

Base form for measurements, which refuses to create a bare Measurement.

API#

class MeasurementFormMixin(*args, **kwargs)#

Bases: fairdm.utils.location.forms.LocationFormMixin, fairdm.core.forms.ManagerOnlyFieldsMixin

Mixin giving measurement model forms autocomplete fields for dataset and sample, and the location input.

Use it with the ModelForm of a concrete measurement type. The dataset choices are limited to the datasets the requesting user may edit. For a measurement that already exists the dataset is offered only to someone who can manage the measurement. The location input is there only when the type’s fields list location. See docs/developers/how-to/add-a-measurement-type.md.

Args: *args: Positional arguments passed to ModelForm. **kwargs: Keyword arguments passed to ModelForm. request is removed first and is used to limit the dataset choices.

Example: ```python class XRFMeasurementForm(MeasurementFormMixin, forms.ModelForm): class Meta: model = XRFMeasurement fields = [“name”, “dataset”, “sample”, “element”, “concentration_ppm”]

form = XRFMeasurementForm(request=request, data=request.POST)
```

Initialization

manager_only_fields#

(‘dataset’,)

class MeasurementForm(*args, **kwargs)#

Bases: fairdm.core.measurement.forms.MeasurementFormMixin, django.forms.ModelForm

Base form for measurements, which refuses to create a bare Measurement.

Measurement is a concrete polymorphic base with its own table, but direct instantiation is refused here and in Measurement.clean(). Build forms for concrete measurement types on MeasurementFormMixin instead. This class exists for registry auto-generation and as a reference implementation.

Initialization

image#

‘ImageField(…)’

class Meta#
model#

None

fields#

[‘name’, ‘dataset’, ‘sample’, ‘image’, ‘tags’]

widgets#

None

help_texts#

None

clean()#

Refuse to create a bare Measurement.