Refactor as requested

main
Florent Daigniere 2 years ago
parent 385b6ac85d
commit 19af2944d7

@ -46,7 +46,7 @@ class MultipleFoldersVerify(object):
self.message = message self.message = message
def __call__(self, form, field): def __call__(self, form, field):
pattern = re.compile(r'^\w+(,\w+)*$') pattern = re.compile(r'^\w+(\s*,\s*\w+)*$')
if not pattern.match(field.data.replace(" ", "")): if not pattern.match(field.data.replace(" ", "")):
raise validators.ValidationError(self.message) raise validators.ValidationError(self.message)

@ -25,9 +25,7 @@
{%- call macros.card(title="Settings") %} {%- call macros.card(title="Settings") %}
{{ macros.form_field(form.keep) }} {{ macros.form_field(form.keep) }}
{{ macros.form_field(form.scan) }} {{ macros.form_field(form.scan) }}
{%- block folders %}
{{ macros.form_field(form.folders) }} {{ macros.form_field(form.folders) }}
{%- endblock %}
{%- endcall %} {%- endcall %}
{{ macros.form_field(form.submit) }} {{ macros.form_field(form.submit) }}

@ -7,15 +7,3 @@
{%- block subtitle %} {%- block subtitle %}
{{ user }} {{ user }}
{%- endblock %} {%- endblock %}
{%- block folders %}
<div class="form-group">
<div class="row">
<div class="col-lg-12 col-xs-12 ">
<label for="folders">Folders to fetch on the server</label>
<input class="form-control" id="folders" name="folders" type="text" value="{{ form.folders.data|join(',') }}">
</div>
</div>
</div>
{%- endblock %}

@ -1,4 +1,4 @@
from mailu import models from mailu import models, utils
from mailu.ui import ui, forms, access from mailu.ui import ui, forms, access
import flask import flask
@ -23,6 +23,7 @@ def fetch_create(user_email):
user = models.User.query.get(user_email) or flask.abort(404) user = models.User.query.get(user_email) or flask.abort(404)
form = forms.FetchForm() form = forms.FetchForm()
form.password.validators = [wtforms.validators.DataRequired()] form.password.validators = [wtforms.validators.DataRequired()]
utils.formatCSVField(form.folders)
if form.validate_on_submit(): if form.validate_on_submit():
fetch = models.Fetch(user=user) fetch = models.Fetch(user=user)
form.populate_obj(fetch) form.populate_obj(fetch)
@ -41,6 +42,7 @@ def fetch_create(user_email):
def fetch_edit(fetch_id): def fetch_edit(fetch_id):
fetch = models.Fetch.query.get(fetch_id) or flask.abort(404) fetch = models.Fetch.query.get(fetch_id) or flask.abort(404)
form = forms.FetchForm(obj=fetch) form = forms.FetchForm(obj=fetch)
utils.formatCSVField(form.folders)
if form.validate_on_submit(): if form.validate_on_submit():
if not form.password.data: if not form.password.data:
form.password.data = fetch.password form.password.data = fetch.password

@ -99,11 +99,7 @@ def user_settings(user_email):
user_email_or_current = user_email or flask_login.current_user.email user_email_or_current = user_email or flask_login.current_user.email
user = models.User.query.get(user_email_or_current) or flask.abort(404) user = models.User.query.get(user_email_or_current) or flask.abort(404)
form = forms.UserSettingsForm(obj=user) form = forms.UserSettingsForm(obj=user)
if isinstance(form.forward_destination.data,str): utils.formatCSVField(form.forward_destination)
data = form.forward_destination.data.replace(" ","").split(",")
else:
data = form.forward_destination.data
form.forward_destination.data = ", ".join(data)
if form.validate_on_submit(): if form.validate_on_submit():
form.forward_destination.data = form.forward_destination.data.replace(" ","").split(",") form.forward_destination.data = form.forward_destination.data.replace(" ","").split(",")
form.populate_obj(user) form.populate_obj(user)

@ -518,3 +518,10 @@ def isBadOrPwned(form):
if breaches > 0: if breaches > 0:
return f"This password appears in {breaches} data breaches! It is not unique; please change it." return f"This password appears in {breaches} data breaches! It is not unique; please change it."
return None return None
def formatCSVField(field):
if isinstance(field.data,str):
data = field.data.replace(" ","").split(",")
else:
data = field.data
field.data = ", ".join(data)

Loading…
Cancel
Save