cleanup gdrive, remove dead code path (is_pdf) and refactor variable names
authorSeth Woodworth <seth@sethish.com>
Wed, 23 Jan 2013 05:39:51 +0000 (00:39 -0500)
committerSeth Woodworth <seth@sethish.com>
Wed, 23 Jan 2013 05:39:51 +0000 (00:39 -0500)
karmaworld/apps/notes/gdrive.py

index d33514f0a38f8d3c802eb8bf12616589fb3803d8..9f815f3e1e4903b38eae781f11b1049a58d99e38 100644 (file)
@@ -129,41 +129,32 @@ def convert_with_google_drive(note):
     # TODO: wrap this in a try loop that does a token refresh if it fails
     file_dict = service.files().insert(body=resource, media_body=media, convert=True).execute()
 
-    # set note.is_pdf
-    if file_type == 'application/pdf':
-        # Get a new copy of the file from the database with the new metadata from filemeta
-        new_file = File.objects.get(id=note.id)
-        # If it's a pdf, instead save an embed_url from resource['selfLink']
-        new_file.is_pdf = True
-        new_file.embed_url = file_dict[u'selfLink']
-        new_file.gdrive_url = file_dict[u'downloadUrl']
-    else:
-        # get the converted filetype urls
-        download_urls = {}
-        download_urls['html'] = file_dict[u'exportLinks']['text/html']
-        download_urls['text'] = file_dict[u'exportLinks']['text/plain']
-        content_dict = {}
-
-
-        for download_type, download_url in download_urls.items():
-            print "\n%s -- %s" % (download_type, download_urls)
-            resp, content = http.request(download_url, "GET")
-
-
-            if resp.status in [200]:
-                print "\t downloaded!"
-                # save to the File.property resulting field
-                content_dict[download_type] = content
-            else:
-                print "\t Download failed: %s" % resp.status
-
-        # Get a new copy of the file from the database with the new metadata from filemeta
-        new_file = Note.objects.get(id=note.id)
-
-        # set the .odt as the download from google link
-        new_file.gdrive_url = file_dict[u'exportLinks']['application/vnd.oasis.opendocument.text']
-        new_file.html = content_dict['html']
-        new_file.text = content_dict['text']
+    # get the converted filetype urls
+    download_urls = {}
+    download_urls['html'] = file_dict[u'exportLinks']['text/html']
+    download_urls['text'] = file_dict[u'exportLinks']['text/plain']
+    content_dict = {}
+
+
+    for download_type, download_url in download_urls.items():
+        print "\n%s -- %s" % (download_type, download_urls)
+        resp, content = http.request(download_url, "GET")
+
+
+        if resp.status in [200]:
+            print "\t downloaded!"
+            # save to the File.property resulting field
+            content_dict[download_type] = content
+        else:
+            print "\t Download failed: %s" % resp.status
+
+    # Get a new copy of the file from the database with the new metadata from filemeta
+    new_note = Note.objects.get(id=note.id)
+
+    # set the .odt as the download from google link
+    new_note.gdrive_url = file_dict[u'exportLinks']['application/vnd.oasis.opendocument.text']
+    new_note.html = content_dict['html']
+    new_note.text = content_dict['text']
 
     # Finally, save whatever data we got back from google
-    new_file.save()
+    new_note.save()