diff --git a/tom_tns/templatetags/tns_extras.py b/tom_tns/templatetags/tns_extras.py index 8ba8437..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"{context['request'].user.get_full_name()}, 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') @@ -52,7 +53,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()', 'Anonymous User')}," + f" using {settings.TOM_NAME}", } # Get spectroscopy if available spectra = target.reduceddatum_set.filter(data_type='spectroscopy') 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 = {}