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.4 KiB
68 lines
2.4 KiB
3 years ago
|
import os
|
||
|
import shutil
|
||
7 months ago
|
|
||
7 months ago
|
from flask import render_template
|
||
7 months ago
|
|
||
5 months ago
|
from distribusikan.distribusis_info import DistribusisInfo
|
||
5 months ago
|
from distribusikan.forms.distribusiform import DistribusiForm
|
||
|
from distribusikan.forms.publicthemeform import PublicThemeForm
|
||
|
from distribusikan.forms.selectorform import SelectorForm
|
||
|
from distribusikan.forms.themeform import ThemeForm
|
||
|
from distribusikan.forms.uploadform import UploadForm
|
||
7 months ago
|
from statuspengguna.helper import UserHelper
|
||
3 years ago
|
|
||
|
|
||
5 months ago
|
def theme_selector():
|
||
6 months ago
|
themeform = ThemeForm()
|
||
|
publicthemeform = PublicThemeForm()
|
||
5 months ago
|
publicthemeform.publicthemes.choices = DistribusisInfo.public_themes()
|
||
6 months ago
|
current_distribusi = UserHelper.current_distribusi()
|
||
|
if themeform.validate_on_submit():
|
||
|
copycssfile = os.path.join(
|
||
|
"themes",
|
||
|
f"{themeform.theme.data}.css",
|
||
|
)
|
||
5 months ago
|
move_css_to_user_folder(current_distribusi, copycssfile)
|
||
6 months ago
|
if publicthemeform.validate_on_submit():
|
||
|
copycssfile = os.path.join(
|
||
|
"themes/publicthemes/",
|
||
|
f"{publicthemeform.publicthemes.data}.css",
|
||
|
)
|
||
5 months ago
|
move_css_to_user_folder(current_distribusi, copycssfile)
|
||
|
return render_distribusi_template(
|
||
6 months ago
|
themeform, publicthemeform, current_distribusi
|
||
|
)
|
||
3 years ago
|
|
||
3 years ago
|
|
||
5 months ago
|
def move_css_to_user_folder(current_distribusi, copycssfile):
|
||
6 months ago
|
newcssfolder = os.path.join("themes/userthemes", current_distribusi)
|
||
|
if not os.path.exists(newcssfolder):
|
||
|
os.mkdir(newcssfolder)
|
||
|
shutil.copy(copycssfile, newcssfolder)
|
||
3 years ago
|
|
||
|
|
||
5 months ago
|
def render_distribusi_template(themeform, publicthemeform, current_distribusi):
|
||
6 months ago
|
uploadform = UploadForm()
|
||
|
distribusiform = DistribusiForm()
|
||
|
selectorform = SelectorForm()
|
||
3 years ago
|
|
||
6 months 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)
|
||
|
selectorvisible = False
|
||
|
limit_reached = UserHelper.distribusi_limit_reached()
|
||
|
template = render_template(
|
||
|
"distribusi.html",
|
||
|
uploadform=uploadform,
|
||
|
distribusiform=distribusiform,
|
||
|
themeform=themeform,
|
||
|
publicthemeform=publicthemeform,
|
||
|
selectorform=selectorform,
|
||
|
files_uploaded=files_uploaded,
|
||
|
distribusi_live=distribusi_live,
|
||
|
css_selected=css_selected,
|
||
|
selectorvisible=selectorvisible,
|
||
|
limit_reached=limit_reached,
|
||
|
)
|
||
|
return template
|