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


Python DocumentProcessor.create方法代码示例

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


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

示例1: upload

# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import create [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)
开发者ID:acrooo,项目名称:Adlibre-DMS,代码行数:36,代码来源:views.py

示例2: post

# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import create [as 别名]
 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,代码行数:28,代码来源:views.py

示例3: handle

# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import create [as 别名]
    def handle(self, *args, **options):
        """Main method processor

        @param args: directory_name directory_name ...
        @param options:
        """

        silent = "silent" in options.keys() and options["silent"]
        if len(args) == 0:
            self.stdout.write("No arguments specified\n")
            return

        for directory in args:
            if not os.path.exists(directory):
                self.stderr.write("Could not import %s: no such directory\n" % directory)
                continue
            cnt = 0
            admin = User.objects.filter(is_superuser=True)[0]
            for root, dirs, files in os.walk(directory):
                if ".svn" in dirs:
                    dirs.remove(".svn")  # don't visit svn directories
                for filename in files:
                    if not silent:
                        self.stdout.write('Importing file: "%s"\n' % filename)
                    file_obj = open(os.path.join(root, filename))
                    file_obj.seek(0)
                    processor = DocumentProcessor()
                    try:
                        processor.create(file_obj, {"user": admin})
                    except Exception, e:
                        self.stderr.write(str(e))
                        self.stderr.write(traceback.format_exc() + "\n")
                    else:
                        if processor.errors:
                            self.stderr.write("\nImport error: %s\n" % processor.errors)
                        else:
                            cnt += 1
                    file_obj.close()
            if not silent:
                if cnt:
                    self.stdout.write('Successfully imported %s documents from directory "%s"\n' % (cnt, directory))
                else:
                    self.stdout.write("No documents were imported\n")
开发者ID:purbohadi,项目名称:Adlibre-DMS,代码行数:45,代码来源:import_documents.py

示例4: create

# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import create [as 别名]
 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,代码行数:18,代码来源:handlers.py

示例5: indexing_source

# 需要导入模块: from core.document_processor import DocumentProcessor [as 别名]
# 或者: from core.document_processor.DocumentProcessor import create [as 别名]
def indexing_source(request, step=None, template='mdtui/indexing.html'):
    """Indexing: Step 3: Upload File / Associate File / Print Barcode

    @param request: is a Django request object
    @param step: is a current step name (for template rendering)
    @param template: is a name of template for this view"""
    context = {}
    warnings = []
    valid_call = True
    temp_vars = {}
    upload_file = None
    # Check session variables, init context and add proper user warnings
    for var_name, context_var, action in [
        ('document_keys', "document_keys_dict", 'NO_INDEX'),
        ('barcode', 'barcode', 'NO_INDEX'),
        ('index_info', 'document_keys_dict', 'NO_S_KEYS'),
        ('docrule', 'indexing_docrule_id', 'NO_DOCRULE'),
    ]:
        try:
            temp_vars[var_name] = None  # Make sure it will definitely be there (Proper init)
            temp_var = request.session[context_var]
            temp_vars[var_name] = temp_var
        except KeyError:
            valid_call = False
            if not MDTUI_ERROR_STRINGS[action] in warnings:
                warnings.append(MDTUI_ERROR_STRINGS[action])
    document_keys = temp_vars['document_keys']
    barcode = temp_vars['barcode']
    index_info = temp_vars['index_info']
    docrule = str(temp_vars['docrule'])

    # Init Forms correctly depending on url posted
    if request.GET.get('uploaded') is None:
        upload_form = DocumentUploadForm()
    else:
        upload_form = DocumentUploadForm(request.POST or None, request.FILES or None)

    if request.GET.get('barcoded') is None:
        barcode_form = BarcodePrintedForm()
    else:
        barcode_form = BarcodePrintedForm(request.POST or None)

    log.debug('indexing_source view called with document_keys: %s, barcode: %s, index_info: %s, docrule: %s' %
              (document_keys, barcode, index_info, docrule))
    # Appending warnings for creating a new parrallel key/value pair.
    new_sec_key_pairs = check_for_secondary_keys_pairs(index_info, docrule)
    if new_sec_key_pairs:
        for new_key, new_value in new_sec_key_pairs.iteritems():
            warnings.append(MDTUI_ERROR_STRINGS['NEW_KEY_VALUE_PAIR'] + new_key + ': ' + new_value)

    if upload_form.is_valid() or barcode_form.is_valid() and valid_call:
        if valid_call:
            # Unifying dates to CouchDB storage formats.
            # TODO: maybe make it a part of the CouchDB storing manager.
            clean_index = unify_index_info_couch_dates_fmt(index_info)

            # Storing into DMS with main Document Processor and current indexes
            processor = DocumentProcessor()
            options = {
                'user': request.user,
                'index_info': clean_index,
                'barcode': barcode,
            }
            if upload_form.is_valid():
                upload_file = upload_form.files['file']
            else:
                options['only_metadata'] = True
            processor.create(upload_file, options)

            if not processor.errors:
                if 'only_metadata' in options and options['only_metadata'] is not None:
                    # For silent barcode storage in MUI
                    return HttpResponse('OK')
                return HttpResponseRedirect(reverse('mdtui-index-finished'))
            else:
                # FIXME: dodgy error handling
                log.error(str(processor.errors))
                return HttpResponse(str(processor.errors))
        else:
            warnings.append(MDTUI_ERROR_STRINGS['NOT_VALID_INDEXING'])

    context.update({
        'step': step,
        'valid_call': valid_call,
        'upload_form': upload_form,
        'barcode_form': barcode_form,
        'document_keys': document_keys,
        'warnings': warnings,
        'barcode': barcode,
    })
    return render_to_response(template, context, context_instance=RequestContext(request))
开发者ID:egon0,项目名称:Adlibre-DMS,代码行数:93,代码来源:views.py


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