2022-03-19 16:19:51 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
2024-04-21 20:44:08 +02:00
|
|
|
|
2024-04-24 23:05:36 +02:00
|
|
|
from flask import render_template
|
2024-04-28 13:04:07 +02:00
|
|
|
|
2024-06-17 22:36:23 +02:00
|
|
|
from distribusikan.distribusis_info import DistribusisInfo
|
2024-06-02 22:14:13 +02:00
|
|
|
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
|
2024-04-21 20:44:08 +02:00
|
|
|
from statuspengguna.helper import UserHelper
|
2022-03-19 16:19:51 +01:00
|
|
|
|
|
|
|
|
2024-06-17 22:36:23 +02:00
|
|
|
def theme_selector():
|
2024-05-28 23:02:17 +02:00
|
|
|
themeform = ThemeForm()
|
|
|
|
publicthemeform = PublicThemeForm()
|
2024-06-17 22:36:23 +02:00
|
|
|
publicthemeform.publicthemes.choices = DistribusisInfo.public_themes()
|
2024-05-28 23:02:17 +02:00
|
|
|
current_distribusi = UserHelper.current_distribusi()
|
|
|
|
if themeform.validate_on_submit():
|
|
|
|
copycssfile = os.path.join(
|
|
|
|
"themes",
|
|
|
|
f"{themeform.theme.data}.css",
|
|
|
|
)
|
2024-06-17 22:36:23 +02:00
|
|
|
move_css_to_user_folder(current_distribusi, copycssfile)
|
2024-05-28 23:02:17 +02:00
|
|
|
if publicthemeform.validate_on_submit():
|
|
|
|
copycssfile = os.path.join(
|
|
|
|
"themes/publicthemes/",
|
|
|
|
f"{publicthemeform.publicthemes.data}.css",
|
|
|
|
)
|
2024-06-17 22:36:23 +02:00
|
|
|
move_css_to_user_folder(current_distribusi, copycssfile)
|
|
|
|
return render_distribusi_template(
|
2024-05-28 23:02:17 +02:00
|
|
|
themeform, publicthemeform, current_distribusi
|
|
|
|
)
|
2022-03-19 17:08:04 +01:00
|
|
|
|
2022-03-19 16:19:51 +01:00
|
|
|
|
2024-06-17 22:36:23 +02:00
|
|
|
def move_css_to_user_folder(current_distribusi, copycssfile):
|
2024-05-28 23:02:17 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
2024-06-17 22:36:23 +02:00
|
|
|
def render_distribusi_template(themeform, publicthemeform, current_distribusi):
|
2024-05-28 23:02:17 +02:00
|
|
|
uploadform = UploadForm()
|
|
|
|
distribusiform = DistribusiForm()
|
|
|
|
selectorform = SelectorForm()
|
2022-03-19 16:19:51 +01:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
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
|