Anonymous avatar Anonymous committed fbaa633

move stop handlin in utils so we could reuse code.

Comments (0)

Files changed (3)

friendpaste/utils/__init__.py

 from time import strptime, localtime, struct_time
 from gettext import gettext, ngettext
 import os
+import socket
 import sys
 from glob import glob
 
 from werkzeug import Local, LocalManager
 from friendpaste import settings
 
+from friendpaste.utils import stomp
+
 _hex = binascii.hexlify
 local = Local()
 local_manager = LocalManager([local])
     
 def short(node):
     return _hex(node[:6])
+
+
+def send_stomp_msg(message, destination):
+    connected = False
+    while not connected:
+        try:
+            conn = stomp.Connection()
+            conn.start()
+            conn.connect()
+            conn.send(' ' + message, destination=destination)
+            conn.disconnect()
+            connected = True
+        except socket.error:
+            pass
+

friendpaste/views.py

 from friendpaste.template import render_response, highlighter, pretty_type, shighlight, \
 render_template
 from friendpaste.utils import local, local_manager, datetimestr_topython,\
-strptime, make_hash, datetime_tojson
+strptime, make_hash, datetime_tojson, send_stomp_msg
 from friendpaste.utils.diff import get_unchanged_lines
-from friendpaste.utils import stomp
+
 
 def _get_lexers():
     lexers = get_all_lexers()
             'reviews_count': len(review.reviews),
             'type': 'review'
         })
-        connected = False
-        while not connected:
-            try:
-                conn = stomp.Connection()
-                conn.start()
-                conn.connect()
-                conn.send(' ' + message, destination='/paste/%s/%s' % (
+
+        send_stomp_msg(' ' + message, destination='/paste/%s/%s' % (
                     s.pasteid, s.nb_revision))
-                conn.disconnect()
-                connected = True
-            except socket.error:
-                pass
 
     if review.reviews:
         review.reviews.sort(lambda a,b: cmp(a['created'], b['created']))

static/js/src/review.js

     },
 
     handle_messages: function(frame) {
-
-        
-
         var message = base2.JSON.parse(frame.body);
         var me = false;
         if (message.type == 'review') {
             }
         }
 
-
-        //alert('line #' + message.nb_line + ' with ' + message.reviews_count + ' reviews was updated');
     },
 
     
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.