mirror of
https://github.com/YunoHost/apps.git
synced 2024-09-03 20:06:07 +02:00
Format Python code with Black (#2214)
Co-authored-by: ericgaspar <46165813+ericgaspar@users.noreply.github.com>
This commit is contained in:
parent
2d15532c31
commit
9620c78864
1 changed files with 204 additions and 127 deletions
|
@ -39,7 +39,7 @@ from wtforms.validators import (
|
||||||
from flask_babel import Babel
|
from flask_babel import Babel
|
||||||
from flask_babel import gettext
|
from flask_babel import gettext
|
||||||
|
|
||||||
from flask import redirect, request, make_response # Language swap by redirecting
|
from flask import redirect, request, make_response # Language swap by redirecting
|
||||||
|
|
||||||
# Markdown to HTML - for debugging purposes
|
# Markdown to HTML - for debugging purposes
|
||||||
from misaka import Markdown, HtmlRenderer
|
from misaka import Markdown, HtmlRenderer
|
||||||
|
@ -63,25 +63,26 @@ cors = CORS(app)
|
||||||
environment = j2.Environment(loader=j2.FileSystemLoader("templates/"))
|
environment = j2.Environment(loader=j2.FileSystemLoader("templates/"))
|
||||||
|
|
||||||
# Handle translations
|
# Handle translations
|
||||||
BABEL_TRANSLATION_DIRECTORIES='translations'
|
BABEL_TRANSLATION_DIRECTORIES = "translations"
|
||||||
|
|
||||||
babel = Babel()
|
babel = Babel()
|
||||||
|
|
||||||
LANGUAGES = {
|
LANGUAGES = {"en": "English", "fr": "French"}
|
||||||
'en': 'English',
|
|
||||||
'fr': 'French'
|
|
||||||
}
|
|
||||||
|
|
||||||
def configure(app):
|
def configure(app):
|
||||||
babel.init_app(app, locale_selector=get_locale)
|
babel.init_app(app, locale_selector=get_locale)
|
||||||
app.config['LANGUAGES'] = LANGUAGES
|
app.config["LANGUAGES"] = LANGUAGES
|
||||||
|
|
||||||
|
|
||||||
def get_locale():
|
def get_locale():
|
||||||
print(request.accept_languages.best_match(app.config['LANGUAGES'].keys()))
|
print(request.accept_languages.best_match(app.config["LANGUAGES"].keys()))
|
||||||
print(request.cookies.get('lang', 'en'))
|
print(request.cookies.get("lang", "en"))
|
||||||
#return 'en' # to test
|
# return 'en' # to test
|
||||||
#return 'fr'
|
# return 'fr'
|
||||||
return request.cookies.get('lang', 'en')
|
return request.cookies.get("lang", "en")
|
||||||
#return request.accept_languages.best_match(app.config['LANGUAGES'].keys()) # The result is based on the Accept-Language header. For testing purposes, you can directly return a language code, for example: return ‘de’
|
# return request.accept_languages.best_match(app.config['LANGUAGES'].keys()) # The result is based on the Accept-Language header. For testing purposes, you can directly return a language code, for example: return ‘de’
|
||||||
|
|
||||||
|
|
||||||
configure(app)
|
configure(app)
|
||||||
|
|
||||||
|
@ -112,12 +113,11 @@ def markdown_file_to_html_string(file):
|
||||||
|
|
||||||
### Forms
|
### Forms
|
||||||
|
|
||||||
|
|
||||||
class GeneralInfos(FlaskForm):
|
class GeneralInfos(FlaskForm):
|
||||||
|
|
||||||
app_id = StringField(
|
app_id = StringField(
|
||||||
Markup(
|
Markup(gettext("Application identifier (id)")),
|
||||||
gettext("Application identifier (id)")
|
|
||||||
),
|
|
||||||
description=gettext("Small caps and without spaces"),
|
description=gettext("Small caps and without spaces"),
|
||||||
validators=[DataRequired(), Regexp("[a-z_1-9]+.*(?<!_ynh)$")],
|
validators=[DataRequired(), Regexp("[a-z_1-9]+.*(?<!_ynh)$")],
|
||||||
render_kw={
|
render_kw={
|
||||||
|
@ -127,7 +127,9 @@ class GeneralInfos(FlaskForm):
|
||||||
|
|
||||||
app_name = StringField(
|
app_name = StringField(
|
||||||
gettext("App name"),
|
gettext("App name"),
|
||||||
description=gettext("It's the application name, displayed in the user interface"),
|
description=gettext(
|
||||||
|
"It's the application name, displayed in the user interface"
|
||||||
|
),
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()],
|
||||||
render_kw={
|
render_kw={
|
||||||
"placeholder": "My super App",
|
"placeholder": "My super App",
|
||||||
|
@ -136,7 +138,9 @@ class GeneralInfos(FlaskForm):
|
||||||
|
|
||||||
description_en = StringField(
|
description_en = StringField(
|
||||||
gettext("Short description (en)"),
|
gettext("Short description (en)"),
|
||||||
description=gettext("Explain in a few words (10-15) why this app is useful or what it does (the goal is to give a broad idea for the user browsing an hundred apps long catalog"),
|
description=gettext(
|
||||||
|
"Explain in a few words (10-15) why this app is useful or what it does (the goal is to give a broad idea for the user browsing an hundred apps long catalog"
|
||||||
|
),
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()],
|
||||||
)
|
)
|
||||||
description_fr = StringField(
|
description_fr = StringField(
|
||||||
|
@ -157,7 +161,9 @@ class IntegrationInfos(FlaskForm):
|
||||||
|
|
||||||
maintainers = StringField(
|
maintainers = StringField(
|
||||||
gettext("Maintener of the generated app"),
|
gettext("Maintener of the generated app"),
|
||||||
description=gettext("Commonly you put your name here... If you agree with it ;)")
|
description=gettext(
|
||||||
|
"Commonly you put your name here... If you agree with it ;)"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
yunohost_required_version = StringField(
|
yunohost_required_version = StringField(
|
||||||
|
@ -182,13 +188,17 @@ class IntegrationInfos(FlaskForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
multi_instance = BooleanField(
|
multi_instance = BooleanField(
|
||||||
gettext("The app can be installed multiple times at the same time on the same server"),
|
gettext(
|
||||||
|
"The app can be installed multiple times at the same time on the same server"
|
||||||
|
),
|
||||||
default=True,
|
default=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
ldap = SelectField(
|
ldap = SelectField(
|
||||||
gettext("The app will be integrating LDAP"),
|
gettext("The app will be integrating LDAP"),
|
||||||
description=gettext("Which means it's possible to use Yunohost credential to connect. 'LDAP' corresponds to the technology used by Yunohost to handle a centralised user base. Bridging the APP and Yunohost LDAP often requires to fill some parameters in the app configuration"),
|
description=gettext(
|
||||||
|
"Which means it's possible to use Yunohost credential to connect. 'LDAP' corresponds to the technology used by Yunohost to handle a centralised user base. Bridging the APP and Yunohost LDAP often requires to fill some parameters in the app configuration"
|
||||||
|
),
|
||||||
choices=[
|
choices=[
|
||||||
("false", gettext("No")),
|
("false", gettext("No")),
|
||||||
("true", gettext("Yes")),
|
("true", gettext("Yes")),
|
||||||
|
@ -199,7 +209,9 @@ class IntegrationInfos(FlaskForm):
|
||||||
)
|
)
|
||||||
sso = SelectField(
|
sso = SelectField(
|
||||||
gettext("The app will be integrated in Yunohost SSO (Single Sign On)"),
|
gettext("The app will be integrated in Yunohost SSO (Single Sign On)"),
|
||||||
description=gettext("Which means that one connexion to Yunohost unlock the connexion to the software, without having to sign on specificaly into it. One only has to connect once (Single Sign On)"),
|
description=gettext(
|
||||||
|
"Which means that one connexion to Yunohost unlock the connexion to the software, without having to sign on specificaly into it. One only has to connect once (Single Sign On)"
|
||||||
|
),
|
||||||
choices=[
|
choices=[
|
||||||
("false", gettext("Yes")),
|
("false", gettext("Yes")),
|
||||||
("true", gettext("No")),
|
("true", gettext("No")),
|
||||||
|
@ -214,7 +226,9 @@ class UpstreamInfos(FlaskForm):
|
||||||
|
|
||||||
license = StringField(
|
license = StringField(
|
||||||
gettext("Licence"),
|
gettext("Licence"),
|
||||||
description=gettext("You should check this on the upstream repository. The expected format is a SPDX id listed in https://spdx.org/licenses/"),
|
description=gettext(
|
||||||
|
"You should check this on the upstream repository. The expected format is a SPDX id listed in https://spdx.org/licenses/"
|
||||||
|
),
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -258,21 +272,31 @@ class UpstreamInfos(FlaskForm):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class InstallQuestions(FlaskForm):
|
class InstallQuestions(FlaskForm):
|
||||||
|
|
||||||
domain_and_path = SelectField(
|
domain_and_path = SelectField(
|
||||||
gettext("Ask the URL where the app will be installed ('domain' and 'path' variables)"),
|
gettext(
|
||||||
|
"Ask the URL where the app will be installed ('domain' and 'path' variables)"
|
||||||
|
),
|
||||||
default="true",
|
default="true",
|
||||||
choices=[
|
choices=[
|
||||||
("true", gettext("Ask domain+path")),
|
("true", gettext("Ask domain+path")),
|
||||||
("full_domain", gettext("Ask only the domain (the app requires to be installed at the root of a dedicated domain)")),
|
(
|
||||||
("false", gettext("Do not ask (it isn't a webapp)"))
|
"full_domain",
|
||||||
|
gettext(
|
||||||
|
"Ask only the domain (the app requires to be installed at the root of a dedicated domain)"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("false", gettext("Do not ask (it isn't a webapp)")),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
init_main_permission = BooleanField(
|
init_main_permission = BooleanField(
|
||||||
gettext("Ask who can access to the app"),
|
gettext("Ask who can access to the app"),
|
||||||
description=gettext("In the users groups : by default at least 'visitors', 'all_users' et 'admins' exists. (It was previously the private/public app concept)"),
|
description=gettext(
|
||||||
|
"In the users groups : by default at least 'visitors', 'all_users' et 'admins' exists. (It was previously the private/public app concept)"
|
||||||
|
),
|
||||||
default=True,
|
default=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -303,12 +327,10 @@ class InstallQuestions(FlaskForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# manifest
|
# manifest
|
||||||
class Resources(FlaskForm):
|
class Resources(FlaskForm):
|
||||||
|
|
||||||
|
# Sources
|
||||||
# Sources
|
|
||||||
source_url = StringField(
|
source_url = StringField(
|
||||||
gettext("Application source code or executable"),
|
gettext("Application source code or executable"),
|
||||||
validators=[DataRequired(), URL()],
|
validators=[DataRequired(), URL()],
|
||||||
|
@ -326,27 +348,31 @@ class Resources(FlaskForm):
|
||||||
|
|
||||||
auto_update = SelectField(
|
auto_update = SelectField(
|
||||||
gettext("Activate the automated source update bot"),
|
gettext("Activate the automated source update bot"),
|
||||||
description=gettext("If the software is available in one of the handled sources and publish releases or tags for its new updates, or for each new commit, a bot will provide an update with updated URL and checksum"),
|
description=gettext(
|
||||||
|
"If the software is available in one of the handled sources and publish releases or tags for its new updates, or for each new commit, a bot will provide an update with updated URL and checksum"
|
||||||
|
),
|
||||||
default="none",
|
default="none",
|
||||||
choices=[
|
choices=[
|
||||||
("none", "Non"),
|
("none", "Non"),
|
||||||
("latest_github_tag", "Github (tag)"),
|
("latest_github_tag", "Github (tag)"),
|
||||||
("latest_github_release", "Github (release)"),
|
("latest_github_release", "Github (release)"),
|
||||||
("latest_github_commit", "Github (commit)"),
|
("latest_github_commit", "Github (commit)"),
|
||||||
("latest_gitlab_tag", "Gitlab (tag)"),
|
("latest_gitlab_tag", "Gitlab (tag)"),
|
||||||
("latest_gitlab_release", "Gitlab (release)"),
|
("latest_gitlab_release", "Gitlab (release)"),
|
||||||
("latest_gitlab_commit", "Gitlab (commit)"),
|
("latest_gitlab_commit", "Gitlab (commit)"),
|
||||||
("latest_gitea_tag", "Gitea (tag)"),
|
("latest_gitea_tag", "Gitea (tag)"),
|
||||||
("latest_gitea_release", "Gitea (release)"),
|
("latest_gitea_release", "Gitea (release)"),
|
||||||
("latest_gitea_commit", "Gitea (commit)"),
|
("latest_gitea_commit", "Gitea (commit)"),
|
||||||
("latest_forgejo_tag", "Forgejo (tag)"),
|
("latest_forgejo_tag", "Forgejo (tag)"),
|
||||||
("latest_forgejo_release", "Forgejo (release)"),
|
("latest_forgejo_release", "Forgejo (release)"),
|
||||||
("latest_forgejo_commit", "Forgejo (commit)"),
|
("latest_forgejo_commit", "Forgejo (commit)"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
apt_dependencies = StringField(
|
apt_dependencies = StringField(
|
||||||
gettext("Dependances to be installed via apt (separated by a quote and/or spaces)"),
|
gettext(
|
||||||
|
"Dependances to be installed via apt (separated by a quote and/or spaces)"
|
||||||
|
),
|
||||||
render_kw={
|
render_kw={
|
||||||
"placeholder": "foo, bar2.1-ext, libwat",
|
"placeholder": "foo, bar2.1-ext, libwat",
|
||||||
},
|
},
|
||||||
|
@ -398,11 +424,11 @@ class SpecificTechnology(FlaskForm):
|
||||||
|
|
||||||
install_snippet = TextAreaField(
|
install_snippet = TextAreaField(
|
||||||
gettext("Installation specific commands"),
|
gettext("Installation specific commands"),
|
||||||
description=gettext("These commands are executed from the app installation folder (by default, /var/www/$app) after the sources have been deployed. This field uses by default a classic example based on the selected technology. You should probably compare and adapt it according to the app installation documentation"),
|
description=gettext(
|
||||||
|
"These commands are executed from the app installation folder (by default, /var/www/$app) after the sources have been deployed. This field uses by default a classic example based on the selected technology. You should probably compare and adapt it according to the app installation documentation"
|
||||||
|
),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
render_kw={
|
render_kw={"spellcheck": "false"},
|
||||||
"spellcheck": "false"
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -436,7 +462,9 @@ class SpecificTechnology(FlaskForm):
|
||||||
|
|
||||||
systemd_execstart = StringField(
|
systemd_execstart = StringField(
|
||||||
gettext("Command to start the app daemon (from systemd service)"),
|
gettext("Command to start the app daemon (from systemd service)"),
|
||||||
description=gettext("Corresponds to 'ExecStart' statement in systemd. You can use '__INSTALL_DIR__' to refer to the install directory, or '__APP__' to refer to the app id"),
|
description=gettext(
|
||||||
|
"Corresponds to 'ExecStart' statement in systemd. You can use '__INSTALL_DIR__' to refer to the install directory, or '__APP__' to refer to the app id"
|
||||||
|
),
|
||||||
render_kw={
|
render_kw={
|
||||||
"placeholder": "__INSTALL_DIR__/bin/app --some-option",
|
"placeholder": "__INSTALL_DIR__/bin/app --some-option",
|
||||||
},
|
},
|
||||||
|
@ -461,80 +489,90 @@ class AppConfig(FlaskForm):
|
||||||
|
|
||||||
custom_config_file_content = TextAreaField(
|
custom_config_file_content = TextAreaField(
|
||||||
gettext("App configuration file pattern"),
|
gettext("App configuration file pattern"),
|
||||||
description=gettext("In this pattern, you can use the syntax __FOO_BAR__ which will automatically replaced by the value of the variable $foo_bar"),
|
description=gettext(
|
||||||
|
"In this pattern, you can use the syntax __FOO_BAR__ which will automatically replaced by the value of the variable $foo_bar"
|
||||||
|
),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
render_kw={
|
render_kw={"spellcheck": "false"},
|
||||||
"spellcheck": "false"
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Documentation(FlaskForm):
|
class Documentation(FlaskForm):
|
||||||
# TODO : # screenshot
|
# TODO : # screenshot
|
||||||
description = TextAreaField(
|
description = TextAreaField(
|
||||||
Markup(gettext('''Type the content of DESCRIPTION.md file. <br> \
|
Markup(
|
||||||
Do not give the software name at the beginning, as it will be integrated an 'Overview' subpart''')),
|
gettext(
|
||||||
validators=[Optional()],
|
"""Type the content of DESCRIPTION.md file. <br> \
|
||||||
render_kw={
|
Do not give the software name at the beginning, as it will be integrated an 'Overview' subpart"""
|
||||||
"class": "form-control",
|
)
|
||||||
"spellcheck": "false",
|
),
|
||||||
},
|
validators=[Optional()],
|
||||||
|
render_kw={
|
||||||
|
"class": "form-control",
|
||||||
|
"spellcheck": "false",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
disclaimer = TextAreaField(
|
disclaimer = TextAreaField(
|
||||||
gettext("Type the DISCLAIMER.md file content, which list warnings and attention points."),
|
gettext(
|
||||||
validators=[Optional()],
|
"Type the DISCLAIMER.md file content, which list warnings and attention points."
|
||||||
render_kw={
|
),
|
||||||
"class": "form-control",
|
validators=[Optional()],
|
||||||
"spellcheck": "false",
|
render_kw={
|
||||||
},
|
"class": "form-control",
|
||||||
|
"spellcheck": "false",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
pre_install = TextAreaField(
|
pre_install = TextAreaField(
|
||||||
gettext("Type the PRE_INSTALL.md file content"),
|
gettext("Type the PRE_INSTALL.md file content"),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
render_kw={
|
render_kw={
|
||||||
"class": "form-control",
|
"class": "form-control",
|
||||||
"spellcheck": "false",
|
"spellcheck": "false",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
post_install = TextAreaField(
|
post_install = TextAreaField(
|
||||||
gettext("Type the POST_INSTALL.md file content"),
|
gettext("Type the POST_INSTALL.md file content"),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
render_kw={
|
render_kw={
|
||||||
"class": "form-control",
|
"class": "form-control",
|
||||||
"spellcheck": "false",
|
"spellcheck": "false",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
pre_upgrade = TextAreaField(
|
pre_upgrade = TextAreaField(
|
||||||
gettext("Type the PRE_UPGRADE.md file content"),
|
gettext("Type the PRE_UPGRADE.md file content"),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
render_kw={
|
render_kw={
|
||||||
"class": "form-control",
|
"class": "form-control",
|
||||||
"spellcheck": "false",
|
"spellcheck": "false",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
post_upgrade = TextAreaField(
|
post_upgrade = TextAreaField(
|
||||||
gettext("Type the POST_UPGRADE.md file content"),
|
gettext("Type the POST_UPGRADE.md file content"),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
render_kw={
|
render_kw={
|
||||||
"class": "form-control",
|
"class": "form-control",
|
||||||
"spellcheck": "false",
|
"spellcheck": "false",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
admin = TextAreaField(
|
admin = TextAreaField(
|
||||||
gettext("Type the ADMIN.md file content"),
|
gettext("Type the ADMIN.md file content"),
|
||||||
validators=[Optional()],
|
validators=[Optional()],
|
||||||
render_kw={
|
render_kw={
|
||||||
"class": "form-control",
|
"class": "form-control",
|
||||||
"spellcheck": "false",
|
"spellcheck": "false",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MoreAdvanced(FlaskForm):
|
class MoreAdvanced(FlaskForm):
|
||||||
|
|
||||||
enable_change_url = BooleanField(
|
enable_change_url = BooleanField(
|
||||||
gettext("Handle app install URL change (change_url script)"),
|
gettext("Handle app install URL change (change_url script)"),
|
||||||
default=True,
|
default=True,
|
||||||
render_kw={
|
render_kw={
|
||||||
"title": gettext("Should changing the app URL be allowed ? (change_url change)")
|
"title": gettext(
|
||||||
|
"Should changing the app URL be allowed ? (change_url change)"
|
||||||
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -542,7 +580,9 @@ class MoreAdvanced(FlaskForm):
|
||||||
gettext("Use logrotate for the app logs"),
|
gettext("Use logrotate for the app logs"),
|
||||||
default=True,
|
default=True,
|
||||||
render_kw={
|
render_kw={
|
||||||
"title": gettext("If the app generates logs, this option permit to handle their archival. Recommended.")
|
"title": gettext(
|
||||||
|
"If the app generates logs, this option permit to handle their archival. Recommended."
|
||||||
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# TODO : specify custom log file
|
# TODO : specify custom log file
|
||||||
|
@ -551,7 +591,9 @@ class MoreAdvanced(FlaskForm):
|
||||||
gettext("Protect the application against brute force attacks (via fail2ban)"),
|
gettext("Protect the application against brute force attacks (via fail2ban)"),
|
||||||
default=False,
|
default=False,
|
||||||
render_kw={
|
render_kw={
|
||||||
"title": gettext("If the app generates failed connexions logs, this option allows to automatically banish the related IP after a certain number of failed password tries. Recommended.")
|
"title": gettext(
|
||||||
|
"If the app generates failed connexions logs, this option allows to automatically banish the related IP after a certain number of failed password tries. Recommended."
|
||||||
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
use_cron = BooleanField(
|
use_cron = BooleanField(
|
||||||
|
@ -575,14 +617,24 @@ class MoreAdvanced(FlaskForm):
|
||||||
render_kw={
|
render_kw={
|
||||||
"placeholder": gettext("A regular expression"),
|
"placeholder": gettext("A regular expression"),
|
||||||
"class": "form-control",
|
"class": "form-control",
|
||||||
"title": gettext("Regular expression to check in the log file to activate failban (search for a line that indicates a credentials error)."),
|
"title": gettext(
|
||||||
|
"Regular expression to check in the log file to activate failban (search for a line that indicates a credentials error)."
|
||||||
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
## Main form
|
## Main form
|
||||||
class GeneratorForm(
|
class GeneratorForm(
|
||||||
GeneralInfos, IntegrationInfos, UpstreamInfos, InstallQuestions, Resources, SpecificTechnology, AppConfig, Documentation, MoreAdvanced
|
GeneralInfos,
|
||||||
|
IntegrationInfos,
|
||||||
|
UpstreamInfos,
|
||||||
|
InstallQuestions,
|
||||||
|
Resources,
|
||||||
|
SpecificTechnology,
|
||||||
|
AppConfig,
|
||||||
|
Documentation,
|
||||||
|
MoreAdvanced,
|
||||||
):
|
):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -590,17 +642,28 @@ class GeneratorForm(
|
||||||
|
|
||||||
generator_mode = SelectField(
|
generator_mode = SelectField(
|
||||||
gettext("Generator mode"),
|
gettext("Generator mode"),
|
||||||
description=gettext("In tutorial version, the generated app will contain additionnal comments to ease the understanding. In steamlined version, the generated app will only contain the necessary minimum."),
|
description=gettext(
|
||||||
choices=[("simple", gettext("Streamlined version")), ("tutorial", gettext("Tutorial version"))],
|
"In tutorial version, the generated app will contain additionnal comments to ease the understanding. In steamlined version, the generated app will only contain the necessary minimum."
|
||||||
|
),
|
||||||
|
choices=[
|
||||||
|
("simple", gettext("Streamlined version")),
|
||||||
|
("tutorial", gettext("Tutorial version")),
|
||||||
|
],
|
||||||
default="true",
|
default="true",
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()],
|
||||||
)
|
)
|
||||||
|
|
||||||
submit_preview = SubmitField(gettext("Previsualise"))
|
submit_preview = SubmitField(gettext("Previsualise"))
|
||||||
submit_download = SubmitField(gettext("Download the .zip"))
|
submit_download = SubmitField(gettext("Download the .zip"))
|
||||||
submit_demo = SubmitField(gettext('Fill with demo values'), render_kw={"onclick": "fillFormWithDefaultValues()",
|
submit_demo = SubmitField(
|
||||||
"title": gettext("Generate a complete and functionnal minimalistic app that you can iterate from")
|
gettext("Fill with demo values"),
|
||||||
})
|
render_kw={
|
||||||
|
"onclick": "fillFormWithDefaultValues()",
|
||||||
|
"title": gettext(
|
||||||
|
"Generate a complete and functionnal minimalistic app that you can iterate from"
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#### Web pages
|
#### Web pages
|
||||||
|
@ -617,13 +680,16 @@ def main_form_route():
|
||||||
print(main_form.errors)
|
print(main_form.errors)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"index.html", main_form=main_form, generator_info=GENERATOR_DICT, generated_files={}
|
"index.html",
|
||||||
|
main_form=main_form,
|
||||||
|
generator_info=GENERATOR_DICT,
|
||||||
|
generated_files={},
|
||||||
)
|
)
|
||||||
|
|
||||||
if main_form.submit_preview.data:
|
if main_form.submit_preview.data:
|
||||||
submit_mode = "preview"
|
submit_mode = "preview"
|
||||||
elif main_form.submit_demo.data:
|
elif main_form.submit_demo.data:
|
||||||
submit_mode = "demo" # TODO : for now this always trigger a preview. Not sure if that's an issue
|
submit_mode = "demo" # TODO : for now this always trigger a preview. Not sure if that's an issue
|
||||||
else:
|
else:
|
||||||
submit_mode = "download"
|
submit_mode = "download"
|
||||||
|
|
||||||
|
@ -634,15 +700,15 @@ def main_form_route():
|
||||||
self.content = None
|
self.content = None
|
||||||
|
|
||||||
app_files = [
|
app_files = [
|
||||||
AppFile("manifest", "manifest.toml"),
|
AppFile("manifest", "manifest.toml"),
|
||||||
AppFile("tests", "tests.toml"), # TODO test this
|
AppFile("tests", "tests.toml"), # TODO test this
|
||||||
AppFile("_common.sh", "scripts/_common.sh"),
|
AppFile("_common.sh", "scripts/_common.sh"),
|
||||||
AppFile("install", "scripts/install"),
|
AppFile("install", "scripts/install"),
|
||||||
AppFile("remove", "scripts/remove"),
|
AppFile("remove", "scripts/remove"),
|
||||||
AppFile("backup", "scripts/backup"),
|
AppFile("backup", "scripts/backup"),
|
||||||
AppFile("restore", "scripts/restore"),
|
AppFile("restore", "scripts/restore"),
|
||||||
AppFile("upgrade", "scripts/upgrade"),
|
AppFile("upgrade", "scripts/upgrade"),
|
||||||
AppFile("nginx", "conf/nginx.conf"),
|
AppFile("nginx", "conf/nginx.conf"),
|
||||||
]
|
]
|
||||||
|
|
||||||
if main_form.enable_change_url.data:
|
if main_form.enable_change_url.data:
|
||||||
|
@ -653,7 +719,7 @@ def main_form_route():
|
||||||
|
|
||||||
# TODO : buggy, tries to open php.j2
|
# TODO : buggy, tries to open php.j2
|
||||||
# if main_form.main_technology.data == "php":
|
# if main_form.main_technology.data == "php":
|
||||||
# app_files.append(AppFile("php", "conf/extra_php-fpm.conf"))
|
# app_files.append(AppFile("php", "conf/extra_php-fpm.conf"))
|
||||||
|
|
||||||
if main_form.description.data:
|
if main_form.description.data:
|
||||||
app_files.append(AppFile("DESCRIPTION", "docs/DESCRIPTION.md"))
|
app_files.append(AppFile("DESCRIPTION", "docs/DESCRIPTION.md"))
|
||||||
|
@ -679,13 +745,17 @@ def main_form_route():
|
||||||
template_dir = os.path.dirname(__file__) + "/templates/"
|
template_dir = os.path.dirname(__file__) + "/templates/"
|
||||||
for app_file in app_files:
|
for app_file in app_files:
|
||||||
template = open(template_dir + app_file.id + ".j2").read()
|
template = open(template_dir + app_file.id + ".j2").read()
|
||||||
app_file.content = render_template_string(template, data=dict(request.form | GENERATOR_DICT))
|
app_file.content = render_template_string(
|
||||||
app_file.content = re.sub(r'\n\s+$', '\n', app_file.content, flags=re.M)
|
template, data=dict(request.form | GENERATOR_DICT)
|
||||||
app_file.content = re.sub(r'\n{3,}', '\n\n', app_file.content, flags=re.M)
|
)
|
||||||
|
app_file.content = re.sub(r"\n\s+$", "\n", app_file.content, flags=re.M)
|
||||||
|
app_file.content = re.sub(r"\n{3,}", "\n\n", app_file.content, flags=re.M)
|
||||||
|
|
||||||
print(main_form.use_custom_config_file.data)
|
print(main_form.use_custom_config_file.data)
|
||||||
if main_form.use_custom_config_file.data:
|
if main_form.use_custom_config_file.data:
|
||||||
app_files.append(AppFile("appconf", "conf/" + main_form.custom_config_file.data))
|
app_files.append(
|
||||||
|
AppFile("appconf", "conf/" + main_form.custom_config_file.data)
|
||||||
|
)
|
||||||
app_files[-1].content = main_form.custom_config_file_content.data
|
app_files[-1].content = main_form.custom_config_file_content.data
|
||||||
print(main_form.custom_config_file.data)
|
print(main_form.custom_config_file.data)
|
||||||
print(main_form.custom_config_file_content.data)
|
print(main_form.custom_config_file_content.data)
|
||||||
|
@ -701,19 +771,26 @@ def main_form_route():
|
||||||
zf.writestr(app_file.destination_path, app_file.content)
|
zf.writestr(app_file.destination_path, app_file.content)
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
# Send the zip file to the user
|
# Send the zip file to the user
|
||||||
return send_file(f, as_attachment=True, download_name=request.form["app_id"] + ".zip")
|
return send_file(
|
||||||
|
f, as_attachment=True, download_name=request.form["app_id"] + ".zip"
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"index.html", main_form=main_form, generator_info=GENERATOR_DICT, generated_files=app_files,
|
"index.html",
|
||||||
|
main_form=main_form,
|
||||||
|
generator_info=GENERATOR_DICT,
|
||||||
|
generated_files=app_files,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Localisation
|
# Localisation
|
||||||
@app.route('/language/<language>')
|
@app.route("/language/<language>")
|
||||||
def set_language(language=None):
|
def set_language(language=None):
|
||||||
response = make_response(redirect(request.referrer or '/'))
|
response = make_response(redirect(request.referrer or "/"))
|
||||||
response.set_cookie('lang', language)
|
response.set_cookie("lang", language)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
#### Running the web server
|
#### Running the web server
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue