distribusi-verse/verse/themeselector.py

70 lines
2.3 KiB
Python
Raw Normal View History

2022-03-19 16:19:51 +01:00
import os
import shutil
from flask import render_template
from statuspengguna.helper import UserHelper
2022-03-19 16:19:51 +01:00
from distribusisinfo import DistribusisInfo
from forms.uploadform import UploadForm
from forms.distribusiform import DistribusiForm
from forms.themeform import ThemeForm
2022-03-19 17:08:04 +01:00
from forms.publicthemeform import PublicThemeForm
2022-03-19 16:19:51 +01:00
from forms.selectorform import SelectorForm
def ThemeSelector():
themeform = ThemeForm()
2022-03-19 17:08:04 +01:00
publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
current_distribusi = UserHelper.current_distribusi()
2022-03-19 16:19:51 +01:00
if themeform.validate_on_submit():
2022-03-19 17:08:04 +01:00
copycssfile = os.path.join(
"themes",
f"{themeform.theme.data}.css",
)
MoveCssToUserFolder(current_distribusi, copycssfile)
if publicthemeform.validate_on_submit():
copycssfile = os.path.join(
"themes/publicthemes/",
f"{publicthemeform.publicthemes.data}.css",
)
MoveCssToUserFolder(current_distribusi, copycssfile)
return RenderDistribusiTemplate(
themeform,
publicthemeform,
current_distribusi
)
2022-03-19 16:19:51 +01:00
2022-03-19 17:08:04 +01:00
def MoveCssToUserFolder(current_distribusi, copycssfile):
newcssfolder = os.path.join("themes/userthemes", current_distribusi)
if not os.path.exists(newcssfolder):
os.mkdir(newcssfolder)
shutil.copy(copycssfile, newcssfolder)
2022-03-19 16:19:51 +01:00
2022-03-19 17:08:04 +01:00
def RenderDistribusiTemplate(themeform, publicthemeform, current_distribusi):
2022-03-19 16:19:51 +01:00
uploadform = UploadForm()
distribusiform = DistribusiForm()
selectorform = SelectorForm()
files_uploaded = UserHelper.is_zip_uploaded(current_distribusi)
distribusi_live = UserHelper.is_distribusi_live(current_distribusi)
css_selected = UserHelper.is_css_selected(current_distribusi)
2022-03-19 16:19:51 +01:00
selectorvisible = False
limit_reached = UserHelper.distribusi_limit_reached()
2022-03-19 16:19:51 +01:00
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
2022-03-19 17:08:04 +01:00
publicthemeform=publicthemeform,
2022-03-19 16:19:51 +01:00
selectorform=selectorform,
files_uploaded=files_uploaded,
distribusi_live=distribusi_live,
css_selected=css_selected,
selectorvisible=selectorvisible,
limit_reached=limit_reached,
2022-03-19 16:19:51 +01:00
)
return template