From 43547559e1fb2bd7263bd37dfe0ae1a0b5d14a5c Mon Sep 17 00:00:00 2001 From: David Collom Date: Thu, 16 Apr 2020 15:20:00 -0700 Subject: [PATCH 1/6] Fixed style error --- tom_observations/management/commands/updatestatus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tom_observations/management/commands/updatestatus.py b/tom_observations/management/commands/updatestatus.py index e80cec991..6ef98e8e6 100644 --- a/tom_observations/management/commands/updatestatus.py +++ b/tom_observations/management/commands/updatestatus.py @@ -7,7 +7,7 @@ class Command(BaseCommand): """ - Updates the status of each observation request in the TOM. Target id can be specified to update the status for all + Updates the status of each observation request in the TOM. Target id can be specified to update the status for all observations for a single target. """ From 55b9f71da07a9ff5298c952043a7eaa127749963 Mon Sep 17 00:00:00 2001 From: David Collom Date: Fri, 17 Apr 2020 08:41:06 -0700 Subject: [PATCH 2/6] Added help text to broker modules --- tom_alerts/brokers/alerce.py | 12 +++++++++- tom_alerts/brokers/gaia.py | 44 +++++++++++++++++++++++++++--------- tom_alerts/brokers/lasair.py | 24 +++++++++++++++++--- tom_alerts/brokers/scout.py | 22 +++++++++++++++--- tom_alerts/brokers/tns.py | 20 ++++++++++------ 5 files changed, 97 insertions(+), 25 deletions(-) diff --git a/tom_alerts/brokers/alerce.py b/tom_alerts/brokers/alerce.py index 57200398b..ac13371d5 100644 --- a/tom_alerts/brokers/alerce.py +++ b/tom_alerts/brokers/alerce.py @@ -1,7 +1,7 @@ import requests from django import forms -from crispy_forms.layout import Layout, Div, Fieldset +from crispy_forms.layout import HTML, Layout, Div, Fieldset from astropy.time import Time, TimezoneInfo import datetime @@ -121,6 +121,11 @@ def __init__(self, *args, **kwargs): self.fields["classrf"].choices = LATE_CHOICES self.helper.layout = Layout( + HTML(''' +

+ Please see the ALeRCE homepage for information about the ALeRCE + filters. + '''), self.common_layout, Fieldset( 'Number of Epochs', @@ -220,6 +225,11 @@ def __init__(self, *args, **kwargs): class ALeRCEBroker(GenericBroker): + """ + The ``ALeRCEBroker`` is the interface to the ALeRCE alert broker. For information regarding the ALeRCE objects + and classification, please see http://alerce.science. + """ + name = 'ALeRCE' form = ALeRCEQueryForm diff --git a/tom_alerts/brokers/gaia.py b/tom_alerts/brokers/gaia.py index 5f038bbb7..f5e5c3cf1 100644 --- a/tom_alerts/brokers/gaia.py +++ b/tom_alerts/brokers/gaia.py @@ -1,28 +1,45 @@ -from tom_alerts.alerts import GenericQueryForm, GenericAlert, GenericBroker -from tom_alerts.models import BrokerQuery -from tom_targets.models import Target -from tom_dataproducts.models import ReducedDatum -from dateutil.parser import parse -from django import forms +import json +from os import path +import requests +from requests.exceptions import HTTPError + from astropy.coordinates import SkyCoord from astropy.time import Time, TimezoneInfo import astropy.units as u -import requests -from requests.exceptions import HTTPError -import json -from os import path +from crispy_forms.layout import Fieldset, HTML, Layout +from dateutil.parser import parse +from django import forms + +from tom_alerts.alerts import GenericQueryForm, GenericAlert, GenericBroker +from tom_dataproducts.models import ReducedDatum BROKER_URL = 'http://gsaweb.ast.cam.ac.uk/alerts/alertsindex' class GaiaQueryForm(GenericQueryForm): - target_name = forms.CharField(required=False) + target_name = forms.CharField(required=False, label='Target Name') cone = forms.CharField( required=False, label='Cone Search', help_text='RA,Dec,radius in degrees' ) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper.layout = Layout( + HTML(''' +

+ Please see the Gaia homepage for a detailed + description of this broker. + '''), + self.common_layout, + Fieldset( + None, + 'target_name', + 'cone' + ) + ) + def clean(self): if len(self.cleaned_data['target_name']) == 0 and \ len(self.cleaned_data['cone']) == 0: @@ -32,6 +49,11 @@ def clean(self): class GaiaBroker(GenericBroker): + """ + The ``GaiaBroker`` is the interface to the Gaia alert broker. For information regarding the Gaia Science Alerts + Project, please see http://gsaweb.ast.cam.ac.uk/alerts/about. + """ + name = 'Gaia' form = GaiaQueryForm diff --git a/tom_alerts/brokers/lasair.py b/tom_alerts/brokers/lasair.py index ee21f8e54..75a144947 100644 --- a/tom_alerts/brokers/lasair.py +++ b/tom_alerts/brokers/lasair.py @@ -1,16 +1,34 @@ +import requests + +from crispy_forms.layout import Fieldset, HTML, Layout +from django import forms + from tom_alerts.alerts import GenericQueryForm, GenericAlert, GenericBroker from tom_targets.models import Target -from django import forms -import requests LASAIR_URL = 'https://lasair.roe.ac.uk' class LasairBrokerForm(GenericQueryForm): - name = forms.CharField(required=True) cone = forms.CharField(required=False, label='Object Cone Search', help_text='Object RA and Dec') sqlquery = forms.CharField(required=False, label='Freeform SQL query', help_text='SQL query') + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper.layout = Layout( + HTML(''' +

+ Please see the Lasair website for more detailed + instructions on querying the broker. + '''), + self.common_layout, + Fieldset( + None, + 'cone', + 'sqlquery' + ), + ) + def get_lasair_object(objectId): url = LASAIR_URL + '/object/' + objectId + '/json/' diff --git a/tom_alerts/brokers/scout.py b/tom_alerts/brokers/scout.py index 1efa923e4..e4cb29fe4 100644 --- a/tom_alerts/brokers/scout.py +++ b/tom_alerts/brokers/scout.py @@ -1,9 +1,10 @@ import requests -from urllib.parse import urlencode from dateutil.parser import parse +from urllib.parse import urlencode + from astropy import units as u from astropy.coordinates import Angle - +from crispy_forms.layout import Fieldset, HTML, Layout from tom_alerts.alerts import GenericAlert, GenericQueryForm, GenericBroker from tom_targets.models import Target @@ -12,7 +13,17 @@ class ScoutQueryForm(GenericQueryForm): - pass + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper.layout = Layout( + HTML(''' +

+ Please see the Scout API Reference + for a detailed description of the service. +

+ '''), + self.common_layout, + ) def hours_min_to_decimal(val): @@ -22,6 +33,11 @@ def hours_min_to_decimal(val): class ScoutBroker(GenericBroker): + """ + The ``ScoutBroker`` is the interface to the Scout alert broker. For information regarding the Scout Broker, + please see https://cneos.jpl.nasa.gov/scout/intro.html, as well as https://ssd-api.jpl.nasa.gov/doc/scout.html. + """ + name = 'Scout' form = ScoutQueryForm diff --git a/tom_alerts/brokers/tns.py b/tom_alerts/brokers/tns.py index ab0b785c3..9ccab9d2c 100644 --- a/tom_alerts/brokers/tns.py +++ b/tom_alerts/brokers/tns.py @@ -4,11 +4,11 @@ import requests import json from datetime import datetime, timedelta -from crispy_forms.layout import Layout, Div, Fieldset +from crispy_forms.layout import Div, Fieldset, HTML, Layout -tns_search_url = 'https://wis-tns.weizmann.ac.il/api/get/search' -tns_object_url = 'https://wis-tns.weizmann.ac.il/api/get/object' +tns_base_url = 'https://wis-tns.weizmann.ac.il/api/get' +tns_api_url = tns_base_url + '/api/get' class TNSForm(GenericQueryForm): @@ -41,6 +41,12 @@ class TNSForm(GenericQueryForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper.layout = Layout( + HTML(''' +

+ Please see + the TNS API Manual for a detailed description of available filters. +

+ '''), self.common_layout, 'target_name', 'internal_name', @@ -74,7 +80,7 @@ def __init__(self, *args, **kwargs): class TNSBroker(GenericBroker): """ - The ``TNSBroker`` is the interface to the Transient Name Server. For information regarding the TNS, please see \ + The ``TNSBroker`` is the interface to the Transient Name Server. For information regarding the TNS, please see https://wis-tns.weizmann.ac.il/ """ @@ -102,7 +108,7 @@ def fetch_alerts(cls, parameters): 'public_timestamp': public_timestamp, }) } - response = requests.post(tns_search_url, data) + response = requests.post(tns_api_url + '/search', data) response.raise_for_status() transients = response.json() alerts = [] @@ -115,7 +121,7 @@ def fetch_alerts(cls, parameters): 'spectroscopy': 0, }) } - response = requests.post(tns_object_url, data) + response = requests.post(tns_api_url + '/object', data) response.raise_for_status() alert = response.json()['data']['reply'] @@ -137,7 +143,7 @@ def fetch_alerts(cls, parameters): def to_generic_alert(cls, alert): return GenericAlert( timestamp=alert['discoverydate'], - url='https://wis-tns.weizmann.ac.il/object/' + alert['name'], + url=tns_base_url + '/object' + alert['name'], id=alert['name'], name=alert['name_prefix'] + alert['name'], ra=alert['radeg'], From 13a2b7a41a54057b7f636493b2f1913703527db9 Mon Sep 17 00:00:00 2001 From: David Collom Date: Fri, 17 Apr 2020 08:41:20 -0700 Subject: [PATCH 3/6] added blurb about testing --- docs/contributing.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/contributing.md b/docs/contributing.md index 2e9ce6d69..31d71c114 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -67,3 +67,9 @@ We recommend that you use a linter, as all pull requests must pass a `pycodestyl ``` pycodestyle tom_* --exclude=*/migrations/* --max-line-length=120 ``` + +### Testing + +Before PRing, at a minimum you should make sure you run all the tests with `./manage.py test`. If you're modifying a particular module, +you should ensure that the existing tests cover all the paths of the code you're writing, and, if they don't, we encourage you to expand +them. If you're relatively new to writing tests, or have questions, Django has [https://docs.djangoproject.com/en/3.0/topics/testing/](multiple guides on testing), or you can take a look at the existing tests in the TOM Toolkit. From ca69b3c0b20bb008e376f24da1e299258da528fd Mon Sep 17 00:00:00 2001 From: David Collom Date: Fri, 17 Apr 2020 08:44:08 -0700 Subject: [PATCH 4/6] Removing superfluous code from TNS harvester --- tom_catalogs/harvesters/tns.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tom_catalogs/harvesters/tns.py b/tom_catalogs/harvesters/tns.py index 4e9d3ffa6..f7e6c0be0 100644 --- a/tom_catalogs/harvesters/tns.py +++ b/tom_catalogs/harvesters/tns.py @@ -20,8 +20,6 @@ def get(term): - # url = "https://wis-tns.weizmann.ac.il/api/get" - get_url = TNS_URL + '/api/get/object' # change term to json format From eb9ddf0177bc60d6b39658b4e2fd1fe029faa537 Mon Sep 17 00:00:00 2001 From: David Collom Date: Mon, 20 Apr 2020 16:01:05 -0700 Subject: [PATCH 5/6] Fixed TNS url but this stupid thing still doesn't work --- tom_alerts/brokers/tns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tom_alerts/brokers/tns.py b/tom_alerts/brokers/tns.py index 9ccab9d2c..d247205be 100644 --- a/tom_alerts/brokers/tns.py +++ b/tom_alerts/brokers/tns.py @@ -7,7 +7,7 @@ from crispy_forms.layout import Div, Fieldset, HTML, Layout -tns_base_url = 'https://wis-tns.weizmann.ac.il/api/get' +tns_base_url = 'https://wis-tns.weizmann.ac.il' tns_api_url = tns_base_url + '/api/get' From d5d78e3a120ee350411218414df8a981f6a22382 Mon Sep 17 00:00:00 2001 From: David Collom Date: Sun, 31 Oct 2021 19:17:52 -0700 Subject: [PATCH 6/6] Removing unused imports --- tom_alerts/brokers/scout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tom_alerts/brokers/scout.py b/tom_alerts/brokers/scout.py index e4cb29fe4..bab015fa0 100644 --- a/tom_alerts/brokers/scout.py +++ b/tom_alerts/brokers/scout.py @@ -4,7 +4,7 @@ from astropy import units as u from astropy.coordinates import Angle -from crispy_forms.layout import Fieldset, HTML, Layout +from crispy_forms.layout import HTML, Layout from tom_alerts.alerts import GenericAlert, GenericQueryForm, GenericBroker from tom_targets.models import Target