distribusi-verse: medium-tech web app content management system for the web
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.
 
 
 
 
 

74 lines
2.3 KiB

import os
import shutil
from flask import render_template
from statuspengguna.helper import (
IsZipUploaded,
IsCssSelected,
CurrentDistribusi,
IsDistribusiLive,
DistribusiLimitReached,
)
from distribusisinfo import DistribusisInfo
from forms.uploadform import UploadForm
from forms.distribusiform import DistribusiForm
from forms.themeform import ThemeForm
from forms.publicthemeform import PublicThemeForm
from forms.selectorform import SelectorForm
def ThemeSelector():
themeform = ThemeForm()
publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
current_distribusi = CurrentDistribusi()
if themeform.validate_on_submit():
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
)
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)
def RenderDistribusiTemplate(themeform, publicthemeform, current_distribusi):
uploadform = UploadForm()
distribusiform = DistribusiForm()
selectorform = SelectorForm()
files_uploaded = IsZipUploaded(current_distribusi)
distribusi_live = IsDistribusiLive(current_distribusi)
css_selected = IsCssSelected(current_distribusi)
selectorvisible = False
limit_reached = DistribusiLimitReached()
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