From d9bbb98236a8e7af3092d9a2acc2b9acafbde633 Mon Sep 17 00:00:00 2001 From: Joseph Chatelain Date: Fri, 15 Dec 2023 14:51:07 -0800 Subject: [PATCH 1/4] allow anonymous user to view forms --- tom_tns/templatetags/tns_extras.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tom_tns/templatetags/tns_extras.py b/tom_tns/templatetags/tns_extras.py index 8ba8437..f1e674e 100644 --- a/tom_tns/templatetags/tns_extras.py +++ b/tom_tns/templatetags/tns_extras.py @@ -23,7 +23,7 @@ def report_to_tns(context): initial = { 'ra': target.ra, 'dec': target.dec, - 'reporter': f"{context['request'].user.get_full_name()}, using {settings.TOM_NAME}", + 'reporter': f"{getattr(context['request'].user, 'get_full_name()', 'Tom Nonymous')}, using {settings.TOM_NAME}", } # Get photometry if available photometry = target.reduceddatum_set.filter(data_type='photometry') @@ -52,7 +52,8 @@ def classify_with_tns(context): target = context['target'] initial = { 'object_name': target.name.replace('AT', '').replace('SN', ''), - 'classifier': f'{context["request"].user.get_full_name()}, using {settings.TOM_NAME}', + 'classifier': f"{getattr(context['request'].user, 'get_full_name()', 'Tom Nonymous')}," + f" using {settings.TOM_NAME}", } # Get spectroscopy if available spectra = target.reduceddatum_set.filter(data_type='spectroscopy') From bd3acbab6851ec809f2794407da455953d1ae714 Mon Sep 17 00:00:00 2001 From: Joseph Chatelain Date: Fri, 15 Dec 2023 15:28:49 -0800 Subject: [PATCH 2/4] throw unconfigured alert if no API key --- tom_tns/tns_api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tom_tns/tns_api.py b/tom_tns/tns_api.py index 7d91bf4..a7e9daf 100644 --- a/tom_tns/tns_api.py +++ b/tom_tns/tns_api.py @@ -23,10 +23,15 @@ def get_tns_credentials(): """ try: tns_info = settings.BROKERS['TNS'] - # Build TNS Marker using Bot info - tns_info['marker'] = 'tns_marker' + json.dumps({'tns_id': tns_info.get('bot_id', None), - 'type': 'bot', - 'name': tns_info.get('bot_name', None)}) + + # Build TNS Marker using Bot info if API key is present + if tns_info.get('api_key', None): + tns_info['marker'] = 'tns_marker' + json.dumps({'tns_id': tns_info.get('bot_id', None), + 'type': 'bot', + 'name': tns_info.get('bot_name', None)}) + else: + logger.error("TNS API key not found in settings.py") + tns_info = {} except (KeyError, AttributeError): logger.error("TNS credentials not found in settings.py") tns_info = {} From d8813075d31dc5d3da46b30728fac66971fecce7 Mon Sep 17 00:00:00 2001 From: Joseph Chatelain Date: Fri, 15 Dec 2023 16:01:54 -0800 Subject: [PATCH 3/4] remove fun --- tom_tns/templatetags/tns_extras.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tom_tns/templatetags/tns_extras.py b/tom_tns/templatetags/tns_extras.py index f1e674e..64865d3 100644 --- a/tom_tns/templatetags/tns_extras.py +++ b/tom_tns/templatetags/tns_extras.py @@ -23,7 +23,7 @@ def report_to_tns(context): initial = { 'ra': target.ra, 'dec': target.dec, - 'reporter': f"{getattr(context['request'].user, 'get_full_name()', 'Tom Nonymous')}, using {settings.TOM_NAME}", + 'reporter': f"{getattr(context['request'].user, 'get_full_name()', 'Anonymous User')}, using {settings.TOM_NAME}", } # Get photometry if available photometry = target.reduceddatum_set.filter(data_type='photometry') @@ -52,7 +52,7 @@ def classify_with_tns(context): target = context['target'] initial = { 'object_name': target.name.replace('AT', '').replace('SN', ''), - 'classifier': f"{getattr(context['request'].user, 'get_full_name()', 'Tom Nonymous')}," + 'classifier': f"{getattr(context['request'].user, 'get_full_name()', 'Anonymous User')}," f" using {settings.TOM_NAME}", } # Get spectroscopy if available From 0c9e850301e2ee8d90a2ee69f6fcc23a4949f149 Mon Sep 17 00:00:00 2001 From: Joseph Chatelain Date: Fri, 15 Dec 2023 16:03:13 -0800 Subject: [PATCH 4/4] fix linting --- tom_tns/templatetags/tns_extras.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tom_tns/templatetags/tns_extras.py b/tom_tns/templatetags/tns_extras.py index 64865d3..9802739 100644 --- a/tom_tns/templatetags/tns_extras.py +++ b/tom_tns/templatetags/tns_extras.py @@ -23,7 +23,8 @@ def report_to_tns(context): initial = { 'ra': target.ra, 'dec': target.dec, - 'reporter': f"{getattr(context['request'].user, 'get_full_name()', 'Anonymous User')}, using {settings.TOM_NAME}", + 'reporter': f"{getattr(context['request'].user, 'get_full_name()', 'Anonymous User')}," + f" using {settings.TOM_NAME}", } # Get photometry if available photometry = target.reduceddatum_set.filter(data_type='photometry')