Views#

class tom_observations.views.AddExistingObservationView(**kwargs)[source]#

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.

form_class#

alias of AddExistingObservationForm

form_valid(form)[source]#

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

get_form(form_class=None)[source]#

Return an instance of the form to be used in this view.

get_initial()[source]#

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

Returns:

initial form data

Return type:

dict

class tom_observations.views.FacilityStatusView(**kwargs)[source]#
class tom_observations.views.ObservationCallbackView(**kwargs)[source]#

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.

class tom_observations.views.ObservationCreateView(**kwargs)[source]#

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

dispatch(request, *args, **kwargs)[source]#

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.

form_valid(form)[source]#

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

get_context_data(**kwargs)[source]#

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

Returns:

context dictionary

Return type:

dict

get_facility()[source]#

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

Returns:

facility name

Return type:

str

get_facility_class()[source]#

Gets the facility interface class

Returns:

facility class name

Return type:

str

get_form(form_class=None)[source]#

Gets an instance of the form appropriate for the request.

Returns:

observation form

Return type:

subclass of GenericObservationForm

get_form_class(observation_type=None)[source]#

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_kwargs() dict[str, Any][source]#

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().

get_initial()[source]#

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_target()[source]#

Gets the target for observing from the database

Returns:

target for observing

Return type:

Target

get_target_id()[source]#

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

Returns:

id of the target for observing

Return type:

int

get_template_names() List[str][source]#

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.

post(request, *args, **kwargs)[source]#

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.

class tom_observations.views.ObservationFilter(*args, **kwargs)[source]#

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

class tom_observations.views.ObservationGroupCreateView(**kwargs)[source]#

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

form_valid(form)[source]#

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

model#

alias of ObservationGroup

class tom_observations.views.ObservationGroupDeleteView(**kwargs)[source]#

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

model#

alias of ObservationGroup

class tom_observations.views.ObservationGroupListView(**kwargs)[source]#

View that handles the display of ObservationGroup. Requires authorization.

model#

alias of ObservationGroup

class tom_observations.views.ObservationListView(**kwargs)[source]#

View that displays all ObservationRecord objects.

filterset_class#

alias of ObservationFilter

get(request, *args, **kwargs)[source]#

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

get_queryset(*args, **kwargs)[source]#

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

Returns:

set of ObservationRecords

Return type:

QuerySet

model#

alias of ObservationRecord

class tom_observations.views.ObservationRecordCancelView(**kwargs)[source]#
class tom_observations.views.ObservationRecordDetailView(**kwargs)[source]#

View for displaying the details of an ObservationRecord object.

get_context_data(
*args,
**kwargs,
)[source]#

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

get_queryset(*args, **kwargs)[source]#

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

Returns:

set of ObservationRecords

Return type:

QuerySet

model#

alias of ObservationRecord

class tom_observations.views.ObservationRecordUpdateView(**kwargs)[source]#

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

get_success_url()[source]#

Return the URL to redirect to after processing a valid form.

model#

alias of ObservationRecord

class tom_observations.views.ObservationRedirectView(**kwargs)[source]#

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

class tom_observations.views.ObservationTemplateCreateView(**kwargs)[source]#

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

form_valid(form)[source]#

If the form is valid, redirect to the supplied URL.

get_context_data(
*args,
**kwargs,
)[source]#

Insert the form into the context dict.

get_form(form_class=None)[source]#

Return an instance of the form to be used in this view.

get_form_class()[source]#

Return the form class to use.

get_initial()[source]#

Return the initial data to use for forms on this view.

class tom_observations.views.ObservationTemplateDeleteView(**kwargs)[source]#

Deletes an observation template.

model#

alias of ObservationTemplate

class tom_observations.views.ObservationTemplateFilter(
data=None,
queryset=None,
*,
request=None,
prefix=None,
)[source]#

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

class tom_observations.views.ObservationTemplateListView(**kwargs)[source]#

Displays the observing strategies that exist in the TOM.

filterset_class#

alias of ObservationTemplateFilter

get_context_data(
*args,
**kwargs,
)[source]#

Get the context for this view.

model#

alias of ObservationTemplate

class tom_observations.views.ObservationTemplateUpdateView(**kwargs)[source]#

View for updating an existing observation template.

form_valid(form)[source]#

If the form is valid, redirect to the supplied URL.

get_form(form_class=None)[source]#

Return an instance of the form to be used in this view.

get_form_class()[source]#

Return the form class to use.

get_initial()[source]#

Return the initial data to use for forms on this view.

tom_observations.views.render_facility_status_list(request, *args, **kwargs)[source]#

View function for rendering the facility status partial.