From 038dd6e36ac28bebaf6434803ecd56e15a06e061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Thu, 25 Feb 2016 17:48:46 +0100 Subject: [PATCH] SortKeyName should be used for Interpret not for Title --- countrylist.py | 53 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/countrylist.py b/countrylist.py index b90cbd2..4584e95 100644 --- a/countrylist.py +++ b/countrylist.py @@ -278,20 +278,6 @@ missing!" ) for ref in self._titel_raw.ifilter_tags(matches="ref"): self._titel_raw.remove( ref ) - # Handle SortKeyName and SortKey - for template in self._titel_raw.ifilter_templates( - matches="SortKey" ): - - if template.name == "SortKeyName": - titel = "[[" + template.get(1) + " " + template.get(2) - if template.has(3): - titel += "|" + template.get(3) - titel += "]]" - self._title_raw.replace( template, titel ) - else: - if template.has(2): - self._title_raw.replace( template, template.get(2) ) - # Remove whitespace self._titel_raw = str(self._titel_raw).strip() else: @@ -364,6 +350,45 @@ missing!" ) for ref in self._interpret_raw.ifilter_tags(matches="ref"): self._interpret_raw.remove( ref ) + # Handle SortKeyName and SortKey + for template in self._interpret_raw.ifilter_templates( + matches="SortKey" ): + + if template.name == "SortKeyName": + # Differing Link-Destination is provided as param 3 + if template.has(3): + # Construct link out of Template, Params: + # 1 = Surname + # 2 = Name + # 3 = Link-Dest + interpret_link = mwparser.nodes.wikilink.Wikilink( + str(template.get(3).value), + str(template.get(1).value) + " " + + str(template.get(2).value) ) + + # Default Link-Dest [[Surname Name]] + else: + interpret_link = mwparser.nodes.wikilink.Wikilink( + str(template.get(1).value) + " " + + str(template.get(2).value) ) + + # Replace Template with link + self._interpret_raw.replace( template, interpret_link ) + + # SortKey + else: + # Replace SortKey with text from param 2 if present + if template.has(2): + self._interpret_raw.replace( template, + template.get(2).value) + # Else Remove SortKey (text should follow behind SortKey) + else: + self._interpret_raw.replace( template, None) + + # Normally won't be needed as there should be only one + # SortKey-Temlate but ... its a wiki + break + # Remove whitespace self._interpret_raw = str(self._interpret_raw).strip() else: