예제 #1
0
 def _set_file(self, file):
     self.file_type, md5 = identify_and_md5(file)
     try:
         blob = ParentBlob.objects.get(md5_sum=md5)
     except ParentBlob.DoesNotExist:
         blob = ParentBlob(md5_sum=md5, file=file)
     if self._blob_id:
         self._old_blob = self._blob
     self._blob = blob
예제 #2
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
예제 #3
0
def uploaded_new_document(file):
    """
    Sets up a new document object ready to be saved.
    Note that it won't fill in the `title` or `author` attributes,
    you have to do that.
    """
    file_type, md5_sum = identify_and_md5(file)
    try:
        blob = ParentBlob.objects.get(md5_sum=md5_sum)
    except ParentBlob.DoesNotExist:
        blob = ParentBlob.objects.create(md5_sum=md5_sum, file=file,
                                            file_type=file_type)
        blob.save()
    document = Document()
    document.file_name = os.path.basename(file.name)
    document._blob = blob

    return document
예제 #4
0
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