Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def edit_file_revisions(request,
                        code,
                        step='edit_revisions',
                        template='mdtui/indexing.html'):
    """Editing file revisions for given code

    @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"""
    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 not db_info:
        errors = [
            MDTUI_ERROR_STRINGS['NO_DOC'] +
            '. Maybe you should go index it first?'
        ]
    elif 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)
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
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))