Css editor placeholder is the current custom theme if there is one

This commit is contained in:
crunk 2022-03-25 15:51:06 +01:00
parent 730a12accd
commit 8dc7871d33
2 changed files with 26 additions and 6 deletions

View File

@ -18,12 +18,13 @@ class DistribusisInfo:
Distribusis.publictheme.isnot(None) Distribusis.publictheme.isnot(None)
).all() ).all()
for distribusi in distribusis: for distribusi in distribusis:
user = User.query.filter_by(id=distribusi.userid).first()
publictheme = ( publictheme = (
f"{distribusi.distribusiname}/{distribusi.publictheme}", f"{distribusi.distribusiname}/{distribusi.publictheme}",
f"{distribusi.publictheme} used in {distribusi.distribusiname}", # noqa: E501 f"""{distribusi.publictheme} used in {distribusi.distribusiname}
made by {user.username}""",
) )
publicthemes.append(publictheme) publicthemes.append(publictheme)
print(publicthemes)
return publicthemes return publicthemes
def visibledistribusis(): def visibledistribusis():

View File

@ -138,7 +138,7 @@ def RenderDistribusiTemplate(current_distribusi):
def RenderEditorTemplate(editorform, current_distribusi): def RenderEditorTemplate(editorform, current_distribusi):
htmlplaceholder = HtmlPlaceholder() htmlplaceholder = HtmlPlaceholder()
cssplaceholder = CssPlaceholder() cssplaceholder = CssPlaceholder(current_distribusi)
editorform.css.data = cssplaceholder editorform.css.data = cssplaceholder
files_uploaded = IsZipUploaded(current_distribusi) files_uploaded = IsZipUploaded(current_distribusi)
@ -153,10 +153,16 @@ def RenderEditorTemplate(editorform, current_distribusi):
return template return template
def CssPlaceholder(): def CssPlaceholder(current_distribusi):
cssplaceholder = "Try out your CSS here" cssplaceholder = "Try out your CSS here"
with open("themes/editor/placeholder.css") as f: distribusi = Distribusis.query.filter_by(
cssplaceholder = f.read() distribusiname=current_distribusi
).first()
if distribusi is not None:
cssplaceholder = GetPublicCssFile(distribusi)
else:
with open("themes/editor/placeholder.css") as f:
cssplaceholder = f.read()
return cssplaceholder return cssplaceholder
@ -165,3 +171,16 @@ def HtmlPlaceholder():
with open("themes/editor/placeholder.html") as f: with open("themes/editor/placeholder.html") as f:
htmlplaceholder = f.read() htmlplaceholder = f.read()
return htmlplaceholder return htmlplaceholder
def GetPublicCssFile(distribusi):
cssplaceholder = ""
publicthemefolder = os.path.join(
"themes/publicthemes", distribusi.distribusiname
)
for filename in os.listdir(publicthemefolder):
if filename.endswith(".css"):
cssfile = os.path.join(publicthemefolder, filename)
with open(cssfile) as f:
cssplaceholder = f.read()
return cssplaceholder