Skip to content

Commit

Permalink
Check if the target already exists before creating it (TOMToolkit/tom…
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPeloton committed May 3, 2021
1 parent 803de3f commit 735c8a7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tom_fink/fink.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,24 @@ def to_target(self, alert: dict) -> Target:
`self.fetch_alerts` for more information.
"""
target = Target.objects.create(
_, created = Target.objects.get_or_create(
name=alert['i:objectId'],
type='SIDEREAL',
ra=alert['i:ra'],
dec=alert['i:dec'],
type=Target.SIDEREAL
)
aliases = [TargetName(target=target, name=alert['i:objectId'])]
return target, [], aliases

if created is False:
# create the target with name/RA/Dec if
# the target name does not exist
target = Target.objects.create(
name=alert['i:objectId'],
type='SIDEREAL',
ra=alert['i:ra'],
dec=alert['i:dec'],
)
else:
# do not recreate the target
target = None
return target, created

def to_generic_alert(self, alert):
""" Extract relevant parameters from the Fink alert to the TOM interface
Expand Down

0 comments on commit 735c8a7

Please sign in to comment.