1. Peter Sanchez
  2. django-awesomebox

Commits

Peter Sanchez  committed deb8439

Adding notification to base class.

  • Participants
  • Parent commits ae31f40
  • Branches default

Comments (0)

Files changed (2)

File awesomebox/base.py

View file
  • Ignore whitespace
             )
         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):

File awesomebox/views.py

View file
  • Ignore whitespace
                     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})