File tree Expand file tree Collapse file tree 2 files changed +25
-18
lines changed Expand file tree Collapse file tree 2 files changed +25
-18
lines changed Original file line number Diff line number Diff line change 4141 "URLField" ,
4242 "UUIDField" ,
4343]
44- import functools
45- import logging
4644from typing import Callable , List , Optional , Union
4745
4846from mongoengine import fields
5452 wtf_fields = None
5553 wtf_validators = None
5654
57- logger = logging .getLogger ("flask_mongoengine" )
58-
59-
60- def wtf_required (func ):
61- """Special decorator to warn user on incorrect installation."""
62-
63- @functools .wraps (func )
64- def wrapped (* args , ** kwargs ):
65- if wtf_validators is None or wtf_fields is None :
66- logger .error (f"WTForms not installed. Function '{ func .__name__ } ' aborted." )
67- return None
68-
69- return func (* args , ** kwargs )
70-
71- return wrapped
72-
7355
7456class WtfFieldMixin :
7557 """
Original file line number Diff line number Diff line change 1+ import functools
2+ import logging
3+
4+ try :
5+ import wtforms # noqa
6+
7+ wtf_installed = True
8+ except ImportError : # pragma: no cover
9+ wtf_installed = False
10+
11+ logger = logging .getLogger ("flask_mongoengine" )
12+
13+
14+ def wtf_required (func ):
15+ """Special decorator to warn user on incorrect installation."""
16+
17+ @functools .wraps (func )
18+ def wrapped (* args , ** kwargs ):
19+ if not wtf_installed :
20+ logger .error (f"WTForms not installed. Function '{ func .__name__ } ' aborted." )
21+ return None
22+
23+ return func (* args , ** kwargs )
24+
25+ return wrapped
You can’t perform that action at this time.
0 commit comments