File tree 3 files changed +28
-4
lines changed
builder/templates/formidable
3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
2
3
+ from django .contrib import messages
3
4
4
5
logger = logging .getLogger (__name__ )
5
6
@@ -31,9 +32,11 @@ def callback_success_message(request):
31
32
This function will be called a form post-save/create.
32
33
33
34
It adds a logging message
35
+
34
36
"""
35
- logger .info ('Sucessfully recorded form :)' )
36
- return True
37
+ msg = 'Sucessfully recorded form :)'
38
+ logger .info (msg )
39
+ messages .info (request ._request , msg )
37
40
38
41
39
42
def callback_fail_message (request ):
@@ -42,5 +45,6 @@ def callback_fail_message(request):
42
45
43
46
It adds a logging message (error)
44
47
"""
45
- logger .error ('Form storing has failed :(' )
46
- return True
48
+ msg = 'Form storing has failed :('
49
+ logger .error (msg )
50
+ messages .error (request ._request , msg )
Original file line number Diff line number Diff line change 4
4
< div class ="title ">
5
5
< h1 > May the Form be with you!</ h1 >
6
6
</ div >
7
+
8
+ {% if messages %}
9
+ < ul class ="messages ">
10
+ {% for message in messages %}
11
+ < li {% if message.tags %} class ="{{ message.tags }} "{% endif %} > {{ message }}</ li >
12
+ {% endfor %}
13
+ </ ul >
14
+ {% endif %}
15
+
7
16
< div >
8
17
< table >
9
18
< thead >
Original file line number Diff line number Diff line change @@ -73,6 +73,12 @@ class CallbackMixin(object):
73
73
def _call_callback (self , callback ):
74
74
"""
75
75
Tool to simply call the callback function and handle edge-cases.
76
+
77
+ **WARNING!** the DRF request is not inherited from django core,
78
+ `HTTPRequest`, and you should not assume they'll behave the same way.
79
+
80
+ If you need the "true" HTTPRequest object,
81
+ use ``self.request._request`` in your callback functions.
76
82
"""
77
83
# If there's no callback value, it's pointless to try to extract it
78
84
if not callback :
@@ -83,6 +89,11 @@ def _call_callback(self, callback):
83
89
if not func :
84
90
return
85
91
try :
92
+ # WARNING! the DRF request is not inherited from django core,
93
+ # `HTTPRequest`, and you should not assume they'll behave the same
94
+ # way.
95
+ # If you need the "true" HTTPRequest object, use
96
+ # ``self.request._request``
86
97
func (self .request )
87
98
except Exception :
88
99
logger .error (
You can’t perform that action at this time.
0 commit comments