Esempio n. 1
0
def indexing_details(request, step=None, template='mdtui/indexing.html'):
    """Indexing: Step 2 : Index Details"""
    # Context init
    context = {}
    document_keys = None
    warnings = []
    errors = []
    cleanup_search_session(request)
    docrule_id = None

    try:
        docrule_id = request.session['indexing_docrule_id']
    except KeyError:
        warnings.append(MDTUI_ERROR_STRINGS['NO_DOCRULE'])

    try:
        document_keys = request.session["document_keys_dict"]
    except KeyError:
        pass

    log.debug('indexing_details view called with docrule_id: %s, document_keys: %s, warnings: %s' % (docrule_id, document_keys, warnings))
    if request.POST:
        secondary_indexes = processDocumentIndexForm(request)
        if secondary_indexes:
            request.session["document_keys_dict"] = secondary_indexes
            # Checking for forbidden keys and changing view behaviour if found
            forbidden_keys = check_for_forbidden_new_keys_created(secondary_indexes, docrule_id, request.user)
            if forbidden_keys:
                for forbidden_key in forbidden_keys:
                    if forbidden_key[1] == 'adminlock':
                        errors.append(MDTUI_ERROR_STRINGS['ADMINLOCKED_KEY_ATTEMPT'] + forbidden_key[0])
                    elif forbidden_key[1] == 'locked':
                        errors.append(MDTUI_ERROR_STRINGS['LOCKED_KEY_ATTEMPT'] + forbidden_key[0])
                # Reinitializing form
                form = initIndexesForm(request)
            else:
                # Success, allocate barcode and move on
                if "barcode" in request.session and request.session["barcode"]:
                    pass
                else:
                    dtr = DocumentTypeRule.objects.get(pk=docrule_id)
                    request.session["barcode"] = dtr.allocate_barcode()
                return HttpResponseRedirect(reverse('mdtui-index-source'))
        else:
            # Return validation with errors...
            form = initIndexesForm(request)
    else:
        form = initIndexesForm(request)

    autocomplete_list = extract_secondary_keys_from_form(form)

    context.update( { 'step': step,
                      'form': form,
                      'document_keys': document_keys,
                      'autocomplete_fields': autocomplete_list,
                      'warnings': warnings,
                      'error_warnings': errors,
                    })
    return render_to_response(template, context, context_instance=RequestContext(request))
Esempio n. 2
0
def search_options(request, step, template='mdtui/search.html'):
    """Search Step 2: Search Options

    @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"""
    warnings = []
    autocomplete_list = None
    mdt_id = None
    # Trying to get stuff we require OR warn user
    try:
        mdt_id = request.session['search_mdt_id']
    except KeyError:
        pass
    if not mdt_id:
        try:
            request.session['searching_docrule_id']
        except KeyError:
            warnings.append(MDTUI_ERROR_STRINGS['NO_MDTS'])

    # CouchDB connection Felt down warn user
    try:
        form = initIndexesForm(request)
        autocomplete_list = extract_secondary_keys_from_form(form)
    except (RequestError, AttributeError):
        form = DocumentSearchOptionsForm
        warnings.append(MDTUI_ERROR_STRINGS['NO_DB'])

    if request.POST:
        try:
            secondary_indexes = processDocumentIndexForm(request)
        except RequestError:
            secondary_indexes = None
            warnings.append(MDTUI_ERROR_STRINGS['NO_DB'])

        if secondary_indexes:
            request.session['document_search_dict'] = secondary_indexes
            return HttpResponseRedirect(reverse('mdtui-search-results'))

    context = {
        'form': form,
        'warnings': warnings,
        'step': step,
        'autocomplete_fields': autocomplete_list,
    }
    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))
Esempio n. 3
0
def search_options(request, step, template='mdtui/search.html'):
    """Search Step 2: Search Options

    @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"""
    warnings = []
    autocomplete_list = None
    mdt_id = None
    # Trying to get stuff we require OR warn user
    try:
        mdt_id = request.session['search_mdt_id']
    except KeyError:
        pass
    if not mdt_id:
        try:
            request.session['searching_docrule_id']
        except KeyError:
            warnings.append(MDTUI_ERROR_STRINGS['NO_MDTS'])

    # CouchDB connection Felt down warn user
    try:
        form = initIndexesForm(request)
        autocomplete_list = extract_secondary_keys_from_form(form)
    except (RequestError, AttributeError):
        form = DocumentSearchOptionsForm
        warnings.append(MDTUI_ERROR_STRINGS['NO_DB'])

    if request.POST:
        try:
            secondary_indexes = processDocumentIndexForm(request)
        except RequestError:
            secondary_indexes = None
            warnings.append(MDTUI_ERROR_STRINGS['NO_DB'])

        if secondary_indexes:
            request.session['document_search_dict'] = secondary_indexes
            return HttpResponseRedirect(reverse('mdtui-search-results'))

    context = {
        'form': form,
        'warnings': warnings,
        'step': step,
        'autocomplete_fields': autocomplete_list,
    }
    return render_to_response(template, context, context_instance=RequestContext(request))
Esempio n. 4
0
def indexing_details(request, step=None, template='mdtui/indexing.html'):
    """Indexing: Step 2 : Index Details

    @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 init
    context = {}
    document_keys = None
    warnings = []
    errors = []
    cleanup_search_session(request)
    docrule_id = None

    try:
        docrule_id = request.session['indexing_docrule_id']
    except KeyError:
        warnings.append(MDTUI_ERROR_STRINGS['NO_DOCRULE'])

    try:
        document_keys = request.session["document_keys_dict"]
    except KeyError:
        pass

    log.debug(
        'indexing_details view called with docrule_id: %s, document_keys: %s, warnings: %s'
        % (docrule_id, document_keys, warnings))
    if request.POST:
        secondary_indexes = processDocumentIndexForm(request)
        if secondary_indexes:
            request.session["document_keys_dict"] = secondary_indexes
            # Checking for forbidden keys and changing view behaviour if found
            forbidden_keys = check_for_forbidden_new_keys_created(
                secondary_indexes, docrule_id, request.user)
            if forbidden_keys:
                for forbidden_key in forbidden_keys:
                    if forbidden_key[1] == 'adminlock':
                        errors.append(
                            MDTUI_ERROR_STRINGS['ADMINLOCKED_KEY_ATTEMPT'] +
                            forbidden_key[0])
                    elif forbidden_key[1] == 'locked':
                        errors.append(
                            MDTUI_ERROR_STRINGS['LOCKED_KEY_ATTEMPT'] +
                            forbidden_key[0])
                # Reinitializing form
                form = initIndexesForm(request)
            else:
                # Success, allocate barcode and move on
                if "barcode" in request.session and request.session["barcode"]:
                    pass
                else:
                    if docrule_id:
                        dtr = DocumentTypeRule.objects.get(pk=docrule_id)
                        request.session["barcode"] = dtr.allocate_barcode()

                return HttpResponseRedirect(reverse('mdtui-index-source'))
        else:
            # Return validation with errors...
            form = initIndexesForm(request)
    else:
        form = initIndexesForm(request)

    autocomplete_list = extract_secondary_keys_from_form(form)

    context.update({
        'step': step,
        'form': form,
        'document_keys': document_keys,
        'autocomplete_fields': autocomplete_list,
        'warnings': warnings,
        'error_warnings': errors,
    })
    return render_to_response(template,
                              context,
                              context_instance=RequestContext(request))