Better Evernotes
authorCharles Connell <charles@connells.org>
Wed, 18 Dec 2013 17:00:58 +0000 (12:00 -0500)
committerCharles Connell <charles@connells.org>
Wed, 18 Dec 2013 17:00:58 +0000 (12:00 -0500)
karmaworld/apps/document_upload/tasks.py
karmaworld/apps/notes/gdrive.py
karmaworld/templates/partial/filepicker.html
reqs/common.txt

index e8630859915f46456fb2594b6c7c54342f4af854..9c1adac0d06a7955c92e8a60900e2a36f6b2c556 100644 (file)
@@ -2,11 +2,9 @@
 # -*- coding:utf8 -*-
 # Copyright (C) 2013  FinalsClub Foundation
 
-from celery import Celery
 from celery import task
 from karmaworld.apps.notes.gdrive import convert_raw_document
 
-#@Celery.task()
 @task()
 def process_raw_document(raw_document):
     """ Process a RawDocument instance in to a Note instance """
index cd540e7f2f311f312edade48a222b7d07d05c13f..b37debe9a9d2d1cb1270319a70f70002b83fdc6a 100644 (file)
@@ -3,7 +3,6 @@
 # Copyright (C) 2012  FinalsClub Foundation
 
 import datetime
-from ENML2HTML import ENMLToHTML
 import magic
 import mimetypes
 import os
@@ -163,68 +162,6 @@ def upload_to_gdrive(service, media, filename, extension=None, mimetype=None):
     return file_dict
 
 
-def convert_with_google_drive(note):
-    """ Upload a local note and download HTML
-        using Google Drive
-        :note: a File model instance # FIXME
-    """
-    # TODO: set the permission of the file to permissive so we can use the
-    #       gdrive_url to serve files directly to users
-
-    # Get file_type and encoding of uploaded file
-    # i.e: file_type = 'text/plain', encoding = None
-    (file_type, encoding) = mimetypes.guess_type(note.note_file.path)
-
-
-    if file_type == 'text/enml': file_type = 'text/xml'
-
-    if file_type != None:
-        media = MediaFileUpload(note.note_file.path, mimetype=file_type,
-                    chunksize=1024*1024, resumable=True)
-
-    else:
-        media = MediaFileUpload(note.note_file.path,
-                    chunksize=1024*1024, resumable=True)
-
-    auth = DriveAuth.objects.filter(email=GOOGLE_USER).all()[0]
-    creds = auth.transform_to_cred()
-
-
-    creds, auth = check_and_refresh(creds, auth)
-
-    service, http = build_api_service(creds)
-
-    # get the file extension
-    filename, extension = os.path.splitext(note.note_file.path)
-
-    file_dict = upload_to_gdrive(service, media, filename, extension)
-
-    content_dict = download_from_gdrive(file_dict, http, extension)
-
-    # Get a new copy of the file from the database with the new metadata from filemeta
-    new_note = Note.objects.get(id=note.id)
-
-    if extension.lower() == '.pdf':
-        new_note.file_type = 'pdf'
-
-    elif extension.lower() in ['.ppt', '.pptx']:
-        new_note.file_type = 'ppt'
-        new_note.pdf_file.save(filename + '.pdf', ContentFile(content_dict['pdf']))
-
-    else:
-        # PPT files do not have this export ability
-        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']
-
-    # before we save new html, sanitize a tags in note.html
-    #new_note.sanitize_html(save=False)
-    #FIXME: ^^^ disabled until we can get html out of an Etree html element
-
-    # Finally, save whatever data we got back from google
-    new_note.save()
-
 def convert_raw_document(raw_document):
     """ Upload a raw document to google drive and get a Note back """
     fp_file = raw_document.get_file()
@@ -240,18 +177,15 @@ def convert_raw_document(raw_document):
     print mimetype
     print ""
 
-    document_contents = fp_file.read()
-
-    # Special case for Evernote documents
+    # A special case for Evernotes
     if raw_document.mimetype == 'text/enml':
-        document_contents = ENMLToHTML(document_contents)
         raw_document.mimetype = 'text/html'
 
     if raw_document.mimetype == None:
-        media = MediaInMemoryUpload(document_contents,
+        media = MediaInMemoryUpload(fp_file.read(),
                     chunksize=1024*1024, resumable=True)
     else:
-        media = MediaInMemoryUpload(document_contents, mimetype=raw_document.mimetype,
+        media = MediaInMemoryUpload(fp_file.read(), mimetype=raw_document.mimetype,
                     chunksize=1024*1024, resumable=True)
 
     auth = DriveAuth.objects.filter(email=GOOGLE_USER).all()[0]
index 5adb5b80f8060136fc1e96acb741db9358f6c5f2..edad6464339e60974b4fa4f983080908a3c9cf34 100644 (file)
@@ -14,7 +14,7 @@
           data-fp-button-text="<i class=icon-upload></i> add notes"
           data-fp-drag-text="Drop Some Knowledge"
           data-fp-drag-class="dragdrop show-for-medium-up large-7 columns"
-          data-fp-extensions=".pdf,.doc,.docx,.txt,.rtf,.odt,.png,.jpg,.jpeg,.ppt,.pptx"
+          data-fp-mimetypes="*/*"
           data-fp-store-path="{{ course.school.slug }}/ {{ course.slug }}/"
           data-fp-store-location="S3"
           data-fp-services="COMPUTER,DROPBOX,URL,GOOGLE_DRIVE,EVERNOTE,GMAIL,BOX,FACEBOOK,FLICKR,PICASA,IMAGE_SEARCH,WEBCAM,FTP"
index d48d7aedbfb7c1881b187ae3b9997fd01bd12e09..25935135593202db8f079cf62078d7bd3c5e19a2 100644 (file)
@@ -14,5 +14,3 @@ django-filepicker==0.1.5
 filemagic==1.6
 fabric-virtualenv
 requests
-beautifulsoup4
-git+https://github.com/btbonval/ENML_PY.git