You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.3 KiB
68 lines
2.3 KiB
3 years ago
|
import os
|
||
|
import shutil
|
||
7 months ago
|
|
||
7 months ago
|
from flask import render_template
|
||
7 months ago
|
|
||
|
from distribusikan.distribusisinfo import DistribusisInfo
|
||
3 years ago
|
from forms.distribusiform import DistribusiForm
|
||
3 years ago
|
from forms.publicthemeform import PublicThemeForm
|
||
3 years ago
|
from forms.selectorform import SelectorForm
|
||
7 months ago
|
from forms.themeform import ThemeForm
|
||
|
from forms.uploadform import UploadForm
|
||
|
from statuspengguna.helper import UserHelper
|
||
3 years ago
|
|
||
|
|
||
|
def ThemeSelector():
|
||
|
themeform = ThemeForm()
|
||
3 years ago
|
publicthemeform = PublicThemeForm()
|
||
|
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||
3 years ago
|
current_distribusi = UserHelper.current_distribusi()
|
||
3 years ago
|
if themeform.validate_on_submit():
|
||
3 years ago
|
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(
|
||
7 months ago
|
themeform, publicthemeform, current_distribusi
|
||
3 years ago
|
)
|
||
|
|
||
3 years ago
|
|
||
3 years ago
|
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)
|
||
3 years ago
|
|
||
|
|
||
3 years ago
|
def RenderDistribusiTemplate(themeform, publicthemeform, current_distribusi):
|
||
3 years ago
|
uploadform = UploadForm()
|
||
|
distribusiform = DistribusiForm()
|
||
|
selectorform = SelectorForm()
|
||
|
|
||
3 years ago
|
files_uploaded = UserHelper.is_zip_uploaded(current_distribusi)
|
||
|
distribusi_live = UserHelper.is_distribusi_live(current_distribusi)
|
||
|
css_selected = UserHelper.is_css_selected(current_distribusi)
|
||
3 years ago
|
selectorvisible = False
|
||
3 years ago
|
limit_reached = UserHelper.distribusi_limit_reached()
|
||
3 years ago
|
template = render_template(
|
||
|
"distribusi.html",
|
||
|
uploadform=uploadform,
|
||
|
distribusiform=distribusiform,
|
||
|
themeform=themeform,
|
||
3 years ago
|
publicthemeform=publicthemeform,
|
||
3 years ago
|
selectorform=selectorform,
|
||
|
files_uploaded=files_uploaded,
|
||
|
distribusi_live=distribusi_live,
|
||
|
css_selected=css_selected,
|
||
|
selectorvisible=selectorvisible,
|
||
3 years ago
|
limit_reached=limit_reached,
|
||
3 years ago
|
)
|
||
|
return template
|