Fixed 2 bugs from GT:
authorŁukasz Rekucki <lrekucki@gmail.com>
Wed, 30 Sep 2009 14:40:21 +0000 (16:40 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Wed, 30 Sep 2009 14:40:21 +0000 (16:40 +0200)
https://mail.google.com/mail/?zx=pyipfvus57bn&shva=1#inbox/1240b1d511c7eb96

apps/api/handlers/library_handlers.py
apps/api/tests/__init__.py
lib/wlrepo/mercurial_backend/__init__.py

index 39177f5..9d50d02 100644 (file)
@@ -102,6 +102,9 @@ class LibraryHandler(BaseHandler):
         else:            
             data = request.FILES['ocr_file'].read().decode('utf-8')
 
         else:            
             data = request.FILES['ocr_file'].read().decode('utf-8')
 
+        if data is None:
+            return response.BadRequest().django_response('You must pass ocr_data or ocr_file.')
+
         if form.cleaned_data['generate_dc']:
             data = librarian.wrap_text(data, unicode(date.today()))
 
         if form.cleaned_data['generate_dc']:
             data = librarian.wrap_text(data, unicode(date.today()))
 
@@ -118,9 +121,10 @@ class LibraryHandler(BaseHandler):
                     doc = doc.quickwrite('xml', data.encode('utf-8'),
                         '$AUTO$ XML data uploaded.', user=request.user.username)
                 except Exception,e:
                     doc = doc.quickwrite('xml', data.encode('utf-8'),
                         '$AUTO$ XML data uploaded.', user=request.user.username)
                 except Exception,e:
+                    import traceback
                     # rollback branch creation
                     lib._rollback()
                     # rollback branch creation
                     lib._rollback()
-                    raise LibraryException("Exception occured:" + repr(e))
+                    raise LibraryException(traceback.format_exc())
 
                 url = reverse('document_view', args=[doc.id])
 
 
                 url = reverse('document_view', args=[doc.id])
 
@@ -133,8 +137,9 @@ class LibraryHandler(BaseHandler):
             finally:
                 lock.release()
         except LibraryException, e:
             finally:
                 lock.release()
         except LibraryException, e:
+            import traceback
             return response.InternalError().django_response(\
             return response.InternalError().django_response(\
-                {'exception': repr(e) })                
+                {'exception': traceback.format_exc()} )
         except DocumentAlreadyExists:
             # Document is already there
             return response.EntityConflict().django_response(\
         except DocumentAlreadyExists:
             # Document is already there
             return response.EntityConflict().django_response(\
index 2044fce..c5d79e7 100644 (file)
@@ -154,7 +154,8 @@ class SimpleTest(TestCase):
             
         resp = self.assert_json_response()
 
             
         resp = self.assert_json_response()
 
-        self.response = self.client.put(resp['text_url'], {'contents': TEXT })
+        self.response = self.client.post(resp['text_url'], {
+            'revision': resp['user_revision'] ,'contents': TEXT })
         result = self.assert_json_response(must_have={u'document': u'sample'} )
         
         #self.response = self.client.get(result['url'])
         result = self.assert_json_response(must_have={u'document': u'sample'} )
         
         #self.response = self.client.get(result['url'])
index 8b5849c..a22e49f 100644 (file)
@@ -28,11 +28,11 @@ class MercurialRevision(wlrepo.Revision):
         
     @property
     def document_name(self):
         
     @property
     def document_name(self):
-        return self._docname.decode('utf-8')
+        return self._docname and self._docname.decode('utf-8')
 
     @property
     def user_name(self):
 
     @property
     def user_name(self):
-        return self._username.decode('utf-8')
+        return self._username and self._username.decode('utf-8')
 
     def hgrev(self):
         return self._changectx.node()
 
     def hgrev(self):
         return self._changectx.node()