Fixed saving of shipcall by correctly interpreting enums now
The trick was to use a helper-field and a (decorated) @post_load method in the model that allows to fill the helper fields with the values (ints) instead of strings for enums. Trouble is: We are parsing strings from API/JSON and want to serialize as int (value in IntEnum). The helper fields also must be skipped when setting up the query. Pretty convoluted, but gets the jon done (finally). Also extended the database by new field 'interval_end' which is a preparation to allow not only timestamps but also intervals when specifying times for participants.
This commit is contained in:
parent
049cdaaf73
commit
a5b16154c6
@ -669,6 +669,11 @@ components:
|
|||||||
format: date-time
|
format: date-time
|
||||||
nullable: true
|
nullable: true
|
||||||
description: can be set by mooring if actual times are different from planned
|
description: can be set by mooring if actual times are different from planned
|
||||||
|
interval_end:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
nullable: true
|
||||||
|
description: End of the interval for the times entry
|
||||||
created:
|
created:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
|||||||
@ -89,4 +89,5 @@ ADD CONSTRAINT `FK_HISTORY_USER`
|
|||||||
-- add ata_atd field to times
|
-- add ata_atd field to times
|
||||||
|
|
||||||
ALTER TABLE `bremen_calling_devel`.`times`
|
ALTER TABLE `bremen_calling_devel`.`times`
|
||||||
ADD COLUMN `ata_atd` DATETIME NULL DEFAULT NULL COMMENT 'Relevant only for mooring, this field can be used to record actual ATA / ATD' AFTER `participant_type`;
|
ADD COLUMN `ata_atd` DATETIME NULL DEFAULT NULL COMMENT 'Relevant only for mooring, this field can be used to record actual ATA / ATD' AFTER `participant_type`,
|
||||||
|
ADD COLUMN `interval_end` DATETIME NULL DEFAULT NULL COMMENT 'If this value is set the times are given as interval instead of a single point in time. The start time value depends on the participant type.' AFTER `ata_atd`;
|
||||||
@ -166,6 +166,7 @@ def PutShipcalls(schemaModel):
|
|||||||
query = "UPDATE shipcall SET "
|
query = "UPDATE shipcall SET "
|
||||||
isNotFirst = False
|
isNotFirst = False
|
||||||
for key in schemaModel.keys():
|
for key in schemaModel.keys():
|
||||||
|
param_key = key
|
||||||
if key == "id":
|
if key == "id":
|
||||||
continue
|
continue
|
||||||
if key == "participants":
|
if key == "participants":
|
||||||
@ -178,10 +179,18 @@ def PutShipcalls(schemaModel):
|
|||||||
continue
|
continue
|
||||||
if key == "evaluation_message":
|
if key == "evaluation_message":
|
||||||
continue
|
continue
|
||||||
|
if key == "type":
|
||||||
|
param_key = "type_value"
|
||||||
|
if key == "type_value":
|
||||||
|
continue
|
||||||
|
if key == "evaluation":
|
||||||
|
param_key = "evaluation_value"
|
||||||
|
if key == "evaluation_value":
|
||||||
|
continue
|
||||||
if isNotFirst:
|
if isNotFirst:
|
||||||
query += ", "
|
query += ", "
|
||||||
isNotFirst = True
|
isNotFirst = True
|
||||||
query += key + " = ?" + key + "? "
|
query += key + " = ?" + param_key + "? "
|
||||||
|
|
||||||
query += "WHERE id = ?id?"
|
query += "WHERE id = ?id?"
|
||||||
affected_rows = commands.execute(query, param=schemaModel)
|
affected_rows = commands.execute(query, param=schemaModel)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ def GetTimes(options):
|
|||||||
commands = pydapper.using(pooledConnection)
|
commands = pydapper.using(pooledConnection)
|
||||||
data = commands.query("SELECT id, eta_berth, eta_berth_fixed, etd_berth, etd_berth_fixed, lock_time, lock_time_fixed, " +
|
data = commands.query("SELECT id, eta_berth, eta_berth_fixed, etd_berth, etd_berth_fixed, lock_time, lock_time_fixed, " +
|
||||||
"zone_entry, zone_entry_fixed, operations_start, operations_end, remarks, shipcall_id, participant_id, " +
|
"zone_entry, zone_entry_fixed, operations_start, operations_end, remarks, shipcall_id, participant_id, " +
|
||||||
"berth_id, berth_info, pier_side, participant_type, created, modified, ata_atd FROM times " +
|
"berth_id, berth_info, pier_side, participant_type, created, modified, ata_atd, interval_end FROM times " +
|
||||||
"WHERE times.shipcall_id = ?scid?", model=model.Times, param={"scid" : options["shipcall_id"]})
|
"WHERE times.shipcall_id = ?scid?", model=model.Times, param={"scid" : options["shipcall_id"]})
|
||||||
pooledConnection.close()
|
pooledConnection.close()
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from dataclasses import field, dataclass
|
from dataclasses import field, dataclass
|
||||||
from marshmallow import Schema, fields, INCLUDE, ValidationError
|
from marshmallow import Schema, fields, post_load, INCLUDE, ValidationError
|
||||||
from marshmallow.fields import Field
|
from marshmallow.fields import Field
|
||||||
from marshmallow_enum import EnumField
|
from marshmallow_enum import EnumField
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
@ -151,7 +151,7 @@ class ShipcallSchema(Schema):
|
|||||||
|
|
||||||
id = fields.Int()
|
id = fields.Int()
|
||||||
ship_id = fields.Int()
|
ship_id = fields.Int()
|
||||||
type = EnumField(ShipcallType, by_value=True, required=True)
|
type = fields.Enum(ShipcallType, by_value=True, required=True)
|
||||||
eta = fields.DateTime(Required = False, allow_none=True)
|
eta = fields.DateTime(Required = False, allow_none=True)
|
||||||
voyage = fields.Str(allow_none=True, metadata={'Required':False}) # Solving: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'Required': False}
|
voyage = fields.Str(allow_none=True, metadata={'Required':False}) # Solving: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'Required': False}
|
||||||
etd = fields.DateTime(Required = False, allow_none=True)
|
etd = fields.DateTime(Required = False, allow_none=True)
|
||||||
@ -172,7 +172,7 @@ class ShipcallSchema(Schema):
|
|||||||
anchored = fields.Bool(Required = False, allow_none=True)
|
anchored = fields.Bool(Required = False, allow_none=True)
|
||||||
moored_lock = fields.Bool(Required = False, allow_none=True)
|
moored_lock = fields.Bool(Required = False, allow_none=True)
|
||||||
canceled = fields.Bool(Required = False, allow_none=True)
|
canceled = fields.Bool(Required = False, allow_none=True)
|
||||||
evaluation = EnumField(EvaluationType, required=False, allow_none=True, by_value=True)
|
evaluation = fields.Enum(EvaluationType, required=False, allow_none=True, by_value=True)
|
||||||
evaluation_message = fields.Str(allow_none=True, metadata={'Required':False}) # Solving: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'Required': False}
|
evaluation_message = fields.Str(allow_none=True, metadata={'Required':False}) # Solving: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'Required': False}
|
||||||
evaluation_time = fields.DateTime(Required = False, allow_none=True)
|
evaluation_time = fields.DateTime(Required = False, allow_none=True)
|
||||||
evaluation_notifications_sent = fields.Bool(Required = False, allow_none=True)
|
evaluation_notifications_sent = fields.Bool(Required = False, allow_none=True)
|
||||||
@ -181,6 +181,12 @@ class ShipcallSchema(Schema):
|
|||||||
created = fields.DateTime(Required = False, allow_none=True)
|
created = fields.DateTime(Required = False, allow_none=True)
|
||||||
modified = fields.DateTime(Required = False, allow_none=True)
|
modified = fields.DateTime(Required = False, allow_none=True)
|
||||||
|
|
||||||
|
@post_load
|
||||||
|
def make_shipcall(self, data, **kwargs):
|
||||||
|
data['type_value'] = data['type'].value
|
||||||
|
data['evaluation_value'] = data['evaluation'].value
|
||||||
|
return data
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Participant_Assignment:
|
class Participant_Assignment:
|
||||||
def __init__(self, participant_id, type):
|
def __init__(self, participant_id, type):
|
||||||
@ -297,6 +303,7 @@ class TimesSchema(Schema):
|
|||||||
shipcall_id = fields.Int(Required = True)
|
shipcall_id = fields.Int(Required = True)
|
||||||
participant_type = fields.Int(Required = False, allow_none=True)
|
participant_type = fields.Int(Required = False, allow_none=True)
|
||||||
ata_atd = fields.DateTime(Required = False, allow_none=True)
|
ata_atd = fields.DateTime(Required = False, allow_none=True)
|
||||||
|
interval_end = fields.DateTime(Required = False, allow_none=True)
|
||||||
created = fields.DateTime(Required = False, allow_none=True)
|
created = fields.DateTime(Required = False, allow_none=True)
|
||||||
modified = fields.DateTime(Required = False, allow_none=True)
|
modified = fields.DateTime(Required = False, allow_none=True)
|
||||||
|
|
||||||
@ -335,6 +342,7 @@ class Times:
|
|||||||
participant_type: int
|
participant_type: int
|
||||||
shipcall_id: int
|
shipcall_id: int
|
||||||
ata_atd: datetime
|
ata_atd: datetime
|
||||||
|
interval_end: datetime
|
||||||
created: datetime
|
created: datetime
|
||||||
modified: datetime
|
modified: datetime
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user