diff --git a/apps/document_indexing/api.py b/apps/document_indexing/api.py index 972b903210..269d5ceddd 100644 --- a/apps/document_indexing/api.py +++ b/apps/document_indexing/api.py @@ -15,7 +15,7 @@ from document_indexing.filesystem import fs_create_index_directory, \ fs_create_document_link, fs_delete_document_link, \ fs_delete_index_directory, fs_delete_directory_recusive from document_indexing.conf.settings import SLUGIFY_PATHS -from document_indexing.os_agnostic import assemble_document_filename +from document_indexing.os_specifics import assemble_suffixed_filename if SLUGIFY_PATHS == False: # Do not slugify path or filenames and extensions @@ -131,10 +131,10 @@ def find_lowest_available_suffix(index_instance, document): index_instance_documents = DocumentRenameCount.objects.filter(index_instance=index_instance)#.filter(document__file_extension=document.file_extension) files_list = [] for index_instance_document in index_instance_documents: - files_list.append(assemble_document_filename(index_instance_document.document, index_instance_document.suffix)) + files_list.append(assemble_suffixed_filename(index_instance_document.document.file.name, index_instance_document.suffix)) for suffix in xrange(MAX_SUFFIX_COUNT): - if assemble_document_filename(document, suffix) not in files_list: + if assemble_suffixed_filename(document.file.name, suffix) not in files_list: return suffix raise MaxSuffixCountReached(ugettext(u'Maximum suffix (%s) count reached.') % MAX_SUFFIX_COUNT) diff --git a/apps/document_indexing/filesystem.py b/apps/document_indexing/filesystem.py index f8762060ce..c89dad4cf6 100644 --- a/apps/document_indexing/filesystem.py +++ b/apps/document_indexing/filesystem.py @@ -3,7 +3,8 @@ import os from django.utils.translation import ugettext_lazy as _ -from document_indexing.os_agnostic import assemble_document_filename +from document_indexing.os_specifics import (assemble_suffixed_filename, + assemble_path_from_list) from document_indexing.conf.settings import FILESERVING_ENABLE from document_indexing.conf.settings import FILESERVING_PATH @@ -19,12 +20,12 @@ def get_instance_path(index_instance): names.append(index_instance.value) - return os.sep.join(names) + return assemble_path_from_list(names) def fs_create_index_directory(index_instance): if FILESERVING_ENABLE: - target_directory = os.path.join(FILESERVING_PATH, get_instance_path(index_instance)) + target_directory = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance)]) try: os.mkdir(target_directory) except OSError, exc: @@ -36,8 +37,9 @@ def fs_create_index_directory(index_instance): def fs_create_document_link(index_instance, document, suffix=0): if FILESERVING_ENABLE: - filename = assemble_document_filename(document.file_filename, suffix) - filepath = os.path.join(FILESERVING_PATH, get_instance_path(index_instance), filename) + filename = assemble_suffixed_filename(document.file.name, suffix) + filepath = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance), filename]) + try: os.symlink(document.file.path, filepath) except OSError, exc: @@ -55,8 +57,8 @@ def fs_create_document_link(index_instance, document, suffix=0): def fs_delete_document_link(index_instance, document, suffix=0): if FILESERVING_ENABLE: - filename = assemble_document_filename(document.file_filename, suffix) - filepath = os.path.join(FILESERVING_PATH, get_instance_path(index_instance), filename) + filename = assemble_suffixed_filename(document.file.name, suffix) + filepath = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance), filename]) try: os.unlink(filepath) @@ -68,7 +70,7 @@ def fs_delete_document_link(index_instance, document, suffix=0): def fs_delete_index_directory(index_instance): if FILESERVING_ENABLE: - target_directory = os.path.join(FILESERVING_PATH, get_instance_path(index_instance)) + target_directory = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance)]) try: os.removedirs(target_directory) except OSError, exc: