当前位置: 首页>>代码示例>>Python>>正文


Python document_processor.DocumentProcessor类代码示例

本文整理汇总了Python中core.document_processor.DocumentProcessor的典型用法代码示例。如果您正苦于以下问题:Python DocumentProcessor类的具体用法?Python DocumentProcessor怎么用?Python DocumentProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DocumentProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit_file_revisions

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)
开发者ID:garmoncheg,项目名称:Adlibre-DMS,代码行数:35,代码来源:views.py

示例2: read

 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)
开发者ID:egon0,项目名称:Adlibre-DMS,代码行数:26,代码来源:handlers.py

示例3: view_object

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)
开发者ID:egon0,项目名称:Adlibre-DMS,代码行数:28,代码来源:views.py

示例4: edit_file_delete

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)
开发者ID:egon0,项目名称:Adlibre-DMS,代码行数:28,代码来源:views.py

示例5: read

 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
开发者ID:garmoncheg,项目名称:Adlibre-DMS,代码行数:25,代码来源:handlers.py

示例6: get

 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)
开发者ID:acrooo,项目名称:Adlibre-DMS,代码行数:33,代码来源:views.py

示例7: post

 def post(self, request, code, suggested_format=None):
     if 'file' in request.FILES:
         uploaded_file = request.FILES['file']
     else:
         return Response(status=status.HTTP_400_BAD_REQUEST)
     processor = DocumentProcessor()
     options = {
         'user': request.user,
         'barcode': code,
     }
     if uploaded_file.size == 0:
         return Response(status=status.HTTP_400_BAD_REQUEST)
     document = processor.create(uploaded_file, options)
     if len(processor.errors) > 0:
         log.error('OldFileHandler.create errors: %s' % processor.errors)
         error = processor.errors[0]
         if error.__class__.__name__ in ['unicode', 'str']:
             return Response(status=status.HTTP_400_BAD_REQUEST)
         if error.code == 409:
             new_processor = DocumentProcessor()
             options['update_file'] = uploaded_file
             document = new_processor.update(code, options)
             if len(new_processor.errors) > 0:
                 return Response(status=status.HTTP_400_BAD_REQUEST)
     log.info('OldFileHandler.create request fulfilled for %s' % document.get_filename())
     return Response(document.get_filename(), status=status.HTTP_200_OK)
开发者ID:acrooo,项目名称:Adlibre-DMS,代码行数:26,代码来源:views.py

示例8: put

    def put(self, request, code, suggested_format=None):
        """Used to work with "update" sequence of DMS code.

        to update a code you need to send a PUT request here.
        PUT must contain:

        @param code: the DMS "code" of file to be updated. e.g.: ADL-0001
        @param suggested_format: format of file for code to be updated. To have ability to post files in certain format.
        """
        context = {'request': request}
        conten_type = request.content_type
        uploaded_obj = None
        if 'multipart/form-data' in conten_type:
            # We have a file upload encoded with multipart/form-data
            file_content = StringIO(request.body)
            parser = MultiPartParser()
            dnf = parser.parse(file_content, media_type=conten_type, parser_context=context)
            extra = dnf.data
            if 'file' in dnf.files:
                uploaded_obj = dnf.files['file']
        else:
            extra = request.QUERY_PARAMS
        # TODO: do we require SQL tagging logic in this API call?
        sql_tag_string = extra.get('tag_string', None)
        sql_remove_tag_string = extra.get('remove_tag_string', None)
        new_name = extra.get('new_name', None)
        new_type = extra.get('new_type', None)
        index_data = extra.get('indexing_data', None)
        if index_data:
            index_data = json.loads(index_data)
        processor = DocumentProcessor()
        options = {
            'tag_string': sql_tag_string,
            'remove_tag_string': sql_remove_tag_string,
            'extension': suggested_format,
            'new_name': new_name,
            'new_type': new_type,
            'new_indexes': index_data,
            'update_file': uploaded_obj,
            'user': request.user,
        }
        document = processor.update(code, options)
        if len(processor.errors) > 0:
            log.error('FileHandler.update manager errors %s' % processor.errors)
            if settings.DEBUG:
                print processor.errors
                raise Exception('FileHandler.update manager errors')
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)
        log.info('FileHandler.update request fulfilled for code: %s, extension: %s'
                 % (code, suggested_format))
        resp = DMSOBjectRevisionsData(document).data
        return Response(resp, status=status.HTTP_200_OK)
开发者ID:acrooo,项目名称:Adlibre-DMS,代码行数:53,代码来源:views.py

示例9: edit_result

def edit_result(request, step='edit_finish', template='mdtui/indexing.html'):
    """Confirmation step for editing indexes"""
    # initialising context
    required_vars = ('edit_processor_indexes', 'edit_index_barcode', 'old_document_keys', 'edit_return', "edit_mdts")
    variables = {}
    warnings = []
    for var in required_vars:
        try:
            variables[var] = request.session[var]
        except KeyError:
            variables[var] = ''
            # Error handling into warnings
            if not var == 'edit_return':
                error_name = MDTUI_ERROR_STRINGS['ERROR_EDIT_INDEXES_FINISHED']
                log.error('indexing_finished error: variable: %s,  %s' % (var, error_name))
                if not error_name in warnings:
                    warnings.append(error_name)
            pass
    log.debug('indexing_edit_result called with: step: "%s", variables: "%s",' % (step, variables))

    if request.POST:
        code = variables['edit_index_barcode']
        processor = DocumentProcessor()
        options = {
            'new_indexes': variables['edit_processor_indexes'],
            'user': request.user,
        }
        processor.update(code, options=options)
        if not processor.errors:
            # cleanup session here because editing is finished
            for var in required_vars:
                _cleanup_session_var(request, var)
            return HttpResponseRedirect(variables['edit_return'])
        else:
            for error in processor.errors:
                warnings.append(error)
    # Building new indexes for confirmation rendering
    context_secondary_indexes = {}
    if 'edit_processor_indexes' in variables.iterkeys() and variables['edit_processor_indexes']:
        for index, value in variables['edit_processor_indexes'].iteritems():
            if not index in ['metadata_user_name', 'metadata_user_id']:
                context_secondary_indexes[index] = value
    context = {
        'step': step,
        'document_keys': context_secondary_indexes,
        'barcode': variables['edit_index_barcode'],
        'old_document_keys': variables['old_document_keys'],
        'edit_return': variables['edit_return'],
        'warnings': warnings,
    }
    return render(request, template, context)
开发者ID:garmoncheg,项目名称:Adlibre-DMS,代码行数:51,代码来源:views.py

示例10: get_file

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
开发者ID:egon0,项目名称:Adlibre-DMS,代码行数:14,代码来源:views.py

示例11: revision_document

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)
开发者ID:acrooo,项目名称:Adlibre-DMS,代码行数:49,代码来源:views.py

示例12: delete

 def delete(self, request, code, suggested_format=None):
     # FIXME: should return 404 if file not found, 400 if no docrule exists.
     revision, hashcode, extra = self._get_info(request)
     processor = DocumentProcessor()
     options = {
         'revision': revision,
         'extension': suggested_format,
         'user': request.user,
     }
     log.debug('FileHandler.delete attempt with %s' % options)
     processor.delete(code, options)
     if len(processor.errors) > 0:
         log.error('Manager Errors encountered %s' % processor.errors)
         return rc.BAD_REQUEST
     log.info('FileHandler.delete request fulfilled for code: %s, format: %s, rev: %s, hash: %s.' % (code, suggested_format, revision, hashcode))
     return rc.DELETED
开发者ID:garmoncheg,项目名称:Adlibre-DMS,代码行数:16,代码来源:handlers.py

示例13: create

 def create(self, request, code, suggested_format=None):
     if 'file' in request.FILES:
         uploaded_file = request.FILES['file']
     else:
         return rc.BAD_REQUEST
     processor = DocumentProcessor()
     options = {
         'user': request.user,
         'barcode': code,
     }
     document = processor.create(uploaded_file, options)
     if len(processor.errors) > 0:
         log.error('FileHandler.create manager errors: %s' % processor.errors)
         return rc.BAD_REQUEST
     log.info('FileHandler.create request fulfilled for %s' % document.get_filename())
     return rc.CREATED
开发者ID:garmoncheg,项目名称:Adlibre-DMS,代码行数:16,代码来源:handlers.py

示例14: edit_type

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)
开发者ID:egon0,项目名称:Adlibre-DMS,代码行数:47,代码来源:views.py

示例15: upload

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)
开发者ID:acrooo,项目名称:Adlibre-DMS,代码行数:34,代码来源:views.py


注:本文中的core.document_processor.DocumentProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。