Views

class tom_observations.views.ObservationFilter(*args, **kwargs)

Defines the available fields for filtering the list of ObservationRecord objects.

The “status” filter is populated dynamically via list comprehension here in the __init__ (at runtime). This is important because the ObservationRecord db table doesn’t necessarily exist at Class-interpretation-time

class tom_observations.views.ObservationListView(**kwargs)

View that displays all ObservationRecord objects.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

filterset_class

alias of ObservationFilter

model

alias of ObservationRecord

get_queryset(*args, **kwargs)

Gets the set of ObservationRecord objects associated with the targets that the user is authorized to view.

Returns:

set of ObservationRecords

Return type:

QuerySet

get(request, *args, **kwargs)

Handles the GET requests to this view. If update_status is passed in the query parameters, calls the updatestatus management command to query for new statuses for ObservationRecord objects.

Parameters:

request (HTTPRequest) – request object for this GET request

class tom_observations.views.ObservationCreateView(**kwargs)

View for creation/submission of an observation. Requires authentication.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

dispatch(request, *args, **kwargs)

Figure out what HTTP method (GET, POST, etc) should be called to handle this request.

Here, we extend the method to attach the Facility class to the View so we don’t have to create more than one instances of it. So, instantiate the facility class once and store it on the view instance for the duration of the request-response cycle.

get_template_names() List[str]

Override the base class method to ask the Facility if it has specified a Facility-specific template to use. If so, put it at the front of the returned list of template_names.

get_target_id()

Parses the target id for the given observation from the query parameters.

Returns:

id of the target for observing

Return type:

int

get_target()

Gets the target for observing from the database

Returns:

target for observing

Return type:

Target

get_facility()

Gets the facility from which the target is being observed from the query parameters

Returns:

facility name

Return type:

str

get_facility_class()

Gets the facility interface class

Returns:

facility class name

Return type:

str

get_context_data(**kwargs)

Adds the available observation types for the observing facility to the context object.

Returns:

context dictionary

Return type:

dict

get_form_class(observation_type=None)

Gets the observation form class for the facility and selected observation type in the query parameters.

Returns:

observation form

Return type:

subclass of GenericObservationForm

get_form(form_class=None)

Gets an instance of the form appropriate for the request.

Returns:

observation form

Return type:

subclass of GenericObservationForm

get_initial()

Populates the observation form with initial data including the id of the target to be observed, the facility at which the observation will take place, and the observation type desired.

Returns:

initial form data

Return type:

dict

get_form_kwargs() dict[str, Any]

Return the keyword arguments for instantiating the form.

Here, we extend the super-class method to add the facility instance: call the super() and then add the facility to the form kwargs. The facility already has user context set via set_user() in dispatch().

post(request, *args, **kwargs)

Handles the POST request to the view.

This method is responsible for processing the form submission. It instantiates the form with the POST data and files, and then checks if the form is valid. If the form is valid, it calls form_valid(); otherwise, it calls form_invalid().

We override this method to handle a TypeError that may occur when instantiating the form. Some forms may not accept the ‘user’ keyword argument. In this case, we catch the TypeError, remove the ‘user’ from the keyword arguments, and try to instantiate the form again.

form_valid(form)

Runs after form validation. Submits the observation to the desired facility and creates an associated ObservationRecord, then redirects to the detail page of the target to be observed.

If the facility returns more than one record, a group is created and all observation records from the request are added to it.

Parameters:

form (subclass of GenericObservationForm) – form containing observating request parameters

class tom_observations.views.ObservationRedirectView(**kwargs)

This view redirects the user to an outside facility using the URL provided by the facility’s redirect_url method (must be a RedirectFacility)

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

class tom_observations.views.ObservationRecordUpdateView(**kwargs)

This view allows for the updating of the observation id, which will eventually be expanded to more fields.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

model

alias of ObservationRecord

class tom_observations.views.ObservationCallbackView(**kwargs)

This is the view that handles the user returning from the facility back to the TOM. The query parameters must include facility, target_id and observation_id as these are the required parameters for creating an ObservationRecord. Once an ObservationRecord object is created, permissions are assigned to it for the current user, and the user is redirected to the observation detail page.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

class tom_observations.views.AddExistingObservationView(**kwargs)

View for associating a pre-existing observation with a target. Requires authentication.

The GET view returns a confirmation page for adding duplicate ObservationRecords. Two duplicates are any two ObservationRecords with the same target_id, facility, and observation_id.

The POST view validates the form and redirects to the confirmation page if the confirm flag isn’t set.

This view is intended to be navigated to via the existing_observation_button templatetag, as the AddExistingObservationForm has a hidden confirmation checkbox selected by default.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

form_class

alias of AddExistingObservationForm

get_initial()

Populates the ManualObservationForm hidden field for target id with the id from the specified target.

Returns:

initial form data

Return type:

dict

form_valid(form)

Runs after form validation. Creates a new ObservationRecord associated with the specified target and facility.

class tom_observations.views.ObservationRecordDetailView(**kwargs)

View for displaying the details of an ObservationRecord object.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

model

alias of ObservationRecord

get_queryset(*args, **kwargs)

Gets the set of ObservationRecord objects associated with targets that the current user is authorized to view.

Returns:

set of ObservationRecords

Return type:

QuerySet

get_context_data(*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

Return type:

dict

class tom_observations.views.ObservationGroupCreateView(**kwargs)

View that handles the creation of ObservationGroup objects. Requires authentication.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

model

alias of ObservationGroup

form_valid(form)

Runs after form validation. Saves the observation group and assigns the user’s permissions to the group.

Parameters:

form (django.forms.ModelForm) – Form data for observation group creation

class tom_observations.views.ObservationGroupListView(**kwargs)

View that handles the display of ObservationGroup. Requires authorization.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

model

alias of ObservationGroup

class tom_observations.views.ObservationGroupDeleteView(**kwargs)

View that handles the deletion of ObservationGroup objects. Requires authorization.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

model

alias of ObservationGroup

class tom_observations.views.ObservationTemplateFilter(data=None, queryset=None, *, request=None, prefix=None)

Defines the available fields for filtering the list of ObservationTemplate objects.

class tom_observations.views.ObservationTemplateListView(**kwargs)

Displays the observing strategies that exist in the TOM.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

model

alias of ObservationTemplate

filterset_class

alias of ObservationTemplateFilter

class tom_observations.views.ObservationTemplateCreateView(**kwargs)

Displays the form for creating a new observation template. Uses the observation template form specified in the respective facility class.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

class tom_observations.views.ObservationTemplateUpdateView(**kwargs)

View for updating an existing observation template.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

class tom_observations.views.ObservationTemplateDeleteView(**kwargs)

Deletes an observation template.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

model

alias of ObservationTemplate

tom_observations.views.render_facility_status_list(request, *args, **kwargs)

View function for rendering the facility status partial.