Don't overwrite default themes during import

main
Bob Mottram 2021-05-30 12:06:15 +01:00
parent e7ae1c0561
commit f06d1b20b3
3 changed files with 38 additions and 0 deletions

16
defaultthemes.txt 100644
View File

@ -0,0 +1,16 @@
Blue
Debian
Default
Hacker
Henge
Indymediaclassic
Indymediamodern
Lcd
Light
Night
Pixel
Purple
Rc3
Solidaric
Starlight
Zen

View File

@ -101,6 +101,7 @@ from content import removeLongWords
from content import replaceContentDuplicates from content import replaceContentDuplicates
from content import removeTextFormatting from content import removeTextFormatting
from content import removeHtmlTag from content import removeHtmlTag
from theme import updateDefaultThemesList
from theme import setCSSparam from theme import setCSSparam
from linked_data_sig import generateJsonSignature from linked_data_sig import generateJsonSignature
from linked_data_sig import verifyJsonSignature from linked_data_sig import verifyJsonSignature
@ -3721,6 +3722,7 @@ def testRoles() -> None:
def runAllTests(): def runAllTests():
print('Running tests...') print('Running tests...')
updateDefaultThemesList(os.getcwd())
testFunctions() testFunctions()
testRoles() testRoles()
testSkills() testSkills()

View File

@ -52,6 +52,13 @@ def importTheme(baseDir: str, filename: str) -> bool:
return False return False
if not newThemeName: if not newThemeName:
return False return False
# if the theme name in the default themes list?
defaultThemesFilename = baseDir + '/defaultthemes.txt'
if os.path.isfile(defaultThemesFilename):
if newThemeName.title() + '\n' in open(defaultThemesFilename).read():
newThemeName = newThemeName + '2'
themeDir = baseDir + '/theme/' + newThemeName themeDir = baseDir + '/theme/' + newThemeName
if not os.path.isdir(themeDir): if not os.path.isdir(themeDir):
os.mkdir(themeDir) os.mkdir(themeDir)
@ -791,3 +798,16 @@ def setTheme(baseDir: str, name: str, domain: str,
_setThemeInConfig(baseDir, name) _setThemeInConfig(baseDir, name)
_setClearCacheFlag(baseDir) _setClearCacheFlag(baseDir)
return result return result
def updateDefaultThemesList(baseDir: str) -> None:
"""Recreates the list of default themes
"""
themeNames = getThemesList(baseDir)
defaultThemesFilename = baseDir + '/defaultthemes.txt'
defaultThemesFile = open(defaultThemesFilename, "w+")
if not defaultThemesFile:
return
for name in themeNames:
defaultThemesFile.write(name + '\n')
defaultThemesFile.close()