Fix for OSM objects with multiple geometry

This commit is contained in:
Edward Betts 2021-07-19 22:07:41 +02:00
parent 6f30e1232a
commit 19a9010aa7

View file

@ -3,6 +3,7 @@
from flask import (Flask, render_template, request, jsonify, redirect, url_for, g, from flask import (Flask, render_template, request, jsonify, redirect, url_for, g,
flash, session, Response, stream_with_context) flash, session, Response, stream_with_context)
from sqlalchemy import func from sqlalchemy import func
from sqlalchemy.sql.expression import update
from matcher import (nominatim, model, database, commons, wikidata, wikidata_api, from matcher import (nominatim, model, database, commons, wikidata, wikidata_api,
osm_oauth, edit, mail, api) osm_oauth, edit, mail, api)
from matcher.data import property_map from matcher.data import property_map
@ -578,10 +579,12 @@ def process_edit(changeset_id, e):
existing = root.find('.//tag[@k="wikidata"]') existing = root.find('.//tag[@k="wikidata"]')
if e["op"] == "add" and existing is not None: if e["op"] == "add" and existing is not None:
return "already_added" return "already_added"
if e["op"] == "remove" and existing is None: if e["op"] == "remove":
return "already_removed" if existing is None:
return "already_removed"
if existing.get("v") != qid:
return "different_qid"
root = etree.fromstring(r.content)
root[0].set("changeset", str(changeset_id)) root[0].set("changeset", str(changeset_id))
if e["op"] == "add": if e["op"] == "add":
tag = etree.Element("tag", k="wikidata", v=qid) tag = etree.Element("tag", k="wikidata", v=qid)
@ -604,8 +607,18 @@ def process_edit(changeset_id, e):
if not success: if not success:
return "element-error" return "element-error"
osm.tags["wikidata"] = qid new_tags = dict(osm.tags)
flag_modified(osm, "tags") if e["op"] == "add":
new_tags["wikidata"] = qid
if e["op"] == "remove":
del new_tags["wikidata"]
cls = type(osm)
database.session.execute(
update(cls).
where(cls.src_id == osm.src_id).
values(tags=new_tags)
)
db_edit = model.ChangesetEdit( db_edit = model.ChangesetEdit(
changeset_id=changeset_id, changeset_id=changeset_id,