From 3ab4df45c8d8d88587c900f61102daa9b41833ff Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 26 Jun 2013 21:10:44 +0000 Subject: [PATCH] finish off changes to google drive to allow for ppt > pdf and pdf.js --- karmaworld/apps/notes/gdrive.py | 13 ++++----- karmaworld/apps/notes/views.py | 31 +++++++++++++++------ karmaworld/templates/notes/note_detail.html | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/karmaworld/apps/notes/gdrive.py b/karmaworld/apps/notes/gdrive.py index d7bacb9..daa21fa 100644 --- a/karmaworld/apps/notes/gdrive.py +++ b/karmaworld/apps/notes/gdrive.py @@ -171,25 +171,24 @@ def convert_with_google_drive(note): new_note.file_type = '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) + nonce_path = '/ppt_pdf/%s/%s/' % (now.year, now.month) + + _path = filename + '.pdf' try: # If those folders don't exist, create them os.makedirs(os.path.realpath(os.path.dirname(_path))) + except: + print "we failed to create those directories" _writer = BufferedWriter(FileIO(_path, "w")) _writer.write(content_dict['pdf']) _writer.close() - new_note.pdf_file = os.path.join(_path, filename) + new_note.pdf_file = _path - # set the .odt as the download from google link - if extension.lower() in ['.ppt', '.pptx']: - print "is ppt" - new_note.pdf_file = File(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'] diff --git a/karmaworld/apps/notes/views.py b/karmaworld/apps/notes/views.py index 378a448..2202a86 100644 --- a/karmaworld/apps/notes/views.py +++ b/karmaworld/apps/notes/views.py @@ -18,6 +18,21 @@ from karmaworld.apps.notes.models import Note from karmaworld.apps.notes.forms import NoteForm + +def is_pdf(self): + _path = self.object.note_file.name + _, _extension = os.path.splitext(_path) + if _extension.lower() == '.pdf': + return True + return False + +def is_ppt(self): + if self.object.pdf_file: + print "is a ppt" + return True + return False + + class NoteDetailView(DetailView): """ Class-based view for the note html page """ model = Note @@ -30,14 +45,8 @@ class NoteDetailView(DetailView): #kwargs['file_url'] = os.path.basename(_path) #kwargs['hostname'] = Site.objects.get_current() - def is_pdf(self): - _path = self.object.note_file.name - _, _extension = os.path.splitext(_path) - if _extension.lower() == '.pdf': - return True - return False - kwargs['pdf'] = is_pdf(self) + kwargs['ppt'] = is_ppt(self) return super(NoteDetailView, self).get_context_data(**kwargs) @@ -119,7 +128,11 @@ class PDFView(DetailView): # FIXME: There may be an undocumented, # but better way of handling media files in django - kwargs['pdf_path'] = "{0}{1}".format(settings.MEDIA_URL, - os.path.basename(self.object.note_file.name)) + if is_ppt: + kwargs['pdf_path'] = "{0}{1}".format(settings.MEDIA_URL, + os.path.basename(self.object.pdf_file.name)) + elif is_pdf: + kwargs['pdf_path'] = "{0}{1}".format(settings.MEDIA_URL, + os.path.basename(self.object.note_file.name)) return super(PDFView, self).get_context_data(**kwargs) diff --git a/karmaworld/templates/notes/note_detail.html b/karmaworld/templates/notes/note_detail.html index 8c396e6..3ce6d1d 100644 --- a/karmaworld/templates/notes/note_detail.html +++ b/karmaworld/templates/notes/note_detail.html @@ -35,7 +35,7 @@
- {% if pdf %} + {% if pdf or ppt %}
-- 2.25.1