Facility Modules (Example)

This is an example facility used in the guide to customizing Hedwig for a new facility.

hedwig.facility.example.calculator_example

class hedwig.facility.example.calculator_example.ExampleCalculator(facility, id_)
ADDITION = 1
SUBTRACTION = 2
modes = {1: ('add', 'Addition'), 2: ('sub', 'Subtraction')}
version = 1
classmethod get_code()

Get the calculator “code”.

This is a short string used to uniquely identify the calculator within the facility which uses it.

get_default_facility_code()

Get the code for the facility which has the template for this calculator. This method need only be overridden if the calculator is intended to be used by multiple facilities.

get_name()
get_calc_version()
get_inputs(mode, version=None)

Get the list of calculator inputs for a given version of the calculator.

Should return a SectionedList because the base HTML template uses the by_section() method. Each value of the list is a CalculatorValue tuple.

Return SectionedList:

list of inputs

get_default_input(mode)

Get the default input values (for the current version).

convert_input_mode(mode, new_mode, input_)

Convert the inputs for one mode to form a suitable set of inputs for another mode. Only called if the mode is changed.

convert_input_version(mode, old_version, input_)

Converts the inputs from an older version so that they can be used with the current version of the calculator.

get_outputs(mode, version=None)

Get the list of calculator outputs for a given version of the calculator.

parse_input(mode, input_, defaults=None)

Parse inputs as obtained from the HTML form (typically unicode) and return values suitable for calculation (perhaps float).

If defaults are specified, these are used in place of missing values to avoid a UserError being raised. This is useful in the case of changing mode when the form has been filled in incompletely.

__call__(mode, input_)

Perform a calculation, taking an input dictionary and returning a CalculatorResult object.

The result object contains the essential output, a dictionary with entries corresponding to the list given by get_outputs. It also contains any extra output for display but which would not be stored in the database as part of the calculation result.

hedwig.facility.example.control

class hedwig.facility.example.control.ExamplePart
search_example_request(proposal_id)

Retrieve observing requests for the given proposal or proposals.

sync_example_proposal_request(proposal_id, records)

Update the observing requests for the given proposal.

hedwig.facility.example.meta

hedwig.facility.example.type

class hedwig.facility.example.type.ExampleRequest
_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ()
classmethod _make(iterable)

Make a new ExampleRequest object from a sequence or iterable

_replace(**kwds)

Return a new ExampleRequest object replacing specified fields with new values

class hedwig.facility.example.type.ExampleRequestCollection

Class to hold a collection of requests to use the Example Facility.

hedwig.facility.example.view

class hedwig.facility.example.view.Example(id_)
classmethod get_code()

Get the “code” name used to represent this facility.

classmethod get_name()

Get the name of the facility.

get_calculator_classes()

Get a tuple of calculator classes which can be used with this facility.