Check if notice is present before add
To prevent duplications we need to check wether notice is already present on talkpage Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=88 FS#88]
This commit is contained in:
@@ -142,7 +142,12 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat()
|
|||||||
other template in leading section
|
other template in leading section
|
||||||
"""
|
"""
|
||||||
# The notice to add
|
# The notice to add
|
||||||
notice = self.current_page.redfam.generate_disc_notice_template()
|
self.disc_notice = \
|
||||||
|
self.current_page.redfam.generate_disc_notice_template()
|
||||||
|
|
||||||
|
# Check if it is already present in wikicode
|
||||||
|
if self.disc_notice_present():
|
||||||
|
return False
|
||||||
|
|
||||||
# Find the right place to insert notice template
|
# Find the right place to insert notice template
|
||||||
# Therfore we need the first section (if there is one)
|
# Therfore we need the first section (if there is one)
|
||||||
@@ -156,16 +161,43 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat()
|
|||||||
|
|
||||||
# If there is one, add notice after this
|
# If there is one, add notice after this
|
||||||
if ltemplate:
|
if ltemplate:
|
||||||
self.current_wikicode.insert_after(ltemplate, notice )
|
self.current_wikicode.insert_after(ltemplate, self.disc_notice)
|
||||||
|
|
||||||
# To have it in its own line we need to add a linbreak before
|
# To have it in its own line we need to add a linbreak before
|
||||||
self.current_wikicode.insert_before(notice, "\n" )
|
self.current_wikicode.insert_before(self.disc_notice, "\n" )
|
||||||
|
|
||||||
# If there is no template, add before first element on page
|
# If there is no template, add before first element on page
|
||||||
else:
|
else:
|
||||||
self.current_wikicode.insert( 0, notice )
|
self.current_wikicode.insert( 0, self.disc_notice )
|
||||||
|
|
||||||
# If there is no leadsec (and therefore no template in it, we will add
|
# If there is no leadsec (and therefore no template in it, we will add
|
||||||
# before the first element
|
# before the first element
|
||||||
else:
|
else:
|
||||||
self.current_wikicode.insert( 0, notice )
|
self.current_wikicode.insert( 0, self.disc_notice )
|
||||||
|
|
||||||
|
# Notice was added
|
||||||
|
return True
|
||||||
|
|
||||||
|
def disc_notice_present(self):
|
||||||
|
"""
|
||||||
|
Checks if disc notice which shall be added is already present.
|
||||||
|
"""
|
||||||
|
# Iterate over Templates with same name (if any) to search equal
|
||||||
|
# Link to decide if they are the same
|
||||||
|
for present_notice in self.current_wikicode.ifilter_templates(
|
||||||
|
matches=self.disc_notice.name ):
|
||||||
|
|
||||||
|
# Get reddisc page.title of notice to add
|
||||||
|
add_notice_link_tile = self.disc_notice.get(
|
||||||
|
"Diskussion").partition("#")[0]
|
||||||
|
# Get reddisc page.title of possible present notice
|
||||||
|
present_notice_link_tile = present_notice.get(
|
||||||
|
"Diskussion").partition("#")[0]
|
||||||
|
|
||||||
|
# If those are equal, notice is already present
|
||||||
|
if add_notice_link_tile == present_notice_link_tile:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# If nothing is found, loop will run till its end
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user