@@ -74,7 +74,7 @@ Now add some code to this file to create a new observation module:
7474 name = ' CustomOCS'
7575 observation_forms = {
7676 ' Instrument1' : Instrument1ObservationForm,
77- ' Spectra' : SpectraObservationForm
77+ ' Spectra' : SpectraObservationForm
7878 }
7979
8080 So what does the above code do?
@@ -156,7 +156,7 @@ by subclassing the base class of the full OCS observation form:
156156 # The init method is where you will define fields, since the field names are
157157 # set based on the number of configurations and instrument configurations our
158158 # form supports. You can also remove base fields here if you don't want them
159- # in your form.
159+ # in your form.
160160 for j in range (self .facility_settings.get_setting(' max_configurations' )):
161161 for i in range (self .facility_settings.get_setting(' max_instrument_configs' )):
162162 self .fields[f ' c_ { j+ 1 } _ic_ { i+ 1 } _defocus ' ] = forms.IntegerField(
@@ -192,8 +192,8 @@ by subclassing the base class of the full OCS observation form:
192192 return Instrument1InstrumentConfigLayout
193193
194194 def _build_instrument_config (self , instrument_type , configuration_id , id ):
195- # This is called when submitting or validating the form, and it constructs the
196- # payload to send to the OCS observation portal. You can get the payload with
195+ # This is called when submitting or validating the form, and it constructs the
196+ # payload to send to the OCS observation portal. You can get the payload with
197197 # base fields and then add your new fields in here.
198198 instrument_config = super ()._build_instrument_config(instrument_type, configuration_id, id )
199199 if self .cleaned_data.get(f ' c_ { j+ 1 } _ic_ { i+ 1 } _readout_mode ' ):
@@ -251,8 +251,8 @@ the full OCS observation form: ``tom_observations.facilities.ocs.OCSFullObservat
251251 ),
252252 css_class = ' form-row'
253253 )
254- )
255-
254+ )
255+
256256 def get_final_ic_items (self , config_instance , instance ):
257257 # This piece of layout will be added at the end of the base Instrument Config
258258 # Layout. There is also a method that could be overridden to add to the beginning,
@@ -319,7 +319,7 @@ the full OCS observation form: ``tom_observations.facilities.ocs.OCSFullObservat
319319 return SpectrographConfigurationLayout
320320
321321 def _build_acquisition_config (self , configuration_id ):
322- # This is called when submitting or validating the form, and it constructs the
322+ # This is called when submitting or validating the form, and it constructs the
323323 # acquisition config payload. Here we will add our extra fields into the payload
324324 acquisition_config = super ()._build_acquisition_config(configuration_id)
325325 if self .cleaned_data.get(f ' c_ { configuration_id} _acquisition_mode ' ):
@@ -337,7 +337,7 @@ the full OCS observation form: ``tom_observations.facilities.ocs.OCSFullObservat
337337 return acquisition_config
338338
339339The above code should define a form which only has spectrograph instruments, and adds three new
340- fields to the `acquisition_config` section of the form.
340+ fields to the `acquisition_config` section of the form.
341341
342342Now that you have defined both new forms, your new OCS - based facility module should be complete!
343343Try reloading your TOM and navigating to the details page for a specific Target. You should see
@@ -403,7 +403,7 @@ class, start by subclassing ``OCSSettings`` like this:
403403 ' elevation' : 1804
404404 },
405405 }
406-
406+
407407 def get_weather_urls(self ):
408408 # Returns a dictionary of sites with weather urls for retrieving weather data for each site
409409 return {
@@ -420,7 +420,7 @@ class, start by subclassing ``OCSSettings`` like this:
420420 name = ' CustomOCS'
421421 observation_forms = {
422422 ' Instrument1' : Instrument1ObservationForm,
423- ' Spectra' : SpectraObservationForm
423+ ' Spectra' : SpectraObservationForm
424424 }
425425
426426 def __init__ (self , facility_settings = CustomOCSSettings(' CustomOCS' )):
@@ -432,3 +432,34 @@ class. Please review
432432`the base OCSSettings class < https:// github.com/ TOMToolkit/ tom_base/ blob/ dev/ tom_observations/ facilities/ ocs.py# L23>`__
433433to see what other behaviour can be customized, including certain fields `help_text` or certain archive
434434data configuration information.
435+
436+ Redirect Faciltiies
437+ ~~~~~~~~~~~~~~~~~~~
438+
439+ Facilities that subclass `BaseRedirectObservationFacility` work differently than other facilities
440+ in that they do not provide any forms or validation logic. When a user decides to submit an observation
441+ using a redirect facility they are redirected to an outside URL where they will create an observation
442+ and be redirected back to the TOM when they are finished.
443+
444+ In order to create a Redirect Facility, you need to subclass `BaseRedirectObservationFacility` and implement the
445+ `get_redirect_url()` method. Here is a simplified example from the `LcoRedirectFacility` class :
446+
447+
448+ .. code- block:: python
449+
450+ class LCORedirectFacility(BaseRedirectObservationFacility):
451+ name = " LCORedirect"
452+
453+ def redirect_url(self , target_id, callback_url):
454+ target = get_object_or_404(Target, pk = target_id)
455+ query_params = self .target_to_query_params(target)
456+ url = f " https://observe.lco.global/create? { query_params} &redirect_uri= { callback_url} "
457+
458+ return url
459+
460+
461+ The outside website that the facility redirects to must also return the user to the specified callback_url
462+ that is passed in as part of the call to `redirect_url` . In addition, it needs to add a `observation_id`
463+ parameter to this URL which is the ID of the newly created observation on the facility side. The `target_id`
464+ and `facility` parameters must also be present, and should match the values passed in by the original
465+ callback_url.
0 commit comments