Skip to content

Commit

Permalink
fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Mar 6, 2021
1 parent abe66a8 commit 4646dc9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
21 changes: 18 additions & 3 deletions frontend/wikicms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'''
from wikibot.wikiclient import WikiClient
from frontend.site import Site

from bs4 import BeautifulSoup
import traceback

import requests
Expand Down Expand Up @@ -113,11 +113,22 @@ def proxy(self,path:str)->str:
r = requests.get(url)
return Response(r.content)

def filterEditSections(self,html):
'''
filter Edit sections from html code
'''
# https://stackoverflow.com/questions/5598524/can-i-remove-script-tags-with-beautifulsoup
soup = BeautifulSoup(html,'lxml')
# https://stackoverflow.com/questions/5041008/how-to-find-elements-by-class
for s in soup.select('span',{"class": "mw-editsection"}):
s.extract()
return str(soup)

def getContent(self,pagePath:str):
def getContent(self,pagePath:str,dofilterEditSections=True):
''' get the content for the given pagePath
Args:
pagePath(str): the page Pageh
pagePath(str): the pagePath
dofilterEditSections(bool): True if editSection html code should be filtered
Returns:
str: the HTML content for the given path
'''
Expand All @@ -131,7 +142,11 @@ def getContent(self,pagePath:str):
error=self.checkPath(pagePath)
pageTitle=self.wikiPage(pagePath)
if error is None:
if self.wiki is None:
raise Exception("getContent without wiki - you might want to call open first")
content=self.wiki.getHtml(pageTitle)
if dofilterEditSections:
content=self.filterEditSections(content)
except Exception as e:
error=self.errMsg(e)
return pageTitle,content,error
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
long_description = open('../../README.md').read()

setup(name='pyWikiCMS',
version='0.0.4',
version='0.0.5',
description='python implementation of a Mediawiki based Content Management System',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
6 changes: 5 additions & 1 deletion templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@
{% macro activateDataTable() -%}
<script type="text/javascript">
$(document).ready(function() {
$('.table').DataTable();
$('.table').DataTable({
buttons: [
'copy', 'excel', 'pdf'
]
});
});
</script>
{%- endmacro %}
22 changes: 22 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from frontend.wikicms import Frontend
from tests.test_webserver import TestWebServer


class TestFrontend(unittest.TestCase):
'''
test the frontend
Expand Down Expand Up @@ -48,6 +49,27 @@ def testProxy(self):
self.assertFalse(imageResponse is None)
self.assertEqual("200 OK",imageResponse.status)
self.assertEqual(79499,len(imageResponse.data))

def testIssue15(self):
'''
test Filter "edit" section buttons
see https://github.com/BITPlan/pyWikiCMS/issues/15
'''
frontend=self.server.enableFrontend('cr')
unfiltered="""<span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=...;action=edit&amp;section=T-1" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span>"""
filtered=frontend.filterEditSections(unfiltered)
if self.debug:
print(filtered)
self.assertFalse('''<span class="mw-editsection">''' in filtered)
pageTitle,content,error=frontend.getContent('Issue15')
self.assertEqual("Issue15",pageTitle)
self.assertIsNone(error)
if self.debug:
print(content)
self.assertFalse('''<span class="mw-editsection">''' in content)


if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
Expand Down

0 comments on commit 4646dc9

Please sign in to comment.