essential bugfixes

This commit is contained in:
Daniel Schick 2024-09-20 09:46:48 +02:00
parent 12c1fc59b1
commit ed6f5ab648
7 changed files with 61 additions and 32 deletions

View File

@ -546,6 +546,7 @@
</data>
<data name="textTooFarInTheFuture" xml:space="preserve">
<value>Eine Zeiteingabe ist zu weit in der Zukunft</value>
</data>
<data name="textHarbour" xml:space="preserve">
<value>Hafen</value>
</data>

View File

@ -52,7 +52,7 @@ def create_app(test_config=None, instance_path=None):
try:
import os
print(f'Instance path = {app.instance_path}')
os.makedirs(app.instance_path)
os.makedirs(app.instance_path, exist_ok=True)
except OSError:
pass

View File

@ -10,6 +10,22 @@ def create_sql_query_shipcall_get(options:dict)->str:
options : dict. A dictionary, which must contains the 'past_days' key (int). Determines the range
by which shipcalls are filtered.
"""
if "participant_id" not in options: # if no participant_id is given, all shipcalls are selected
query = ("SELECT s.id as id, ship_id, port_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " +
"flags, s.pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, " +
"tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, evaluation, " +
"evaluation_message, evaluation_time, evaluation_notifications_sent, s.created as created, s.modified as modified, time_ref_point " +
"FROM shipcall s " +
"LEFT JOIN times t ON t.shipcall_id = s.id AND t.participant_type = 8 " +
"WHERE " +
"(type = 1 AND " +
"((t.id IS NOT NULL AND t.eta_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " +
"(eta >= DATE(NOW() - INTERVAL %d DAY)))) OR " +
"((type = 2 OR type = 3) AND " +
"((t.id IS NOT NULL AND t.etd_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " +
"(etd >= DATE(NOW() - INTERVAL %d DAY)))) " +
"ORDER BY eta") % (options["past_days"], options["past_days"], options["past_days"], options["past_days"])
else:
query = ("SELECT s.id as id, ship_id, port_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " +
"flags, s.pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, " +
"tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, evaluation, " +

View File

@ -15,10 +15,15 @@ def GetBerths(options):
commands = pydapper.using(pooledConnection)
# only load berths to ports that the participant is assigned to
if "participant_id" in options:
query = ("SELECT id, name, `lock`, owner_id, port_id, authority_id, created, modified, deleted FROM berth WHERE " +
"deleted = 0 AND + "
"port_id IN (SELECT port_id FROM participant_port_map WHERE participant_id = %d) " +
"ORDER BY name") % (options["participant_id"])
else:
query = ("SELECT id, name, `lock`, owner_id, port_id, authority_id, created, modified, deleted FROM berth WHERE " +
"deleted = 0 ORDER BY name")
data = commands.query(query, model=model.Berth)
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}

View File

@ -23,7 +23,7 @@ def GetParticipant(options):
data = commands.query(query, model=model.Participant)
else:
# query = SQLQuery.get_participants()
if "participant_id" in options:
# list only participants that are assigned to the same ports than participant of caller
query = ("SELECT p.id as id, name, street, postal_code, city, type, flags, p.created, p.modified, p.deleted " +
"FROM participant p " +
@ -32,6 +32,12 @@ def GetParticipant(options):
"(SELECT port_id FROM participant_port_map where participant_id = %d) " +
"GROUP BY id " +
"ORDER BY p.name") % options["participant_id"]
else:
query = ("SELECT p.id as id, name, street, postal_code, city, type, flags, p.created, p.modified, p.deleted " +
"FROM participant p " +
"JOIN participant_port_map ON p.id = participant_port_map.participant_id " +
"GROUP BY id " +
"ORDER BY p.name")
data = commands.query(query, model=model.Participant)
for participant in data:

View File

@ -216,6 +216,7 @@ class ShipcallSchema(Schema):
id = fields.Integer(required=True)
ship_id = fields.Integer(required=True)
port_id = fields.Integer(required=True)
type = fields.Enum(ShipcallType, default=ShipcallType.undefined)
eta = fields.DateTime(required=False, allow_none=True)
voyage = fields.String(allow_none=True, required=False, validate=[validate.Length(max=16)])

View File

@ -26,7 +26,7 @@ def get_participant_id_dictionary():
def get_berth_id_dictionary():
# get all berths
response,status_code,header = GetBerths(token=None)
response,status_code,header = GetBerths(options={})
# build a dictionary of id:item pairs, so one can select the respective participant
berths = json.loads(response)