M awesomebox/base.py +13 -3
@@ 35,18 35,28 @@ class BaseAwesomebox(object):
)
return result
+ def notify_user(self, request, result):
+ ''' Default method to notify the user of success. Override
+ to customize
+ '''
+ if 'django.contrib.messages' in settings.INSTALLED_APPS:
+ from django.contrib import messages
+ level = messages.SUCCESS if result.success else messages.ERROR
+ messages.add_message(request, level, result.message)
+
def cmd_echo(self, data):
''' Example function. Returns back the data passed in.
'''
return Result(True, data)
+class NullAwesomeBox(BaseAwesomebox):
+ pass
+
+
def get_awesomebox_class():
''' Return the class to use for Awesomebox dispatching.
'''
- class NullAwesomeBox(BaseAwesomebox):
- pass
-
cls_path = getattr(settings, 'AWESOMEBOX_CLASS', None)
cls = NullAwesomeBox if cls_path is None else import_module(cls_path)
if not issubclass(cls, BaseAwesomebox):
M awesomebox/views.py +2 -1
@@ 33,7 33,8 @@ class AwesomeboxView(View):
json.dumps(result),
mimetype='application/json',
)
- # TODO Add message here for user session
+
+ abox.notify_user(request, result)
return redirect(self.success_url)
return render(request, self.template_name, {'form': form})