Skip to content

Commit

Permalink
refactors to prepare templateFolder handling
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Mar 8, 2021
1 parent b0cdb9c commit db3e522
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions frontend/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: wf
'''
import os
from wikibot.smw import SMWClient

class Site(object):
'''
Expand Down Expand Up @@ -33,5 +34,9 @@ def configure(self,config:dict):
self.wikiId=config['wikiId']
self.defaultPage=config['defaultPage']
self.template=config['template']
if "templateFolder" in config:
self.templateFolder=config['templateFolder']
else:
self.templateFolder=self.name


20 changes: 17 additions & 3 deletions frontend/wikicms.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ def getFrame(self,pageTitle):
}}
""" % pageTitle
frame=None
frameResult=self.smwclient.query(askQuery)
frameResult={}
try:
frameResult=self.smwclient.query(askQuery)
except Exception as ex:
if "invalid characters" in str(ex):
pass
else:
raise ex
if pageTitle in frameResult:
frameRow=frameResult[pageTitle]
frame=frameRow['frame']
Expand All @@ -152,7 +159,7 @@ def getFrame(self,pageTitle):
pass
return frame

def getContent(self,pagePath:str,dofilterEditSections=True):
def getPageContent(self,pagePath:str,dofilterEditSections=True):
''' get the content for the given pagePath
Args:
pagePath(str): the pagePath
Expand All @@ -172,11 +179,18 @@ 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)
except Exception as e:
error=self.errMsg(e)
return pageTitle,content,error

def getContent(self,pagePath:str,dofilterEditSections=True):
'''
get the content for the given pagePath
'''
pageTitle,content,error=self.getPageContent(pagePath, dofilterEditSections)
frame=self.getFrame(pageTitle)
return pageTitle,content,error

8 changes: 8 additions & 0 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def testProxy(self):
self.assertEqual("200 OK",imageResponse.status)
self.assertEqual(79499,len(imageResponse.data))


def testIssue14Templates(self):
'''
test template handling
'''
frontend=self.server.enableFrontend('wiki')
print (frontend.site)

def testIssue14(self):
'''
test Allow to use templates specified in Wiki
Expand Down

0 comments on commit db3e522

Please sign in to comment.