Initial commit to support per user staging folder
This commit is contained in:
@@ -29,6 +29,9 @@ register_settings(
|
|||||||
# Upload
|
# Upload
|
||||||
{'name': u'USE_STAGING_DIRECTORY', 'global_name': u'DOCUMENTS_USE_STAGING_DIRECTORY', 'default': False},
|
{'name': u'USE_STAGING_DIRECTORY', 'global_name': u'DOCUMENTS_USE_STAGING_DIRECTORY', 'default': False},
|
||||||
{'name': u'STAGING_DIRECTORY', 'global_name': u'DOCUMENTS_STAGING_DIRECTORY', 'default': u'/tmp/mayan/staging', 'exists': True},
|
{'name': u'STAGING_DIRECTORY', 'global_name': u'DOCUMENTS_STAGING_DIRECTORY', 'default': u'/tmp/mayan/staging', 'exists': True},
|
||||||
|
{'name': u'PER_USER_STAGING_DIRECTORY', 'global_name': u'DOCUMENTS_PER_USER_STAGING_DIRECTORY', 'default': False},
|
||||||
|
{'name': u'USER_STAGING_DIRECTORY_ROOT', 'global_name': u'DOCUMENTS_USER_STAGING_DIRECTORY_ROOT', 'default': u'/tmp/mayan/staging/users', 'exists': True},
|
||||||
|
{'name': u'USER_STAGING_DIRECTORY_EXPRESSION', 'global_name': u'DOCUMENTS_USER_STAGING_DIRECTORY_EXPRESSION', 'default': u'user.username'},
|
||||||
{'name': u'DELETE_STAGING_FILE_AFTER_UPLOAD', 'global_name': u'DOCUMENTS_DELETE_STAGING_FILE_AFTER_UPLOAD', 'default': False},
|
{'name': u'DELETE_STAGING_FILE_AFTER_UPLOAD', 'global_name': u'DOCUMENTS_DELETE_STAGING_FILE_AFTER_UPLOAD', 'default': False},
|
||||||
{'name': u'STAGING_FILES_PREVIEW_SIZE', 'global_name': u'DOCUMENTS_STAGING_FILES_PREVIEW_SIZE', 'default': u'640x480'},
|
{'name': u'STAGING_FILES_PREVIEW_SIZE', 'global_name': u'DOCUMENTS_STAGING_FILES_PREVIEW_SIZE', 'default': u'640x480'},
|
||||||
{'name': u'ENABLE_SINGLE_DOCUMENT_UPLOAD', 'global_name': u'DOCUMENTS_ENABLE_SINGLE_DOCUMENT_UPLOAD', 'default': True},
|
{'name': u'ENABLE_SINGLE_DOCUMENT_UPLOAD', 'global_name': u'DOCUMENTS_ENABLE_SINGLE_DOCUMENT_UPLOAD', 'default': True},
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from common.utils import urlquote
|
|||||||
from metadata.models import MetadataSet, MetadataType
|
from metadata.models import MetadataSet, MetadataType
|
||||||
from metadata.forms import MetadataFormSet
|
from metadata.forms import MetadataFormSet
|
||||||
|
|
||||||
from documents.staging import StagingFile
|
|
||||||
from documents.models import Document, DocumentType, \
|
from documents.models import Document, DocumentType, \
|
||||||
DocumentPage, DocumentPageTransformation
|
DocumentPage, DocumentPageTransformation
|
||||||
|
|
||||||
@@ -217,10 +216,11 @@ class DocumentForm_edit(DocumentForm):
|
|||||||
|
|
||||||
class StagingDocumentForm(forms.Form):
|
class StagingDocumentForm(forms.Form):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
cls = kwargs.pop('cls')
|
||||||
super(StagingDocumentForm, self).__init__(*args, **kwargs)
|
super(StagingDocumentForm, self).__init__(*args, **kwargs)
|
||||||
try:
|
try:
|
||||||
self.fields['staging_file_id'].choices = [
|
self.fields['staging_file_id'].choices = [
|
||||||
(staging_file.id, staging_file) for staging_file in StagingFile.get_all()
|
(staging_file.id, staging_file) for staging_file in cls.get_all()
|
||||||
]
|
]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -18,24 +18,34 @@ HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
|
|||||||
#t1=time.time();func();t2=time.time();print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0)
|
#t1=time.time();func();t2=time.time();print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0)
|
||||||
|
|
||||||
|
|
||||||
def get_all_files():
|
def get_all_files(path):
|
||||||
try:
|
try:
|
||||||
return sorted([os.path.normcase(f) for f in os.listdir(STAGING_DIRECTORY) if os.path.isfile(os.path.join(STAGING_DIRECTORY, f))])
|
return sorted([os.path.normcase(f) for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))])
|
||||||
except OSError, exc:
|
except OSError, exc:
|
||||||
raise OSError(ugettext(u'Unable get list of staging files: %s') % exc)
|
raise OSError(ugettext(u'Unable get list of staging files: %s') % exc)
|
||||||
|
|
||||||
|
|
||||||
|
def create_staging_file_class():
|
||||||
|
return type('StagingFile', (StagingFile,), dict(StagingFile.__dict__))
|
||||||
|
|
||||||
|
|
||||||
class StagingFile(object):
|
class StagingFile(object):
|
||||||
"""
|
"""
|
||||||
Simple class to encapsulate the files in a directory and hide the
|
Simple class to encapsulate the files in a directory and hide the
|
||||||
specifics to the view
|
specifics to the view
|
||||||
"""
|
"""
|
||||||
|
path = STAGING_DIRECTORY
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_path(cls, path):
|
||||||
|
cls.path = path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all(cls):
|
def get_all(cls):
|
||||||
staging_files = []
|
staging_files = []
|
||||||
for filename in get_all_files():
|
for filename in get_all_files(cls.path):
|
||||||
staging_files.append(StagingFile(
|
staging_files.append(StagingFile(
|
||||||
filepath=os.path.join(STAGING_DIRECTORY, filename)))
|
filepath=os.path.join(cls.path, filename)))
|
||||||
|
|
||||||
return staging_files
|
return staging_files
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ from document_indexing.api import update_indexes, delete_indexes
|
|||||||
|
|
||||||
from documents.conf.settings import DELETE_STAGING_FILE_AFTER_UPLOAD
|
from documents.conf.settings import DELETE_STAGING_FILE_AFTER_UPLOAD
|
||||||
from documents.conf.settings import USE_STAGING_DIRECTORY
|
from documents.conf.settings import USE_STAGING_DIRECTORY
|
||||||
|
from documents.conf.settings import PER_USER_STAGING_DIRECTORY
|
||||||
|
from documents.conf.settings import USER_STAGING_DIRECTORY_ROOT
|
||||||
|
from documents.conf.settings import USER_STAGING_DIRECTORY_EXPRESSION
|
||||||
|
|
||||||
from documents.conf.settings import PREVIEW_SIZE
|
from documents.conf.settings import PREVIEW_SIZE
|
||||||
from documents.conf.settings import THUMBNAIL_SIZE
|
from documents.conf.settings import THUMBNAIL_SIZE
|
||||||
from documents.conf.settings import UNCOMPRESS_COMPRESSED_LOCAL_FILES
|
from documents.conf.settings import UNCOMPRESS_COMPRESSED_LOCAL_FILES
|
||||||
@@ -65,7 +69,7 @@ from documents.forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
|||||||
|
|
||||||
from documents.models import Document, DocumentType, DocumentPage, \
|
from documents.models import Document, DocumentType, DocumentPage, \
|
||||||
DocumentPageTransformation, RecentDocument
|
DocumentPageTransformation, RecentDocument
|
||||||
from documents.staging import StagingFile
|
from documents.staging import create_staging_file_class
|
||||||
from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
|
from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
|
||||||
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM
|
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM
|
||||||
|
|
||||||
@@ -156,10 +160,20 @@ def upload_document_with_type(request, multiple=True):
|
|||||||
document_type = get_object_or_404(DocumentType, pk=document_type_id)
|
document_type = get_object_or_404(DocumentType, pk=document_type_id)
|
||||||
else:
|
else:
|
||||||
document_type = None
|
document_type = None
|
||||||
|
|
||||||
local_form = DocumentForm(prefix='local', initial={'document_type': document_type})
|
local_form = DocumentForm(prefix='local', initial={'document_type': document_type})
|
||||||
if USE_STAGING_DIRECTORY:
|
if USE_STAGING_DIRECTORY:
|
||||||
staging_form = StagingDocumentForm(prefix='staging',
|
StagingFile = create_staging_file_class()
|
||||||
|
|
||||||
|
staging_form = StagingDocumentForm(prefix='staging',
|
||||||
|
cls=StagingFile,
|
||||||
|
initial={'document_type': document_type})
|
||||||
|
|
||||||
|
if PER_USER_STAGING_DIRECTORY:
|
||||||
|
UserStagingFile = create_staging_file_class()
|
||||||
|
UserStagingFile.set_path('/tmp/mayan/staging/users/admin')
|
||||||
|
user_staging_form = StagingDocumentForm(prefix='user_staging',
|
||||||
|
cls=UserStagingFile,
|
||||||
initial={'document_type': document_type})
|
initial={'document_type': document_type})
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -211,38 +225,82 @@ def upload_document_with_type(request, multiple=True):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if USE_STAGING_DIRECTORY:
|
if USE_STAGING_DIRECTORY or PER_USER_STAGING_DIRECTORY:
|
||||||
try:
|
local_upload_form.update({'grid': 12})
|
||||||
filelist = StagingFile.get_all()
|
subtemplates_list.append(local_upload_form)
|
||||||
except Exception, e:
|
|
||||||
messages.error(request, e)
|
if PER_USER_STAGING_DIRECTORY:
|
||||||
filelist = []
|
try:
|
||||||
finally:
|
user_filelist = UserStagingFile.get_all()
|
||||||
local_upload_form.update({'grid': 6})
|
except Exception, e:
|
||||||
subtemplates_list.append(local_upload_form)
|
messages.error(request, e)
|
||||||
subtemplates_list.append(
|
filelist = []
|
||||||
{
|
finally:
|
||||||
'name': 'generic_form_subtemplate.html',
|
subtemplates_list.append(
|
||||||
'grid': 6,
|
{
|
||||||
'grid_clear': True,
|
'name': 'generic_form_subtemplate.html',
|
||||||
'context': {
|
'grid': 6,
|
||||||
'form': staging_form,
|
#'grid_clear': False,
|
||||||
'title': _(u'upload a document from staging'),
|
'context': {
|
||||||
}
|
'form': user_staging_form,
|
||||||
},
|
'title': _(u'upload a document from user staging'),
|
||||||
)
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if USE_STAGING_DIRECTORY:
|
||||||
|
try:
|
||||||
|
staging_filelist = StagingFile.get_all()
|
||||||
|
except Exception, e:
|
||||||
|
messages.error(request, e)
|
||||||
|
filelist = []
|
||||||
|
finally:
|
||||||
|
subtemplates_list.append(
|
||||||
|
{
|
||||||
|
'name': 'generic_form_subtemplate.html',
|
||||||
|
'grid': 6,
|
||||||
|
#'grid_clear': False,
|
||||||
|
'context': {
|
||||||
|
'form': staging_form,
|
||||||
|
'title': _(u'upload a document from staging'),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if PER_USER_STAGING_DIRECTORY:
|
||||||
subtemplates_list.append(
|
subtemplates_list.append(
|
||||||
{
|
{
|
||||||
'name': 'generic_list_subtemplate.html',
|
'name': 'generic_list_subtemplate.html',
|
||||||
|
'grid': 6,
|
||||||
|
|
||||||
|
'context': {
|
||||||
|
'title': _(u'files in user staging'),
|
||||||
|
'object_list': user_filelist,
|
||||||
|
'hide_link': True,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if USE_STAGING_DIRECTORY:
|
||||||
|
subtemplates_list.append(
|
||||||
|
{
|
||||||
|
'name': 'generic_list_subtemplate.html',
|
||||||
|
'grid': 6,
|
||||||
|
'grid_clear': True,
|
||||||
|
|
||||||
'context': {
|
'context': {
|
||||||
'title': _(u'files in staging'),
|
'title': _(u'files in staging'),
|
||||||
'object_list': filelist,
|
'object_list': staging_filelist,
|
||||||
'hide_link': True,
|
'hide_link': True,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
subtemplates_list.append(local_upload_form)
|
subtemplates_list.append(local_upload_form)
|
||||||
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'document_type_id': document_type_id,
|
'document_type_id': document_type_id,
|
||||||
@@ -597,6 +655,7 @@ def document_download(request, document_id):
|
|||||||
|
|
||||||
def staging_file_preview(request, staging_file_id):
|
def staging_file_preview(request, staging_file_id):
|
||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_CREATE])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_CREATE])
|
||||||
|
StagingFile = create_staging_file_class()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output_file, errors = StagingFile.get(staging_file_id).preview()
|
output_file, errors = StagingFile.get(staging_file_id).preview()
|
||||||
@@ -623,6 +682,7 @@ def staging_file_preview(request, staging_file_id):
|
|||||||
|
|
||||||
def staging_file_delete(request, staging_file_id):
|
def staging_file_delete(request, staging_file_id):
|
||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_CREATE])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_CREATE])
|
||||||
|
StagingFile = create_staging_file_class()
|
||||||
|
|
||||||
staging_file = StagingFile.get(staging_file_id)
|
staging_file = StagingFile.get(staging_file_id)
|
||||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', None)))
|
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', None)))
|
||||||
|
|||||||
Reference in New Issue
Block a user