本文整理汇总了Python中core.document_processor.DocumentProcessor.read方法的典型用法代码示例。如果您正苦于以下问题:Python DocumentProcessor.read方法的具体用法?Python DocumentProcessor.read怎么用?Python DocumentProcessor.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.document_processor.DocumentProcessor
的用法示例。
在下文中一共展示了DocumentProcessor.read方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_file_delete
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def edit_file_delete(request, code):
"""Deletes specified code or revision from system (Marks deleted)
@param request: is a Django request object
@param code is a DMS Object() code for view interactions"""
# Decision of where to go back after or instead of removal
return_url = reverse('mdtui-home')
if 'edit_return' in request.session:
return_url = request.session['edit_return']
if request.method == 'POST':
revision = request.POST.get('revision', False)
if revision:
return_url = reverse('mdtui-edit-revisions', kwargs={'code': code})
processor = DocumentProcessor()
processor.read(code, {'user': request.user, 'only_metadata': True})
if not processor.errors:
# Selecting to delete (Mark deleted) revision or whole document
options = {'user': request.user}
if revision:
options['mark_revision_deleted'] = revision
else:
options['mark_deleted'] = True
processor.delete(code, options)
if not processor.errors:
request.session['cleanup_caches'] = True
return HttpResponseRedirect(return_url)
return HttpResponseRedirect(return_url)
示例2: view_object
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def view_object(request, code, step, template='mdtui/view.html'):
"""View PDF Document
@param request: is a Django request object
@param code: is a DMS Object() code for view interactions
@param step: is a current step name (for template rendering)
@param template: is a name of template for this view"""
# TODO: Add certain revision view possibility for "edit revisions" view
revision = request.GET.get('revision', None)
pdf_url = reverse('mdtui-download-pdf', kwargs={'code': code})
processor = DocumentProcessor()
document = processor.read(code, options={'only_metadata': True, 'user': request.user, 'revision': revision})
mimetype = document.get_mimetype()
context = {
'pdf_url': pdf_url,
'code': code,
'step': step,
'mimetype': mimetype,
'revision': revision,
}
if not document.get_file_revisions_data():
db = document.get_db_info()
if 'metadata_doc_type_rule_id' in db.iterkeys() and db['metadata_doc_type_rule_id']:
# Indexed Document with 0 revisions (Displaying stub document from static)
# TODO: expand this for branding. (Using custom DMS stub document)
stub_doc_url = settings.STATIC_URL + 'pdf/stub_document.pdf'
context.update({'mimetype': 'stub_document', 'pdf_url': stub_doc_url})
return render(request, template, context)
示例3: upload
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def upload(request, template_name='browser/upload.html', extra_context=None):
"""Upload file processing.
Uploaded file will be check against available rules to
determine storage, validator, and security plugins.
"""
extra_context = extra_context or {}
form = UploadForm(request.POST or None, request.FILES or None)
if request.method == 'POST':
if form.is_valid():
processor = DocumentProcessor()
upl_file = form.files['file']
# finding file in system. Updating if found and storing new if not or uncategorized.
dms_file = processor.read(upl_file.name, {'user': request.user, 'only_metadata': True})
if not processor.errors and not dms_file.get_docrule().uncategorized:
processor.update(upl_file.name, {'user': request.user, 'update_file': upl_file})
else:
processor.errors = []
processor.create(upl_file, {'user': request.user})
# Handling processor errors in interactions.
if not processor.errors:
if dms_file.get_docrule().uncategorized:
messages.success(request, 'File has been uploaded into uncategorized.')
else:
messages.success(request, 'File has been uploaded.')
log.info('browser.upload file: %s sucess' % form.files['file'].name)
else:
error_string = "; ".join([unicode(x) for x in processor.errors])
messages.error(request, error_string)
log.error('browser.upload errror: %s' % error_string)
extra_context['form'] = form
return render(request, template_name, extra_context)
示例4: read
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def read(self, request, code, suggested_format=None):
revision, hashcode, extra = self._get_info(request)
processor = DocumentProcessor()
options = {
'hashcode': hashcode,
'revision': revision,
'extension': suggested_format,
'user': request.user,
}
document = processor.read(code, options)
if not request.user.is_superuser:
# Hack: Used part of the code from MDTUI Wrong!
user_permissions = list_permitted_docrules_qs(request.user)
if not document.docrule in user_permissions:
return rc.FORBIDDEN
if processor.errors:
log.error('FileHandler.read manager errors: %s' % processor.errors)
return rc.NOT_FOUND
if document.marked_deleted:
log.error('FileHandler.read request to marked deleted document: %s' % code)
return rc.NOT_FOUND
else:
response = DMSObjectResponse(document)
log.info('FileHandler.read request fulfilled for code: %s, options: %s' % (code, options))
return response
示例5: read
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def read(self, request, code, suggested_format=None):
revision, hashcode, extra = self._get_info(request)
processor = DocumentProcessor()
options = {
'revision': revision,
'hashcode': hashcode,
'only_metadata': True,
'extension': suggested_format,
'user': request.user,
}
document = processor.read(code, options)
if document.marked_deleted:
log.error('FileInfoHandler.read request to marked deleted document: %s' % code)
return rc.NOT_FOUND
if processor.errors:
log.error('FileInfoHandler.read errors: %s' % processor.errors)
if settings.DEBUG:
raise Exception('FileInfoHandler.read manager.errors')
else:
return rc.BAD_REQUEST
info = DMSOBjectRevisionsData(document).jsons
log.info(
'FileInfoHandler.read request fulfilled for %s, ext %s, rev %s, hash %s'
% (code, suggested_format, revision, hashcode)
)
return HttpResponse(info)
示例6: get
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def get(self, request, code, suggested_format=None):
revision, hashcode, extra = self._get_info(request)
only_metadata = True
indexing_data = extra.get('indexing_data', None)
# Security measure for variable
if indexing_data:
indexing_data = True
only_metadata = False
processor = DocumentProcessor()
options = {
'revision': revision,
'hashcode': hashcode,
'only_metadata': only_metadata,
'extension': suggested_format,
'indexing_data': indexing_data,
'user': request.user,
}
document = processor.read(code, options)
if document.marked_deleted:
log.error('FileInfoHandler.read request to marked deleted document: %s' % code)
return Response(status=status.HTTP_404_NOT_FOUND)
if processor.errors:
log.error('FileInfoHandler.read errors: %s' % processor.errors)
if settings.DEBUG:
raise Exception('FileInfoHandler.read manager.errors')
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
info = DMSOBjectRevisionsData(document).jsons
log.info(
'FileInfoHandler.read request fulfilled for %s, ext %s, rev %s, hash %s'
% (code, suggested_format, revision, hashcode)
)
return Response(info, status=status.HTTP_200_OK)
示例7: edit_file_revisions
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def edit_file_revisions(request, code, step='edit_revisions', template='mdtui/indexing.html'):
"""Editing file revisions for given code"""
form = DocumentUploadForm(request.POST or None, request.FILES or None)
revision_file = request.FILES.get('file', None)
errors = []
context = {
'step': step,
'doc_name': code,
'upload_form': form,
'barcode': None, # for compatibility with scripts (We are reusing modal scripts in templates)
}
processor = DocumentProcessor()
doc = processor.read(code, {'user': request.user, 'only_metadata': True})
frd = doc.get_file_revisions_data()
db_info = doc.get_db_info()
if not processor.errors and not doc.marked_deleted:
if revision_file and form.is_valid():
options = {
'user': request.user,
'update_file': revision_file,
}
processor.update(code, options)
if not processor.errors:
return HttpResponseRedirect(request.path)
else:
errors.append(processor.errors)
context.update({
'file_revision_data': frd,
'file_revision_data_order_list': sorted(frd.iterkeys()),
'index_data': db_info,
})
if processor.errors or doc.marked_deleted or (not frd and not db_info['mdt_indexes']):
errors = [MDTUI_ERROR_STRINGS['NO_DOC'] + '. Maybe you should go index it first?']
context.update({'error_warnings': errors})
return render(request, template, context)
示例8: get_file
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def get_file(request, code, suggested_format=None):
hashcode = request.GET.get('hashcode', None) # Refactor me out
processor = DocumentProcessor()
options = {
'hashcode': hashcode,
'extension': suggested_format,
'user': request.user,
}
document = processor.read(code, options)
if processor.errors:
response = error_response(processor.errors)
else:
response = DMSObjectResponse(document)
return response
示例9: revision_document
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def revision_document(request, document):
document_name = document
processor = DocumentProcessor()
document = processor.read(document_name, options={'only_metadata': True, 'user': request.user})
extra_context = {}
file_revision_data = document.get_file_revisions_data()
def get_args(f_info):
args = []
for arg in ['revision', 'hashcode']:
if f_info.get(arg, None):
args.append("%s=%s" % (arg, f_info[arg]))
arg_string = ""
if args:
arg_string = "?" + "&".join(args)
return arg_string
if not processor.errors:
if file_revision_data:
revisions = map(lambda x: int(x), file_revision_data.keys())
revisions.sort()
fileinfos = []
for revision in revisions:
fileinfo = file_revision_data[str(revision)]
fileinfo['args'] = get_args(fileinfo)
if not 'deleted' in fileinfo:
fileinfo['deleted'] = False
fileinfos.append(fileinfo)
extra_context = {
'fileinfo_db': fileinfos,
'document_name': document.get_code(),
}
else:
fileinfo = {
'revision': None,
'name': document.get_filename(),
'created_date': document.get_creation_time(),
'hashcode': document.get_hashcode(),
}
fileinfo['args'] = get_args(fileinfo)
extra_context = {
'fileinfo_db': [fileinfo],
'document_name': document.get_filename(),
}
else:
messages.error(request, "; ".join(map(lambda x: x.parameter, processor.errors)))
if processor.warnings:
messages.warning(request, "; ".join(processor.warnings))
return render(request, 'browser/revision.html', extra_context)
示例10: edit_type
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def edit_type(request, code, step='edit_type', template='mdtui/indexing.html'):
"""Indexing step: Edit. Editing document type (in fact document rename)
@param request: is a Django request object
@param code: is a DMS Object() code for view interactions
@param step: is a current step name (for template rendering)
@param template: is a name of template for this view"""
context = {}
warnings = [MDTUI_ERROR_STRINGS['EDIT_TYPE_WARNING'], ]
error_warnings = []
form = False
processor = DocumentProcessor()
return_url = reverse('mdtui-edit', kwargs={'code': code})
log.debug('indexing_edit_type view called with code: %s' % code)
doc = processor.read(code, {'user': request.user, })
if not processor.errors:
empty_form = make_document_type_select_form(request.user, docrule_initial=doc.get_docrule())
form = empty_form(request.POST or None)
if request.POST:
if form.is_valid():
docrule = form.cleaned_data['docrule']
current_docrule = doc.get_docrule()
if not docrule == current_docrule:
options = {
'user': request.user,
'new_type': docrule,
}
doc = processor.update(code, options)
if not processor.errors:
return HttpResponseRedirect(reverse('mdtui-edit', kwargs={'code': doc.get_filename()}))
else:
warnings = [MDTUI_ERROR_STRINGS['EDIT_TYPE_ERROR'], ]
# Can cause errors in two places here (on doc read and update)
if processor.errors:
for error in processor.errors:
error_warnings.append(error)
context.update({
'step': step,
'doc_name': code,
'docrule': doc.get_docrule(),
'warnings': warnings,
'form': form,
'type_edit_return': return_url,
'error_warnings': error_warnings,
})
return render(request, template, context)
示例11: edit
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def edit(request, code, step='edit', template='mdtui/indexing.html'):
"""Indexing step: Edit. Made for editing indexes of document that is indexed already.
@param request: is a Django request object
@param code: is a DMS Object() code for view interactions
@param step: is a current step name (for template rendering)
@param template: is a name of template for this view"""
context = {}
warnings = []
error_warnings = []
form = False
processor = DocumentProcessor()
autocomplete_list = None
changed_indexes = None
# Storing cancel (return back from edit) url
try:
return_url = request.session['edit_return']
except KeyError:
try:
return_url = request.META['HTTP_REFERER']
request.session['edit_return'] = return_url
except KeyError:
return_url = '/'
pass
pass
# Only preserve indexes if returning from edit indexes confirmation step
if 'HTTP_REFERER' in request.META and request.META['HTTP_REFERER'].endswith(reverse('mdtui-edit-finished')):
try:
changed_indexes = request.session['edit_processor_indexes']
except KeyError:
pass
log.debug('indexing_edit view called with return_url: %s, changed_indexes: %s' % (return_url, changed_indexes))
doc = processor.read(code, {'user': request.user, 'only_metadata': True})
if not processor.errors and not doc.marked_deleted:
if not request.POST:
form = initEditIndexesForm(request, doc, changed_indexes)
# Setting context variables required for autocomplete
docrule_id = str(doc.get_docrule().id)
request.session['indexing_docrule_id'] = docrule_id
request.session['edit_mdts'] = get_mdts_for_docrule(docrule_id)
else:
old_db_info = doc.get_db_info()
secondary_indexes = processEditDocumentIndexForm(request, doc)
request.session['edit_processor_indexes'] = secondary_indexes
request.session['edit_index_barcode'] = code
old_docs_indexes = {'description': old_db_info['description']}
for index_name, index_value in old_db_info['mdt_indexes'].iteritems():
# Converting Old index dates to render according to DMS date format
if index_value.__class__.__name__ == 'datetime':
old_docs_indexes[index_name] = datetime.datetime.strftime(index_value, settings.DATE_FORMAT)
else:
old_docs_indexes[index_name] = index_value
request.session['old_document_keys'] = old_docs_indexes
return HttpResponseRedirect(reverse('mdtui-edit-finished'))
else:
for error in processor.errors:
# Intercepting type Exception and using it's message or using error.__str__
if not error.__class__.__name__ == 'unicode' and 'parameter' in error.__dict__.iterkeys():
error_warnings.append(error.parameter)
else:
error_warnings.append(error)
if doc.marked_deleted:
error_warnings.append(MDTUI_ERROR_STRINGS['NO_DOC'])
if form:
autocomplete_list = extract_secondary_keys_from_form(form)
# No form is possible when document does not exist
context.update({'form': form, })
# In case of no doc type (empty document) fix
type_name = None
if doc.docrule:
type_name = doc.get_docrule().title
context.update({
'step': step,
'doc_name': code,
'type_name': type_name,
'warnings': warnings,
'autocomplete_fields': autocomplete_list,
'edit_return': return_url,
'error_warnings': error_warnings,
})
return render(request, template, context)
示例12: store
# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import read [as 别名]
def store(self, document):
"""Stores CouchDB object into DB.
(Updates or overwrites CouchDB document)
@param document: is a DMS Document() instance
"""
# FIXME: Refactor me. We should upload new "secondary_indexes" or metatags with update() workflow,
# not a create(), like it is now. Because this method is a mess.
docrule = document.get_docrule()
# doing nothing for no docrule documents
if docrule.uncategorized:
return document
else:
user = self.check_user(document)
processor = DocumentProcessor()
# FIXME: there might be more than one mapping
mapping = docrule.get_docrule_plugin_mappings()
# doing nothing for documents without mapping has DB plugins
if not mapping.get_database_storage_plugins():
return document
else:
# if not exists all required metadata getting them from docrule retrieve sequence
if not document.file_revision_data:
# HACK: Preserving db_info here... (May be Solution!!!)
db_info = document.get_db_info()
document = processor.read(document.file_name, options={
'only_metadata': True,
'user': document.user
})
# saving NEW file_revision_data ONLY if they exist in new uploaded doc (Preserving old indexes)
if db_info:
# Storing new indexes
document.set_db_info(db_info)
else:
# TODO: move this code into a proper place (UPDATE method)
# Asking couchdb about if old file_revision_data exists and updating them properly
current_revisions = document.file_revision_data
try:
# Only if document exists in DB. Falling gracefully if not.
temp_doc = self.retrieve(document)
old_metadata = temp_doc.get_db_info()
old_index_revisions = None
if old_metadata['mdt_indexes']:
# Preserving Description, User, Created Date, indexes revisions
if temp_doc.index_revisions:
old_index_revisions = temp_doc.index_revisions
old_metadata['mdt_indexes']['description'] = old_metadata['description']
old_metadata['mdt_indexes']['metadata_user_name'] = old_metadata['metadata_user_name']
old_metadata['mdt_indexes']['metadata_user_id'] = old_metadata['metadata_user_id']
old_cr_date = datetime.datetime.strftime(
old_metadata['metadata_created_date'],
settings.DATE_FORMAT
)
old_metadata['mdt_indexes']['date'] = old_cr_date
document.set_db_info(old_metadata['mdt_indexes'])
document.set_index_revisions(old_index_revisions)
document.set_file_revisions_data(current_revisions)
else:
# Preserving set revisions anyway.
document.set_file_revisions_data(current_revisions)
except ResourceNotFound:
pass
# updating tags to sync with Django DB
self.sync_document_tags(document)
# assuming no document with this _id exists. SAVING or overwriting existing
couchdoc = CouchDocument()
couchdoc.populate_from_dms(user, document)
couchdoc.save(force_update=True)
return document