From 967b0218230563c0c62217c4b7f08840e5cceda3 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 26 Jun 2013 16:33:00 -0400 Subject: [PATCH] more tests for gdrive --- karmaworld/apps/notes/gdrive.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/karmaworld/apps/notes/gdrive.py b/karmaworld/apps/notes/gdrive.py index dac5593..437300c 100644 --- a/karmaworld/apps/notes/gdrive.py +++ b/karmaworld/apps/notes/gdrive.py @@ -3,6 +3,7 @@ # Copyright (C) 2012 FinalsClub Foundation import datetime +from io import FileIO, BufferedWriter import mimetypes import os import time @@ -159,7 +160,22 @@ def convert_with_google_drive(note): new_note = Note.objects.get(id=note.id) if extension.lower() == '.pdf': new_note.file_type = 'pdf' - new_note.pdf_file = File(content_dict['pdf']) + + elif extension.lower() in ['.ppt', '.pptx']: + print "try to save ppt" + now = datetime.datetime.utcnow() + # create a folder path to store the ppt > pdf file with year and month folders + _path = os.path.join(settings.MEDIA_ROOT, 'ppt_pdf/%s/%s' % (now.year, now.month), filename) + try: + # If those folders don't exist, create them + os.makedirs(os.path.realpath(os.path.dirname(_path))) + + _writer = BufferedWriter(FileIO(_path, "w")) + _writer.write(content_dict['pdf']) + _writer.close() + + + new_note.pdf_file = os.path.join(_path, filename) # set the .odt as the download from google link new_note.gdrive_url = file_dict[u'exportLinks']['application/vnd.oasis.opendocument.text'] -- 2.25.1