Ladsgroup has uploaded a new change for review.
https://gerrit.wikimedia.org/r/219244
Change subject: Add suport for adding/removing statements in PropertyPage
......................................................................
Add suport for adding/removing statements in PropertyPage
It's possible to make/remove statements in Property pages in wikidata.
- Moved addClaim and removeClaims from ItemPage to WikibasePage
- Add .claims attribute to PropertyPage class as well
I tested it and it worked fine: [[d:Special:Diff/222806029]]
[[d:Special:Diff/222805971]]
Change-Id: Ic0ca0de87af017a6356beac2dad793ac81cc7ee8
---
M pywikibot/page.py
1 file changed, 34 insertions(+), 25 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/44/219244/1
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 446bbe0..5a471d4 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3485,6 +3485,31 @@
data = {'aliases': aliases}
self.editEntity(data, **kwargs)
+ def addClaim(self, claim, bot=True, **kwargs):
+ """
+ Add a claim to the item.
+
+ @param claim: The claim to add
+ @type claim: Claim
+ @param bot: Whether to flag as bot (if possible)
+ @type bot: bool
+ """
+ self.repo.addClaim(self, claim, bot=bot, **kwargs)
+ claim.on_item = self
+
+ def removeClaims(self, claims, **kwargs):
+ """
+ Remove the claims from the item.
+
+ @type claims: list
+
+ """
+ # this check allows single claims to be removed by pushing them into a
+ # list of length one.
+ if isinstance(claims, pywikibot.Claim):
+ claims = [claims]
+ self.repo.removeClaims(claims, **kwargs)
+
def set_redirect_target(self, target_page, create=False, force=False,
keep_section=False, save=True, **kwargs):
"""
@@ -3789,31 +3814,6 @@
data = {'sitelinks': data}
self.editEntity(data, **kwargs)
- def addClaim(self, claim, bot=True, **kwargs):
- """
- Add a claim to the item.
-
- @param claim: The claim to add
- @type claim: Claim
- @param bot: Whether to flag as bot (if possible)
- @type bot: bool
- """
- self.repo.addClaim(self, claim, bot=bot, **kwargs)
- claim.on_item = self
-
- def removeClaims(self, claims, **kwargs):
- """
- Remove the claims from the item.
-
- @type claims: list
-
- """
- # this check allows single claims to be removed by pushing them into a
- # list of length one.
- if isinstance(claims, pywikibot.Claim):
- claims = [claims]
- self.repo.removeClaims(claims, **kwargs)
-
def mergeInto(self, item, **kwargs):
"""
Merge the item into another item.
@@ -3965,6 +3965,15 @@
"""
if force or not hasattr(self, '_content'):
WikibasePage.get(self, force=force, *args)
+ # claims
+ self.claims = {}
+ if 'claims' in self._content:
+ for pid in self._content['claims']:
+ self.claims[pid] = list()
+ for claim in self._content['claims'][pid]:
+ c = Claim.fromJSON(self.repo, claim)
+ c.on_item = self
+ self.claims[pid].append(c)
self._type = self._content['datatype']
def newClaim(self, *args, **kwargs):
--
To view, visit https://gerrit.wikimedia.org/r/219244
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0ca0de87af017a6356beac2dad793ac81cc7ee8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits