File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change
1
+ # noinspection PyPackageRequirements
2
+ from sanic .exceptions import NotFound
3
+
1
4
from .. import api
2
5
from ..local import enable_task_local , disable_task_local
3
6
4
7
8
+ class SanicModelMixin :
9
+ @classmethod
10
+ async def get_or_404 (cls , * args , ** kwargs ):
11
+ # noinspection PyUnresolvedReferences
12
+ rv = await cls .get (* args , ** kwargs )
13
+ if rv is None :
14
+ raise NotFound ('{} is not found' .format (cls .__name__ ))
15
+ return rv
16
+
17
+
5
18
# noinspection PyClassHasNoInit
6
19
class Gino (api .Gino ):
7
20
"""Support Sanic web server.
@@ -21,6 +34,8 @@ class Gino(api.Gino):
21
34
Here `request['connection']` is a :class:`LazyConnection` object, see its
22
35
doc string for more information.
23
36
"""
37
+ default_model_classes = api .Gino .default_model_classes + (SanicModelMixin ,)
38
+
24
39
def init_app (self , app ):
25
40
task_local_enabled = [False ]
26
41
You can’t perform that action at this time.
0 commit comments