Skip to content

Commit

Permalink
Cleanup API and release.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Aug 1, 2020
1 parent 795e4f9 commit 77aab6a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 53 deletions.
6 changes: 3 additions & 3 deletions abilian/web/forms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ class AntiVirus(Rule):
field_flags = ("antivirus",)

def __call__(self, form, field):
svc = get_service("antivirus")
if not svc:
service = get_service("antivirus")
if not service:
return

res = svc.scan(field.data)
res = service.scan(field.data)
if res is False:
raise validators.ValidationError(_("Virus detected!"))

Expand Down
27 changes: 12 additions & 15 deletions abilian/web/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,19 +655,17 @@ def __init__(
input_type: Optional[Any] = None,
pre_icon: Optional[Any] = None,
post_icon: Optional[Any] = None,
*args: Any,
**kwargs: Any,
) -> None:
super().__init__(input_type, *args, **kwargs)
super().__init__(input_type)

if pre_icon is not None:
self.pre_icon = pre_icon
if post_icon is not None:
self.post_icon = post_icon

def __call__(self, field, *args, **kwargs):
def __call__(self, field, **kwargs):
if not any((self.pre_icon, self.post_icon)):
return super().__call__(field, *args, **kwargs)
return super().__call__(field, **kwargs)

kwargs.setdefault("type", self.input_type)
if "value" not in kwargs:
Expand Down Expand Up @@ -938,15 +936,15 @@ def __call__(self, field, **kwargs):
for val, label, selected in field.iter_choices():
html.append(self.render_option(val, label, selected))
html.append("</select>")
return HTMLString("".join(html))
return Markup("".join(html))

@classmethod
def render_option(cls, value, label, selected, **kwargs):
options = dict(kwargs, value=value)
if selected:
options["selected"] = True
params = html_params(**options)
return HTMLString(f"<option {params}>{html.escape(str(label))}</option>")
return Markup(f"<option {params}>{html.escape(str(label))}</option>")


class TagInput(Input):
Expand All @@ -959,7 +957,7 @@ def __call__(self, field, **kwargs):
kwargs["value"] = field._value()

params = self.html_params(name=field.name, **kwargs)
return HTMLString(f"<input {params}>")
return Markup(f"<input {params}>")


class DateInput(Input):
Expand Down Expand Up @@ -1103,9 +1101,8 @@ def __call__(self, field, **kwargs):
locale = get_locale()
date_fmt = locale.date_formats["short"].pattern
date_fmt = babel2datetime(date_fmt)
date_fmt = date_fmt.replace("%B", "%m").replace(
"%b", "%m"
) # force numerical months
# force numerical months
date_fmt = date_fmt.replace("%B", "%m").replace("%b", "%m")
time_fmt = "%H:%M"

value = kwargs.pop("value", None)
Expand Down Expand Up @@ -1398,7 +1395,7 @@ def __call__(self, field, **kwargs):
html.append(f"<li>{subfield()}</li>")

html.append(f"</{self.html_tag}>")
return wtforms.widgets.HTMLString("".join(html))
return Markup("".join(html))

def render_view(self, field, **kwargs):
data = field.data
Expand Down Expand Up @@ -1527,7 +1524,7 @@ def __init__(
if unescape_html:
self.unescape_html = True

def __call__(self, field, *args, **kwargs):
def __call__(self, field, **kwargs):
# 'placeholder' option presence is required for 'allowClear'
params = {"placeholder": ""}
if self.unescape_html:
Expand All @@ -1542,7 +1539,7 @@ def __call__(self, field, *args, **kwargs):

kwargs.setdefault("data-init-with", self.js_init)
kwargs["data-init-params"] = json.dumps(params)
return Select.__call__(self, field, *args, **kwargs)
return Select.__call__(self, field, **kwargs)

def render_view(self, field, **kwargs):
labels = [str(label) for v, label, checked in field.iter_choices() if checked]
Expand All @@ -1551,7 +1548,7 @@ def render_view(self, field, **kwargs):
@classmethod
def render_option(cls, value, label, selected, **kwargs):
if value is None:
return HTMLString("<option></option>")
return Markup("<option></option>")
return Select.render_option(value, label, selected, **kwargs)


Expand Down
9 changes: 4 additions & 5 deletions etc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-e /Users/fermigier/envs/abilian-core/lib/python3.7/site-packages
alabaster==0.7.12
alembic==1.4.2
amqp==2.6.0
amqp==2.6.1
apipkg==1.5
appdirs==1.4.4
argcomplete==1.12.0
Expand All @@ -13,7 +13,7 @@ billiard==3.6.3.0
black==19.10b0
bleach==3.1.5
blinker==1.4
celery==4.4.6
celery==4.4.7
certifi==2020.6.20
cffi==1.14.1
cfgv==3.0.0
Expand Down Expand Up @@ -52,7 +52,6 @@ Flask-Migrate==2.5.3
Flask-SQLAlchemy==2.1
flask-talisman==0.7.0
Flask-WTF==0.12
future==0.18.2
gitchangelog==3.0.4
honcho==1.0.1
html5lib==1.1
Expand All @@ -63,7 +62,7 @@ imagesize==1.2.0
importlib-metadata==1.7.0
incremental==17.5.0
infinity==1.5
iniconfig==1.0.0
iniconfig==1.0.1
intervals==0.9.0
isort==5.2.2
itsdangerous==1.1.0
Expand Down Expand Up @@ -142,7 +141,7 @@ urllib3==1.25.10
validate-email==1.3
validators==0.16.0
vine==1.3.0
virtualenv==20.0.28
virtualenv==20.0.29
webassets==0.12.1
webencodings==0.5.1
Werkzeug==0.16.1
Expand Down
35 changes: 12 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "abilian-core"
version = "0.11.8"
version = "0.11.9"
description = "A framework for enterprise applications (CRM, ERP, collaboration...), based on Flask and SQLAlchemy"
authors = ["Abilian SAS"]
license = "LGPL"
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,9 @@ domutils@^2.0.0:
domhandler "^3.0.0"

electron-to-chromium@^1.3.488:
version "1.3.515"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.515.tgz#96683d2c2be9bf83f6cca75d504a7b443d763c08"
integrity sha512-C9h2yLQwNSK/GTtWQsA9O6mLKv0ubmiAQgmz1HvHnAIH8g5Sje1shWxcooumbGiwgqvZ9yrTYULe4seMTgMYqQ==
version "1.3.516"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.516.tgz#03ec071b061e462b786bf7e7ce226fd7ab7cf1f6"
integrity sha512-WDM5AAQdOrvLqSX8g3Zd5AujBXfMxf96oeZkff0U2HF5op3tjShE+on2yay3r1UD4M9I3p0iHpAS4+yV8U8A9A==

emoji-regex@^7.0.1:
version "7.0.3"
Expand Down Expand Up @@ -828,9 +828,9 @@ eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0:
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==

eslint@^7.0.0:
version "7.5.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.5.0.tgz#9ecbfad62216d223b82ac9ffea7ef3444671d135"
integrity sha512-vlUP10xse9sWt9SGRtcr1LAC67BENcQMFeV+w5EvLEoFe3xJ8cF1Skd0msziRx/VMC+72B4DxreCE+OR12OA6Q==
version "7.6.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.6.0.tgz#522d67cfaea09724d96949c70e7a0550614d64d6"
integrity sha512-QlAManNtqr7sozWm5TF4wIH9gmUm2hE3vNRUvyoYAa4y1l5/jxD/PQStEjBMQtCqZmSep8UxrcecI60hOpe61w==
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.10.0"
Expand Down

0 comments on commit 77aab6a

Please sign in to comment.