# Copyright (C) 2012 FinalsClub Foundation
import datetime
-from io import FileIO, BufferedWriter
import mimetypes
import os
import time
from apiclient.http import MediaFileUpload
from apiclient.http import MediaInMemoryUpload
from django.conf import settings
-from django.core.files import File
+from django.core.files.base import ContentFile
from oauth2client.client import flow_from_clientsecrets
from karmaworld.apps.notes.models import DriveAuth, Note
elif extension.lower() in ['.ppt', '.pptx']:
new_note.file_type = 'ppt'
- now = datetime.datetime.utcnow()
- # create a folder path to store the ppt > pdf file with year and month folders
- 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 = _path
+ new_note.pdf_file.save(filename + '.pdf', ContentFile(content_dict['pdf']))
else:
# PPT files do not have this export ability
elif raw_document.mimetype in PPT_MIMETYPES:
note.file_type = 'ppt'
- now = datetime.datetime.utcnow()
- # create a folder path to store the ppt > pdf file with year and month folders
- 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()
-
- note.pdf_file = _path
+ note.pdf_file.save(filename + '.pdf', ContentFile(content_dict['pdf']))
else:
# PPT files do not have this export ability
blank=True, null=True)
# Upload files to MEDIA_ROOT/notes/YEAR/MONTH/DAY, 2012/10/30/filename
- # FIXME: because we are adding files by hand in tasks.py, upload_to is being ignored for media files
pdf_file = models.FileField( \
storage=fs, \
- upload_to="notes/%Y/%m/%j/",\
+ upload_to="notes/%Y/%m/%d/",\
blank=True, null=True)
# No longer keeping a local copy backed by django
note_file = models.FileField( \
storage=fs, \
- upload_to="notes/%Y/%m/%j/",\
+ upload_to="notes/%Y/%m/%d/",\
blank=True, null=True)
# Google Drive URLs