|
@ -38,14 +38,24 @@ class SummaryPage(): |
|
|
Handles summary page related actions |
|
|
Handles summary page related actions |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def __init__( self, text ): |
|
|
def __init__( self, text, force_reload=False ): |
|
|
""" |
|
|
""" |
|
|
Create Instance |
|
|
Create Instance |
|
|
|
|
|
|
|
|
|
|
|
@param text: Page Text of summarypage |
|
|
|
|
|
@type text: str |
|
|
|
|
|
@param force-reload: If given, countrylists will be always parsed |
|
|
|
|
|
regardless if needed or not |
|
|
|
|
|
@type force-reload: bool |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
# Parse Text with mwparser |
|
|
# Parse Text with mwparser |
|
|
self.wikicode = mwparser.parse( text ) |
|
|
self.wikicode = mwparser.parse( text ) |
|
|
|
|
|
|
|
|
|
|
|
# Force parsing of countrylist |
|
|
|
|
|
self.force_reload = force_reload |
|
|
|
|
|
|
|
|
def treat( self ): |
|
|
def treat( self ): |
|
|
""" |
|
|
""" |
|
|
Handles parsing/editing of text |
|
|
Handles parsing/editing of text |
|
@ -55,7 +65,9 @@ class SummaryPage(): |
|
|
for entry in self.wikicode.filter_templates( matches="/Eintrag" ): |
|
|
for entry in self.wikicode.filter_templates( matches="/Eintrag" ): |
|
|
|
|
|
|
|
|
# Instantiate SummaryPageEntry-object |
|
|
# Instantiate SummaryPageEntry-object |
|
|
summarypageentry = SummaryPageEntry( entry ) |
|
|
summarypageentry = SummaryPageEntry(entry, |
|
|
|
|
|
force_reload=self.force_reload) |
|
|
|
|
|
|
|
|
# Treat SummaryPageEntry-object |
|
|
# Treat SummaryPageEntry-object |
|
|
summarypageentry.treat() |
|
|
summarypageentry.treat() |
|
|
|
|
|
|
|
@ -85,13 +97,22 @@ class SummaryPageEntry(): |
|
|
|
|
|
|
|
|
write_needed = False |
|
|
write_needed = False |
|
|
|
|
|
|
|
|
def __init__( self, entry ): |
|
|
def __init__( self, entry, force_reload=False ): |
|
|
""" |
|
|
""" |
|
|
Constructor |
|
|
Constructor |
|
|
|
|
|
|
|
|
|
|
|
@param entry: Entry template of summarypage entry |
|
|
|
|
|
@type text: mwparser.template |
|
|
|
|
|
@param force-reload: If given, countrylists will be always parsed |
|
|
|
|
|
regardless if needed or not |
|
|
|
|
|
@type force-reload: bool |
|
|
""" |
|
|
""" |
|
|
self.old_entry = SummaryPageEntryTemplate( entry ) |
|
|
self.old_entry = SummaryPageEntryTemplate( entry ) |
|
|
self.new_entry = SummaryPageEntryTemplate( ) |
|
|
self.new_entry = SummaryPageEntryTemplate( ) |
|
|
|
|
|
|
|
|
|
|
|
# Force parsing of countrylist |
|
|
|
|
|
self.force_reload = force_reload |
|
|
|
|
|
|
|
|
def treat( self ): |
|
|
def treat( self ): |
|
|
""" |
|
|
""" |
|
|
Controls parsing/update-sequence of entry |
|
|
Controls parsing/update-sequence of entry |
|
@ -134,9 +155,7 @@ class SummaryPageEntry(): |
|
|
try: |
|
|
try: |
|
|
self.countrylist = CountryList( self.countrylist_wikilink ) |
|
|
self.countrylist = CountryList( self.countrylist_wikilink ) |
|
|
|
|
|
|
|
|
if( self.countrylist and |
|
|
self.maybe_parse_countrylist() |
|
|
self.countrylist.is_parsing_needed( self.countrylist_revid )): |
|
|
|
|
|
self.countrylist.parse() |
|
|
|
|
|
|
|
|
|
|
|
# Maybe fallback to last years list |
|
|
# Maybe fallback to last years list |
|
|
except CountryListError: |
|
|
except CountryListError: |
|
@ -144,13 +163,26 @@ class SummaryPageEntry(): |
|
|
self.countrylist_wikilink.title = link_title |
|
|
self.countrylist_wikilink.title = link_title |
|
|
self.countrylist = CountryList( self.countrylist_wikilink ) |
|
|
self.countrylist = CountryList( self.countrylist_wikilink ) |
|
|
|
|
|
|
|
|
if( self.countrylist and |
|
|
self.maybe_parse_countrylist() |
|
|
self.countrylist.is_parsing_needed( self.countrylist_revid )): |
|
|
|
|
|
self.countrylist.parse() |
|
|
|
|
|
|
|
|
|
|
|
if not self.countrylist: |
|
|
if not self.countrylist: |
|
|
raise SummaryPageEntryError( "CountryList does not exists!" ) |
|
|
raise SummaryPageEntryError( "CountryList does not exists!" ) |
|
|
|
|
|
|
|
|
|
|
|
def maybe_parse_countrylist( self ): |
|
|
|
|
|
""" |
|
|
|
|
|
Parse countrylist if page-object exists and if parsing is needed or |
|
|
|
|
|
param -force-reload is set |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
# Fast return if no countrylist-object |
|
|
|
|
|
if not self.countrylist: |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
# Parse if needed or forced |
|
|
|
|
|
if( self.countrylist.is_parsing_needed( self.countrylist_revid ) or |
|
|
|
|
|
self.force_reload ): |
|
|
|
|
|
self.countrylist.parse() |
|
|
|
|
|
|
|
|
def get_countrylist_wikilink( self ): |
|
|
def get_countrylist_wikilink( self ): |
|
|
""" |
|
|
""" |
|
|
Load wikilink to related countrylist |
|
|
Load wikilink to related countrylist |
|
@ -250,8 +282,8 @@ class SummaryPageEntryTemplate(): |
|
|
Creates Instance of Class for given mwparser.template object of |
|
|
Creates Instance of Class for given mwparser.template object of |
|
|
SummmaryPageEntry Template. If no object was given create empty one. |
|
|
SummmaryPageEntry Template. If no object was given create empty one. |
|
|
|
|
|
|
|
|
@param template_obj mw.parser.template Object of |
|
|
@param template_obj Object of SummmaryPageEntry Template |
|
|
SummmaryPageEntry Template |
|
|
@type template_obj: mwparser.template |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
# Check if object was given |
|
|
# Check if object was given |
|
|