|
1 """All decorators, that are created by this package. |
|
2 |
|
3 Imports: |
|
4 |
|
5 - :func:`.user.vUser` -- a validator for apikeys. |
|
6 - :func:`.pool.runInDBPool` -- runs a actual function in dbpool. |
|
7 """ |
1 import types |
8 import types |
2 from decorator import decorator |
|
3 |
9 |
4 from .user import vUser |
10 from .user import vUser |
5 from .schema import Offer |
11 from .schema import Offer |
6 from .dbdefer import dbdefer |
12 from .dbdefer import dbdefer |
7 from .pool import runInDBPool |
13 from .pool import runInDBPool |
8 |
14 |
9 from ..error import ValidateException |
15 from ..error import ValidateException |
10 |
16 |
11 @dbdefer |
17 @dbdefer |
12 def vRoute(session, value, field, typ, allowString=True, allowList=True): |
18 def vRoute(session, value, field, typ, allowString=True, allowList=True): |
|
19 """ a validator to test a valid route. use with :func:`iro.validate.validate`. |
|
20 |
|
21 :param session: a valid session object (is created by decorator :func:`iro.model.dbdefer.dbdefer`) |
|
22 :param value: the value to test |
|
23 :param string field: the field that is tested (only used to get a propper error message). |
|
24 :param string typ: a typ to test the route in |
|
25 :param boolean allowString: a single route is allowd. |
|
26 :param boolean allowList: a list of routes is allowed. |
|
27 :return: *value*, if value is a valid route for a given typ. |
|
28 :raises: :exc:`iro.error.ValidateException` |
|
29 """ |
13 str_ = False |
30 str_ = False |
14 ret = [] |
31 ret = [] |
15 |
32 |
16 if type(value) is types.StringType: |
33 if type(value) is types.StringType: |
17 if not allowString: |
34 if not allowString: |
32 return ret[0] |
49 return ret[0] |
33 return ret |
50 return ret |
34 |
51 |
35 @dbdefer |
52 @dbdefer |
36 def vTyp(value,field, session): |
53 def vTyp(value,field, session): |
|
54 """ a validator to test a valid typ. use with :func:`iro.validate.validate`. |
|
55 |
|
56 :param session: a valid session object (is created by decorator :func:`iro.model.dbdefer.dbdefer`) |
|
57 :param value: the value to test |
|
58 :param string field: the field that is tested (only used to get a propper error message). |
|
59 :return: *value*, if value is a valid typ. |
|
60 :raises: :exc:`iro.error.ValidateException` |
|
61 """ |
|
62 |
37 for typ in Offer.typs(session): |
63 for typ in Offer.typs(session): |
38 if value == typ[0]: |
64 if value == typ[0]: |
39 break |
65 break |
40 else: |
66 else: |
41 raise ValidateException(field=field,msg='Typ %s is not valid.'%value) |
67 raise ValidateException(field=field,msg='Typ %s is not valid.'%value) |