Skip to content

Commit

Permalink
prepares frame handling for #14
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Mar 7, 2021
1 parent 638c5cb commit c088a99
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
30 changes: 29 additions & 1 deletion frontend/wikicms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: wf
'''
from wikibot.wikiclient import WikiClient
from wikibot.smw import SMWClient
from frontend.site import Site
from bs4 import BeautifulSoup
import traceback
Expand Down Expand Up @@ -43,7 +44,8 @@ def open(self):
'''
if self.wiki is None:
self.wiki=WikiClient.ofWikiId(self.site.wikiId)
#self.wiki.login()
self.wiki.login()
self.smwclient=SMWClient(self.wiki.getSite())

def errMsg(self,ex):
if self.debug:
Expand Down Expand Up @@ -123,6 +125,31 @@ def filterEditSections(self,html):
for s in soup.select('span',{"class": "mw-editsection"}):
s.extract()
return str(soup)

def getFrame(self,pageTitle):
'''
get the frame template to be used for the given pageTitle#
Args:
pageTitle(str): the pageTitle to get the Property:Frame for
Returns:
str: the frame or None
'''
askQuery="""{{#ask: [[%s]]
|mainlabel=-
|?Frame=frame
}}
""" % pageTitle
frame=None
frameResult=self.smwclient.query(askQuery)
if pageTitle in frameResult:
frameRow=frameResult[pageTitle]
frame=frameRow['frame']
# legacy java handling
frame=frame.replace(".rythm","")
pass
return frame

def getContent(self,pagePath:str,dofilterEditSections=True):
''' get the content for the given pagePath
Expand All @@ -144,6 +171,7 @@ def getContent(self,pagePath:str,dofilterEditSections=True):
if error is None:
if self.wiki is None:
raise Exception("getContent without wiki - you might want to call open first")
frame=self.getFrame(pageTitle)
content=self.wiki.getHtml(pageTitle)
if dofilterEditSections:
content=self.filterEditSections(content)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ def testProxy(self):
self.assertEqual("200 OK",imageResponse.status)
self.assertEqual(79499,len(imageResponse.data))

def testIssue14(self):
'''
test Allow to use templates specified in Wiki
https://github.com/BITPlan/pyWikiCMS/issues/14
'''
# see e.g. http://wiki.bitplan.com/index.php/Property:Frame
frontend=self.server.enableFrontend('wiki')
pageTitle="Feedback"
frame=frontend.getFrame(pageTitle)
self.assertEqual("Contact",frame)
html=frontend.getContent(pageTitle)
print(html)

def testIssue15(self):
'''
test Filter "edit" section buttons
Expand Down
6 changes: 6 additions & 0 deletions tests/test_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def initServer():
'wikiId':'wiki',
'template':'bootstrap.html',
'defaultPage':'Sharks'
},
{
'site': 'wiki',
'wikiId':'wiki',
'template':'bootstrap.html',
'defaultPage':'Welcome'
}
]
for frontendConfigs in server.frontendConfigs:
Expand Down

0 comments on commit c088a99

Please sign in to comment.