Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-08-25-try-fix-fk_dataowner_etc_organisation #156

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qgepqwat2ili/gui/gui_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def commit_session(self):
# session.begin_nested() and one additionnal self.session.commit()

# add info in message bar
iface.messageBar().pushMessage("Please be patient!", "Importing data in qgep - working ...", level=Qgis.Warning)
iface.messageBar().pushMessage("Please be patient!", "Importing data in qgep - working ...", level=Qgis.Info)

try:
self.session.commit()
Expand Down
30 changes: 30 additions & 0 deletions qgepqwat2ili/qgepdss/import_.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,36 @@ def create_or_update_organisation(name):
instance = obj
break

# set instance with organisation.obj instead of organisation.name, as fk_dataowner / fk_provider could already be a obj_id instead of an identifier
if not instance:
instance = qgep_session.query(QGEP.organisation).filter(QGEP.organisation.obj_id == name).first()

# also look for non-flushed objects in the session
if not instance:
for obj in qgep_session:
# for VSA-DSS look in subclasses instead of organisation
#if obj.__class__ is QGEP.organisation and obj.obj_id == name:
# instance = obj
# break
if obj.__class__ is QGEP.municipality and obj.obj_id == name:
instance = obj
break
if obj.__class__ is QGEP.administrative_office and obj.obj_id == name:
instance = obj
break
if obj.__class__ is QGEP.canton and obj.obj_id == name:
instance = obj
break
if obj.__class__ is QGEP.cooperative and obj.obj_id == name:
instance = obj
break
if obj.__class__ is QGEP.private and obj.obj_id == name:
instance = obj
break
if obj.__class__ is QGEP.waste_water_association and obj.obj_id == name:
instance = obj
break

# if still nothing, we create it
if not instance:
# 10.8.2022 extra logger info added
Expand Down
Loading