Example #1
0
 def _set_file(self, file):
     self.file_type, md5 = identify_and_md5(file)
     path = get_path(self.file_type)
     try:
         blob = DerivedBlob.objects.get(md5_sum=md5,
                                         upload_to_url=path)
         if hasattr(self, '_blob'):
             self._old_blob = self._blob
     except DerivedBlob.DoesNotExist:
         blob = DerivedBlob(upload_to_url=path, md5_sum=md5, file=file)
     self._blob = blob
def uploaded_new_derived_document(file):
    """
    Like `uploaded_new_derived_document' this creates the 'DerivedBlob'
    object and a 'DerivedDocument' object.

    The `DerivedDocument` object is returned, you need to fill in
    `derived_from` and `index`.
    """
    file_type, md5_sum = identify_and_md5(file)
    try:
        blob = DerivedBlob.objects.get(md5_sum=md5_sum)
    except DerivedBlob.DoesNotExist:
        blob = DerivedBlob(md5_sum=md5_sum, file=file, file_type=file_type)
        blob.upload_to_url = get_path(file_type)
        blob.save()

    document = DerivedDocument()
    document._blob = blob

    return document