Added support for the NO SLUGIFY option and fixed problem with filename extension separator when re composing the filename
This commit is contained in:
@@ -9,3 +9,5 @@ default_available_functions = {
|
||||
AVAILABLE_FUNCTIONS = getattr(settings, 'DOCUMENTS_METADATA_AVAILABLE_FUNCTIONS', default_available_functions)
|
||||
STAGING_DIRECTORY = getattr(settings, 'DOCUMENTS_STAGIN_DIRECTORY', '/tmp')
|
||||
FILESERVING_PATH = getattr(settings, 'DOCUMENTS_FILESERVING_PATH', '/tmp')
|
||||
DELETE_ORIGINAL = getattr(settings, 'DOCUMENTS_DELETE_ORIGINAL', False)
|
||||
SLUGIFY_PATH = getattr(settings, 'DOCUMENTS_SLUGIFY_PATH', False)
|
||||
|
||||
@@ -13,6 +13,11 @@ from dynamic_search.api import register
|
||||
|
||||
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||
from documents.conf.settings import FILESERVING_PATH
|
||||
from documents.conf.settings import SLUGIFY_PATH
|
||||
|
||||
if SLUGIFY_PATH == False:
|
||||
#Do not slugify path or filenames and extensions
|
||||
slugify = lambda x:x
|
||||
|
||||
|
||||
def get_filename_from_uuid(instance, filename, directory='documents'):
|
||||
@@ -59,20 +64,23 @@ class Document(models.Model):
|
||||
|
||||
def create_fs_links(self):
|
||||
for metadata in self.documentmetadata_set.all():
|
||||
print metadata.metadata_type.name
|
||||
|
||||
if metadata.metadata_type.documenttypemetadatatype_set.all()[0].create_directory_link:
|
||||
target_directory = os.path.join(FILESERVING_PATH, slugify(metadata.metadata_type.name), slugify(metadata.value))
|
||||
try:
|
||||
os.makedirs(target_directory)
|
||||
|
||||
except OSError as exc:
|
||||
if exc.errno == errno.EEXIST:
|
||||
pass
|
||||
else:
|
||||
raise 'Unable to create metadata indexing directory.'
|
||||
|
||||
target_filepath = os.path.join(target_directory, os.extsep.join([slugify(self.file_filename), slugify(self.file_extension)]))
|
||||
if SLUGIFY_PATH:
|
||||
extsep = os.extsep
|
||||
else:
|
||||
extsep = ''
|
||||
|
||||
target_filepath = os.path.join(target_directory, extsep.join([slugify(self.file_filename), slugify(self.file_extension)]))
|
||||
|
||||
try:
|
||||
os.symlink(os.path.abspath(self.file.path), target_filepath)
|
||||
except OSError as exc:
|
||||
|
||||
Reference in New Issue
Block a user