Skip to content

Commit

Permalink
Merge pull request #12 from TOMToolkit/4-anonymous-user-has-no-attrib…
Browse files Browse the repository at this point in the history
…ute-full_name

Fixes crashes in TNS form for anonymous users and no API key.
  • Loading branch information
jchate6 authored Dec 16, 2023
2 parents 1c24cd2 + 0c9e850 commit 73f1c3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions tom_tns/templatetags/tns_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
13 changes: 9 additions & 4 deletions tom_tns/tns_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 73f1c3b

Please sign in to comment.