John Vandenberg has uploaded a new change for review. https://gerrit.wikimedia.org/r/176934
Change subject: Allow some Claim methdods to be performed locally ...................................................................... Allow some Claim methdods to be performed locally ItemPage.editEntity can be used to submit multiple changes to the repository at once. To do this, the ItemPage in memory is altered, and editEntity determines the difference between the in memory copy and the server record. Most of the ItemPage methods that related to Claims submit the change immediately, which prevents these methods being used to batch up a set of changes to the ItemPage before being submitted to the repository together. This change only allows ItemPage.addClaim and Claim.addSources and Claim.addQualifier to be used to alter the in memory copy. Change-Id: Id41ff0c6c30a64ab4add1a93a7f497e142900eca --- M pywikibot/page.py 1 file changed, 28 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/34/176934/1 diff --git a/pywikibot/page.py b/pywikibot/page.py index 8df644f..de24a73 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -3364,7 +3364,7 @@ data = {'sitelinks': data} self.editEntity(data, **kwargs) - def addClaim(self, claim, bot=True, **kwargs): + def addClaim(self, claim, bot=True, save=True, **kwargs): """ Add a claim to the item. @@ -3372,8 +3372,18 @@ @type claim: Claim @param bot: Whether to flag as bot (if possible) @type bot: bool + @param save: If attached to an item, update the item on the server + @param save: bool """ - self.repo.addClaim(self, claim, bot=bot, **kwargs) + if save: + self.repo.addClaim(self, claim, bot=bot, **kwargs) + else: + # Add the claim, which repo.addClaim also does + if claim.getID() in self.claims: + self.claims[claim.getID()].append(claim) + else: + self.claims[claim.getID()] = [claim] + claim.on_item = self def removeClaims(self, claims, **kwargs): @@ -3793,18 +3803,23 @@ """ self.addSources([claim], **kwargs) - def addSources(self, claims, **kwargs): + def addSources(self, claims, save=True, **kwargs): """ Add the claims as one source. - @param claims: the claims to add + @param claims: the source claims to add @type claims: list of pywikibot.Claim + @param save: If attached to an item, update the item on the server + @param save: bool """ - data = self.repo.editSource(self, claims, new=True, **kwargs) + if self.on_item and save: + data = self.repo.editSource(self, claims, new=True, **kwargs) + self.on_item.lastrevid = data['pageinfo']['lastrevid'] + for claim in claims: + claim.hash = data['reference']['hash'] + source = collections.defaultdict(list) for claim in claims: - claim.hash = data['reference']['hash'] - self.on_item.lastrevid = data['pageinfo']['lastrevid'] source[claim.getID()].append(claim) self.sources.append(source) @@ -3830,15 +3845,18 @@ source_dict[source.getID()].append(source) self.sources.remove(source_dict) - def addQualifier(self, qualifier, **kwargs): + def addQualifier(self, qualifier, save=True, **kwargs): """Add the given qualifier. @param qualifier: the qualifier to add @type qualifier: Claim + @param save: If attached to an item, update the item on the server + @param save: bool """ - data = self.repo.editQualifier(self, qualifier, **kwargs) qualifier.isQualifier = True - self.on_item.lastrevid = data['pageinfo']['lastrevid'] + if self.on_item and save: + data = self.repo.editQualifier(self, qualifier, **kwargs) + self.on_item.lastrevid = data['pageinfo']['lastrevid'] if qualifier.getID() in self.qualifiers: self.qualifiers[qualifier.getID()].append(qualifier) else: -- To view, visit https://gerrit.wikimedia.org/r/176934 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id41ff0c6c30a64ab4add1a93a7f497e142900eca Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <jay...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits