sync
This commit is contained in:
@@ -59,8 +59,10 @@ def reject_observation(session: Session, observation: ExternalObservation, *, re
|
||||
|
||||
|
||||
def publish_observation(session: Session, observation: ExternalObservation) -> CatchReport:
|
||||
if observation.catch_report is not None:
|
||||
if observation.catch_report is not None and observation.status == "published":
|
||||
return observation.catch_report
|
||||
if observation.status == "rejected":
|
||||
raise ExternalReviewError("rejected observation must be mapped again before publication")
|
||||
if observation.fish is None or observation.waterbody is None or not _complete(observation):
|
||||
raise ExternalReviewError("fish, waterbody, coordinates and weight are required for publication")
|
||||
spot = session.scalar(select(Spot).where(
|
||||
@@ -71,7 +73,7 @@ def publish_observation(session: Session, observation: ExternalObservation) -> C
|
||||
session.add(spot)
|
||||
bait = _bait(session, observation.payload.get("bait"))
|
||||
now = datetime.now(timezone.utc)
|
||||
report = CatchReport(
|
||||
values = dict(
|
||||
fish=observation.fish, waterbody=observation.waterbody, spot=spot, bait=bait,
|
||||
weight_g=observation.weight_g,
|
||||
fishing_method=observation.payload.get("fishing_method"),
|
||||
@@ -95,6 +97,12 @@ def publish_observation(session: Session, observation: ExternalObservation) -> C
|
||||
"original": observation.payload,
|
||||
},
|
||||
)
|
||||
report = observation.catch_report
|
||||
if report is None:
|
||||
report = CatchReport(**values)
|
||||
else:
|
||||
for key, value in values.items():
|
||||
setattr(report, key, value)
|
||||
session.add(report)
|
||||
session.flush()
|
||||
observation.catch_report = report
|
||||
|
||||
Reference in New Issue
Block a user