From 27a6798dae9d7ec8f95d6f94b27df5b5e89d925b Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Wed, 18 Dec 2013 12:00:58 -0500 Subject: [PATCH] Better Evernotes --- karmaworld/apps/document_upload/tasks.py | 2 - karmaworld/apps/notes/gdrive.py | 72 +------------------- karmaworld/templates/partial/filepicker.html | 2 +- reqs/common.txt | 2 - 4 files changed, 4 insertions(+), 74 deletions(-) diff --git a/karmaworld/apps/document_upload/tasks.py b/karmaworld/apps/document_upload/tasks.py index e863085..9c1adac 100644 --- a/karmaworld/apps/document_upload/tasks.py +++ b/karmaworld/apps/document_upload/tasks.py @@ -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 """ diff --git a/karmaworld/apps/notes/gdrive.py b/karmaworld/apps/notes/gdrive.py index cd540e7..b37debe 100644 --- a/karmaworld/apps/notes/gdrive.py +++ b/karmaworld/apps/notes/gdrive.py @@ -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] diff --git a/karmaworld/templates/partial/filepicker.html b/karmaworld/templates/partial/filepicker.html index 5adb5b8..edad646 100644 --- a/karmaworld/templates/partial/filepicker.html +++ b/karmaworld/templates/partial/filepicker.html @@ -14,7 +14,7 @@ data-fp-button-text=" 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" diff --git a/reqs/common.txt b/reqs/common.txt index d48d7ae..2593513 100644 --- a/reqs/common.txt +++ b/reqs/common.txt @@ -14,5 +14,3 @@ django-filepicker==0.1.5 filemagic==1.6 fabric-virtualenv requests -beautifulsoup4 -git+https://github.com/btbonval/ENML_PY.git -- 2.25.1