Peter Sanchez avatar Peter Sanchez committed deb8439

Adding notification to base class.

Comments (0)

Files changed (2)

awesomebox/base.py

             )
         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):

awesomebox/views.py

                     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})
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.