self.uploaded_at.day, self.uploaded_at.microsecond)
self.slug = _slug
+ def _get_fpf(self):
+ """
+ Memoized FilepickerFile getter. Returns FilepickerFile.
+ """
+ if not hasattr(self, 'cached_fpf'):
+ # Fetch additional_params containing signature, etc
+ aps = self.fp_file.field.additional_params
+ self.cached_fpf = django_filepicker.utils.FilepickerFile(self.fp_file.name, aps)
+ return self.cached_fpf
+
+ def get_fp_url(self):
+ """
+ Returns the Filepicker URL for reading the upstream document.
+ """
+ # Fetch FilepickerFile
+ fpf = self._get_fpf()
+ # Return proper URL for reading
+ return fpf.get_url()
+
def get_file(self):
- """ Downloads the file from filepicker.io and returns a
- Django File wrapper object """
- fpf = django_filepicker.utils.FilepickerFile(self.fp_file.name)
- return fpf.get_file(self.fp_file.field.additional_params)
+ """
+ Downloads the file from filepicker.io and returns a Django File wrapper
+ object.
+ """
+ # Fetch FilepickerFile
+ fpf = self._get_fpf()
+ # Return Django File
+ return fpf.get_file()
def save(self, *args, **kwargs):
if self.name and not self.slug:
kwargs['pdf_path'] = "{0}{1}".format(settings.MEDIA_URL,
os.path.basename(self.object.pdf_file.name))
elif is_pdf(self):
- kwargs['pdf_path'] = self.object.fp_file
+ kwargs['pdf_path'] = self.object.get_fp_url()
#kwargs['pdf_path'] = "{0}{1}".format(settings.MEDIA_URL,
# os.path.basename(self.object.note_file.name))
</a>
</div>
<div class="small-4 column">
- <a id="note-download-button" href="{{ note.fp_file }}">
+ <a id="note-download-button" href="{{ note.get_fp_url }}">
<img
src="{{ STATIC_URL }}img/note_download.png"
alt="note_download"