mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
continue work on multiples
This commit is contained in:
parent
032837e184
commit
9ae9c6b3e2
3 changed files with 15 additions and 6 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
__pycache__
|
||||
13
forms.py
13
forms.py
|
|
@ -110,12 +110,17 @@ def settings_to_form(settings):
|
|||
|
||||
def compute_form(client_form, request_form, settings):
|
||||
for key, value in request_form.items():
|
||||
print(key)
|
||||
real_key = key
|
||||
res = search(r"_([0-9]+)$", setting)
|
||||
res = search(r"([a-z\-]+\-[0-9]+\-).*_([0-9]+)$", key)
|
||||
if res:
|
||||
real_key = "_".join(key.split("_")[:-1])
|
||||
if real_key in settings:
|
||||
real_key = "_".join(key.replace(res.group(1), "").split("_")[:-1])
|
||||
if real_key in settings and "multiple" in settings[real_key]:
|
||||
setattr(
|
||||
client_form,
|
||||
key,
|
||||
)
|
||||
StringField(
|
||||
validators=[Regexp(settings[real_key]["regex"])]
|
||||
)
|
||||
)
|
||||
return client_form
|
||||
7
main.py
7
main.py
|
|
@ -1,7 +1,7 @@
|
|||
from flask import Flask, render_template, request
|
||||
from json import loads
|
||||
|
||||
from forms import settings_to_form
|
||||
from forms import settings_to_form, compute_form
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
@ -12,7 +12,10 @@ def global_settings():
|
|||
with open("limit.json") as f:
|
||||
settings = loads(f.read())["settings"]
|
||||
form = settings_to_form(settings)(request.form)
|
||||
if request.method == "POST" and form.validate():
|
||||
if request.method == "POST":
|
||||
form = compute_form(form, request.form, settings)
|
||||
if not form.validate():
|
||||
print("error validate")
|
||||
for field in form:
|
||||
print(f"field {field.id} = {field.data}")
|
||||
print(form.errors)
|
||||
|
|
|
|||
Loading…
Reference in a new issue