Skip to content

Commit

Permalink
Merge pull request #1086 from TOMToolkit/1074-target-detail-page-coul…
Browse files Browse the repository at this point in the history
…d-automatically-display-what-constellation-a-target-is-in

add constellation to Target detail page
  • Loading branch information
jchate6 authored Oct 23, 2024
2 parents 5f7ecf2 + c9dfb6d commit d5480ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tom_targets/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils.module_loading import import_string
from guardian.shortcuts import assign_perm
from math import radians
from astropy.coordinates import get_constellation, SkyCoord

from tom_common.hooks import run_hook

Expand Down Expand Up @@ -488,6 +489,20 @@ def names(self):
"""
return [self.name] + [alias.name for alias in self.aliases.all()]

@property
def constellation(self):
"""
Gets the constellation of this target if it is sidereal
:returns: The constellation of this target according to astropy
:rtype: str
"""
constellation = None
if self.type == 'SIDEREAL':
coordinates = SkyCoord(self.ra, self.dec, frame='icrs', unit='deg')
constellation = get_constellation(coordinates)
return constellation

@property
def future_observations(self):
"""
Expand Down
4 changes: 4 additions & 0 deletions tom_targets/templates/tom_targets/partials/target_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{% if key == 'dec' %}
<dt class="col-sm-6">&nbsp;</dt>
<dd class="col-sm-6">{{ value|deg_to_sexigesimal:"dms" }}</dd>
{% if target.constellation %}
<dt class="col-sm-6">Constellation</dt>
<dd class="col-sm-6">{{ target.constellation }}</dd>
{% endif %}
{% endif%}
{% endfor %}
</dl>
Expand Down

0 comments on commit d5480ae

Please sign in to comment.