Browse Source

Cut Titel and Interpret on first linebreak

For some asian countries there is the original name following after a
linebreak. This is not needed in overview, so cat it of.

Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=118 FS#118]
develop
Jonathan Golder 5 years ago
parent
commit
af44323930
1 changed files with 25 additions and 0 deletions
  1. +25
    -0
      countrylist.py

+ 25
- 0
countrylist.py View File

@ -284,6 +284,9 @@ missing!" )
if self.entry.has( "Titel" ):
self._titel_raw = self.entry.get("Titel").value
# Only use part before possible "<br"
self.remove_lines(self._titel_raw)
# Remove possible ref-tags
for ref in self._titel_raw.ifilter_tags(matches="ref"):
self._titel_raw.remove( ref )
@ -356,6 +359,9 @@ missing!" )
if self.entry.has( "Interpret" ):
self._interpret_raw = self.entry.get("Interpret").value
# Only use part before possible "<br"
self.remove_lines(self._interpret_raw)
# Remove possible ref-tags
for ref in self._interpret_raw.ifilter_tags(matches="ref"):
self._interpret_raw.remove( ref )
@ -458,6 +464,25 @@ missing!" )
else:
return str(keywords[0])
def remove_lines(self, wikicode):
"""
Removes linebreaks (<br>) and everything after them in given wikicode
"""
# Catch wrong typed param
if not isinstance(wikicode, mwparser.wikicode.Wikicode):
raise TypeError(str(type(self)) + "._remove_lines() expects " +
"parameter 'wikicode' of type " +
"'mwparserfromhell.wikicode.Wikicode', " +
str(type(wikicode)) + " was given!")
# Find first linebreak
br = next(wikicode.ifilter_tags(matches="br"), None)
# If there is one, get its position and slice nodes-list
if br:
brpos = wikicode.nodes.index(br)
wikicode.nodes = wikicode.nodes[0:brpos]
def __str__( self ):
"""
Returns str repression for Object


Loading…
Cancel
Save