jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
[FIX] Correctly choose primary coordinates in BasePage.coordinates()

Bug: T244963
Change-Id: Ic47e75b5d04848ac45f2ab7a994a6d4361a1142d
---
M pywikibot/__init__.py
M pywikibot/data/api.py
M pywikibot/page.py
3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index c8a66dc..e5aaf8a 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -254,18 +254,14 @@

class Coordinate(_WbRepresentation):

- """
- Class for handling and storing Coordinates.
-
- For now its just being used for DataSite, but
- in the future we can use it for the GeoData extension.
- """
+ """Class for handling and storing Coordinates."""

_items = ('lat', 'lon', 'entity')

@_deprecate_arg('entity', 'globe_item')
def __init__(self, lat, lon, alt=None, precision=None, globe=None,
- typ='', name='', dim=None, site=None, globe_item=None):
+ typ='', name='', dim=None, site=None, globe_item=None,
+ primary=False):
"""
Represent a geo coordinate.

@@ -290,6 +286,8 @@
of this Wikibase item. Takes precedence over 'globe'
if present.
@type globe_item: pywikibot.ItemPage or str
+ @param primary: True for a primary set of coordinates
+ @type primary: bool
"""
self.lat = lat
self.lon = lon
@@ -300,6 +298,7 @@
self.name = name
self._dim = dim
self.site = site or Site().data_repository()
+ self.primary = primary

if globe:
globe = globe.lower()
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 79cb0f7..a75b09e 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -3301,6 +3301,7 @@
name=co.get('name', ''),
dim=int(co.get('dim', 0)) or None,
globe=co['globe'], # See [[gerrit:67886]]
+ primary=True if 'primary' in co else False
)
coords.append(coord)
page._coords = coords
diff --git a/pywikibot/page.py b/pywikibot/page.py
index d585648..1e6746a 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1673,7 +1673,7 @@
self._coords = []
self.site.loadcoordinfo(self)
if primary_only:
- return self._coords[0] if len(self._coords) > 0 else None
+ return [coord for coord in self._coords if coord.primary]
else:
return self._coords


To view, visit change 571852. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic47e75b5d04848ac45f2ab7a994a6d4361a1142d
Gerrit-Change-Number: 571852
Gerrit-PatchSet: 2
Gerrit-Owner: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: jenkins-bot (75)