forked from crunk/distribusi-verse
public theme prototype
This commit is contained in:
parent
4d754e226e
commit
538394dfef
@ -18,7 +18,9 @@ class DistribusisInfo:
|
||||
Distribusis.publictheme.isnot(None)
|
||||
).all()
|
||||
for distribusi in distribusis:
|
||||
publicthemes.append(
|
||||
f"{distribusi.publictheme} used in {distribusi.distribusiname}"
|
||||
publictheme = (
|
||||
f"{distribusi.distribusiname}/{distribusi.publictheme}",
|
||||
f"{distribusi.publictheme} used in {distribusi.distribusiname}",
|
||||
)
|
||||
publicthemes.append(publictheme)
|
||||
return publicthemes
|
||||
|
@ -19,6 +19,7 @@ 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.editorform import EditorForm
|
||||
from forms.selectorform import SelectorForm
|
||||
|
||||
@ -92,7 +93,8 @@ def RenderDistribusiTemplate(current_distribusi):
|
||||
uploadform = UploadForm()
|
||||
distribusiform = DistribusiForm()
|
||||
themeform = ThemeForm()
|
||||
themeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
publicthemeform = PublicThemeForm()
|
||||
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
selectorform = SelectorForm()
|
||||
|
||||
files_uploaded = IsZipUploaded(current_distribusi)
|
||||
@ -105,6 +107,7 @@ def RenderDistribusiTemplate(current_distribusi):
|
||||
uploadform=uploadform,
|
||||
distribusiform=distribusiform,
|
||||
themeform=themeform,
|
||||
publicthemeform=publicthemeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
distribusi_live=distribusi_live,
|
||||
|
16
verse/forms/publicthemeform.py
Normal file
16
verse/forms/publicthemeform.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""Form object declaration."""
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import (
|
||||
RadioField,
|
||||
SubmitField,
|
||||
)
|
||||
|
||||
|
||||
class PublicThemeForm(FlaskForm):
|
||||
"""PublicTheme selection form."""
|
||||
|
||||
publicthemes = RadioField(
|
||||
"Public themes from other distribusi-verse users:"
|
||||
)
|
||||
|
||||
save = SubmitField("Save")
|
@ -18,8 +18,4 @@ class ThemeForm(FlaskForm):
|
||||
],
|
||||
)
|
||||
|
||||
publicthemes = RadioField(
|
||||
"Public themes from other distribusi-verse users:"
|
||||
)
|
||||
|
||||
save = SubmitField("Save")
|
||||
|
@ -26,6 +26,7 @@ from distribusimodel import Distribusis
|
||||
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
|
||||
|
||||
# CRUD!
|
||||
@ -105,7 +106,8 @@ def distribusi():
|
||||
uploadform = UploadForm()
|
||||
distribusiform = DistribusiForm()
|
||||
themeform = ThemeForm()
|
||||
themeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
publicthemeform = PublicThemeForm()
|
||||
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
selectorform = SelectorForm()
|
||||
selectorform.distribusis.choices = DistribusisInfo.userdistribusis()
|
||||
|
||||
@ -152,6 +154,7 @@ def distribusi():
|
||||
uploadform=uploadform,
|
||||
distribusiform=distribusiform,
|
||||
themeform=themeform,
|
||||
publicthemeform=publicthemeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
distribusi_live=distribusi_live,
|
||||
@ -166,7 +169,8 @@ def distribusi():
|
||||
def upload():
|
||||
distribusiform = DistribusiForm()
|
||||
themeform = ThemeForm()
|
||||
themeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
publicthemeform = PublicThemeForm()
|
||||
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
selectorform = SelectorForm()
|
||||
selectorform.distribusis.choices = DistribusisInfo.userdistribusis()
|
||||
selectorvisible = SelectorVisible()
|
||||
@ -183,6 +187,7 @@ def upload():
|
||||
uploadform=uploadform,
|
||||
distribusiform=distribusiform,
|
||||
themeform=themeform,
|
||||
publicthemeform=publicthemeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
distribusi_live=distribusi_live,
|
||||
@ -211,7 +216,8 @@ def selector():
|
||||
uploadform = UploadForm()
|
||||
distribusiform = DistribusiForm()
|
||||
themeform = ThemeForm()
|
||||
themeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
publicthemeform = PublicThemeForm()
|
||||
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
selectorform = SelectorForm()
|
||||
selectorform.distribusis.choices = DistribusisInfo.userdistribusis()
|
||||
current_distribusi = CurrentDistribusi()
|
||||
@ -250,6 +256,7 @@ def selector():
|
||||
uploadform=uploadform,
|
||||
distribusiform=distribusiform,
|
||||
themeform=themeform,
|
||||
publicthemeform=publicthemeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
distribusi_live=distribusi_live,
|
||||
|
@ -1,17 +1,14 @@
|
||||
<div id="theme" class="workflow">
|
||||
<h3>(Optional) Step 2: Theme</h3>
|
||||
<p>Select your Theme here. If you want your own custom css, skip and go to
|
||||
step 3. Don't forget to press Save</p>
|
||||
<h3>(Optional) Step 2: Choose a Theme</h3>
|
||||
<p>Select your Theme here. If you want to make own custom css, skip and go to
|
||||
step 3.</p>
|
||||
<p>Don't forget to press Save</p>
|
||||
<form method="POST" enctype="multipart/form-data" action="{{ url_for('theme') }}">
|
||||
{{ themeform.csrf_token }}
|
||||
<fieldset class="required">
|
||||
{{ themeform.theme.label }}
|
||||
{{ themeform.theme }}
|
||||
</fieldset>
|
||||
<fieldset class="required">
|
||||
{{ themeform.publicthemes.label }}
|
||||
{{ themeform.publicthemes }}
|
||||
</fieldset>
|
||||
{% if files_uploaded or distribusi_live %}
|
||||
<fieldset class="button required">
|
||||
{{ themeform.save }}
|
||||
@ -24,4 +21,23 @@
|
||||
<a href="#upload">Go to Step 1</a>
|
||||
{% endif %}
|
||||
</form>
|
||||
<hr>
|
||||
<form method="POST" enctype="multipart/form-data" action="{{ url_for('theme') }}">
|
||||
{{ publicthemeform.csrf_token }}
|
||||
<fieldset class="required">
|
||||
{{ publicthemeform.publicthemes.label }}
|
||||
{{ publicthemeform.publicthemes }}
|
||||
</fieldset>
|
||||
{% if files_uploaded or distribusi_live %}
|
||||
<fieldset class="button required">
|
||||
{{ publicthemeform.save }}
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<p>
|
||||
You need to upload your files first before you can a css theme
|
||||
for your files.
|
||||
</p>
|
||||
<a href="#upload">Go to Step 1</a>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
|
@ -12,39 +12,44 @@ 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()
|
||||
themeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
publicthemeform = PublicThemeForm()
|
||||
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
current_distribusi = CurrentDistribusi()
|
||||
if themeform.validate_on_submit():
|
||||
newcssfolder = os.path.join("themes/userthemes", current_distribusi)
|
||||
if not os.path.exists(newcssfolder):
|
||||
os.mkdir(newcssfolder)
|
||||
if themeform.theme.data:
|
||||
copycssfile = os.path.join(
|
||||
"themes",
|
||||
f"{themeform.theme.data}.css",
|
||||
)
|
||||
if themeform.publicthemes.data:
|
||||
publictheme = themeform.publicthemes.data
|
||||
copycssfile = os.path.join(
|
||||
"themes/publicthemes",
|
||||
f"{distribusiname}",
|
||||
f"{themename}.css",
|
||||
)
|
||||
shutil.copy(copycssfile, newcssfolder)
|
||||
|
||||
return RenderDistribusiTemplate(current_distribusi)
|
||||
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 RenderDistribusiTemplate(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()
|
||||
themeform = ThemeForm()
|
||||
themeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||
selectorform = SelectorForm()
|
||||
|
||||
files_uploaded = IsZipUploaded(current_distribusi)
|
||||
@ -57,6 +62,7 @@ def RenderDistribusiTemplate(current_distribusi):
|
||||
uploadform=uploadform,
|
||||
distribusiform=distribusiform,
|
||||
themeform=themeform,
|
||||
publicthemeform=publicthemeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
distribusi_live=distribusi_live,
|
||||
|
Loading…
Reference in New Issue
Block a user