Commits

Anonymous committed b7e9b97

Added comments about voting not being fully HTTP compliant. But we're
close and it works without JavaScript which is a huge plus.

  • Participants
  • Parent commits ffebcda

Comments (0)

Files changed (3)

File solace/application.py

             rv = get_view('core.forbidden')(self)
         except NotFound, e:
             rv = get_view('core.not_found')(self)
+        rv = self.process_view_result(rv)
+        after_request_dispatch.emit(request=self, response=rv)
+        return rv
+
+    def process_view_result(self, rv):
+        """Processes a view's return value and ensures it's a response
+        object.  This is automatically called by the dispatch function
+        but is also handy for view decorators.
+        """
         if isinstance(rv, basestring):
             rv = Response(rv, mimetype='text/html')
-        after_request_dispatch.emit(request=self, response=rv)
+        elif not isinstance(rv, Response):
+            rv = Response.force_type(rv, self.environ)
         return rv
 
     def _get_locale(self):

File solace/static/solace.js

   },
 
   /* replaces a container with the response from a server. */
-  loadPartial : function(selector, url, data) {
-    Solace.request(url, data, 'GET', function(response) {
+  loadPartial : function(selector, url, method, data) {
+    Solace.request(url, data, method, function(response) {
       var el = $(response.html);
       $(selector).replaceWith(el);
       Solace.processElement(el);
   makeDynamicVotes : function(selector, element) {
     $('div.votebox a', element).bind('click', function() {
       var link = $(this);
-      Solace.loadPartial(link.parent().parent(), link.attr('href'));
+      Solace.loadPartial(link.parent().parent(), link.attr('href'), 'POST');
       return false;
     });
   },
   makeDynamicAccepting : function(element) {
     $('div.acceptbox a', element).bind('click', function() {
       var link = $(this);
-      Solace.request(link.attr('href'), null, 'GET',
+      Solace.request(link.attr('href'), null, 'POST',
                      function(response) {
         var reply = link.parent().parent();
         if (response.accepted) {

File solace/views/kb.py

 from solace.utils.forms import Form as EmptyForm
 from solace.utils.formatting import format_creole_diff, format_creole
 from solace.utils.csrf import exchange_token_protected
+from solace.utils.caching import no_cache
 
 
 _topic_order = {
     return common_userlist(request, locale=request.view_lang)
 
 
+@no_cache
 @require_login
 @exchange_token_protected
 def vote(request, post):
     """Votes on a post."""
+    # TODO: this is currently also fired as GET if JavaScript is
+    # not available.  Not very nice.
     post = Post.query.get(post)
     if post is None:
         raise NotFound()
     return json_response(html=box(post, request.user))
 
 
+@no_cache
+@exchange_token_protected
 @require_login
 def accept(request, post):
     """Accept a post as an answer."""
+    # TODO: this is currently also fired as GET if JavaScript is
+    # not available.  Not very nice.
     post = Post.query.get(post)
     if post is None:
         raise NotFound()