Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes crashes in TNS form for anonymous users and no API key. #12

Merged
merged 4 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading