def perform_request_update_record(requestType, uid, data):
    """Handle record update requests for actions on a field level.
    Handle merging, adding, or replacing of fields.
    """
    result = {
        'resultCode': 0,
        'resultText': ''
        }
    recid1 = data["recID1"]
    recid2 = data["recID2"]
    record_content = get_cache_file_contents(recid1, uid)
    cache_dirty = record_content[0]
    rec_revision = record_content[1]
    record1 = record_content[2]
    pending_changes = record_content[3]
    disabled_hp_changes = record_content[4]

    mode = data['record2Mode']
    record2 = _get_record_slave(recid2, result, mode, uid)
    if result['resultCode'] != 0: #if record not accessible return error information
        return result

    if requestType == 'getFieldGroup':
        result['resultHtml'] = bibmerge_templates.BM_html_field_group(record1, record2, data['fieldTag'])
        result['resultText'] = 'Field group retrieved'
        return result
    elif requestType == 'getFieldGroupDiff':
        result['resultHtml'] = bibmerge_templates.BM_html_field_group(record1, record2, data['fieldTag'], True)
        result['resultText'] = 'Fields compared'
        return result
    elif requestType == 'mergeFieldGroup' or requestType == 'mergeNCFieldGroup':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        if requestType == 'mergeNCFieldGroup':
            merge_field_group(record1, record2, fnum, ind1, ind2, False)
        else:
            merge_field_group(record1, record2, fnum, ind1, ind2, True)
        resultText = 'Field group merged'

    elif requestType == 'replaceField' or requestType == 'addField':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        findex1 = _field_info( data['fieldCode1'] )[1]
        findex2 = _field_info( data['fieldCode2'] )[1]
        if findex2 == None:
            result['resultCode'], result['resultText'] = 1, 'No value in the selected field'
            return result
        if requestType == 'replaceField':
            replace_field(record1, record2, fnum, findex1, findex2)
            resultText = 'Field replaced'
        else: # requestType == 'addField'
            add_field(record1, record2, fnum, findex1, findex2)
            resultText = 'Field added'

    elif requestType == 'deleteField':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        findex1 = _field_info( data['fieldCode1'] )[1]
        if findex1 == None:
            result['resultCode'], result['resultText'] = 1, 'No value in the selected field'
            return result
        delete_field(record1, fnum, findex1)
        resultText = 'Field deleted'

    elif requestType == 'mergeField':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        findex1 = _field_info( data['fieldCode1'] )[1]
        findex2 = _field_info( data['fieldCode2'] )[1]
        if findex2 == None:
            result['resultCode'], result['resultText'] = 1, 'No value in the selected field'
            return result
        merge_field(record1, record2, fnum, findex1, findex2)
        resultText = 'Field merged'

    else:
        result['resultCode'], result['resultText'] = 1, 'Wrong request type'
        return result

    result['resultHtml'] = bibmerge_templates.BM_html_field_group(record1, record2, data['fieldTag'])
    result['resultText'] = resultText
    update_cache_file_contents(recid1, uid, rec_revision, record1, pending_changes, disabled_hp_changes )
    return result
def perform_request_update_record(requestType, uid, data):
    """Handle record update requests for actions on a field level.
    Handle merging, adding, or replacing of fields.
    """
    result = {'resultCode': 0, 'resultText': ''}
    recid1 = data["recID1"]
    recid2 = data["recID2"]
    record_content = get_cache_file_contents(recid1, uid)
    cache_dirty = record_content[0]
    rec_revision = record_content[1]
    record1 = record_content[2]
    pending_changes = record_content[3]
    disabled_hp_changes = record_content[4]
    # We will not be able to Undo/Redo correctly after any modifications
    # from the level of bibmerge are performed ! We clear all the undo/redo
    # lists
    undo_list = []
    redo_list = []

    mode = data['record2Mode']
    record2 = _get_record_slave(recid2, result, mode, uid)
    if result[
            'resultCode'] != 0:  #if record not accessible return error information
        return result

    if requestType == 'getFieldGroup':
        result['resultHtml'] = bibmerge_templates.BM_html_field_group(
            record1, record2, data['fieldTag'])
        result['resultText'] = 'Field group retrieved'
        return result
    elif requestType == 'getFieldGroupDiff':
        result['resultHtml'] = bibmerge_templates.BM_html_field_group(
            record1, record2, data['fieldTag'], True)
        result['resultText'] = 'Fields compared'
        return result
    elif requestType == 'mergeFieldGroup' or requestType == 'mergeNCFieldGroup':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        if requestType == 'mergeNCFieldGroup':
            merge_field_group(record1, record2, fnum, ind1, ind2, False)
        else:
            merge_field_group(record1, record2, fnum, ind1, ind2, True)
        resultText = 'Field group merged'

    elif requestType == 'replaceField' or requestType == 'addField':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        findex1 = _field_info(data['fieldCode1'])[1]
        findex2 = _field_info(data['fieldCode2'])[1]
        if findex2 == None:
            result['resultCode'], result[
                'resultText'] = 1, 'No value in the selected field'
            return result
        if requestType == 'replaceField':
            replace_field(record1, record2, fnum, findex1, findex2)
            resultText = 'Field replaced'
        else:  # requestType == 'addField'
            add_field(record1, record2, fnum, findex1, findex2)
            resultText = 'Field added'

    elif requestType == 'deleteField':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        findex1 = _field_info(data['fieldCode1'])[1]
        if findex1 == None:
            result['resultCode'], result[
                'resultText'] = 1, 'No value in the selected field'
            return result
        delete_field(record1, fnum, findex1)
        resultText = 'Field deleted'

    elif requestType == 'mergeField':
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data['fieldTag'])
        findex1 = _field_info(data['fieldCode1'])[1]
        findex2 = _field_info(data['fieldCode2'])[1]
        if findex2 == None:
            result['resultCode'], result[
                'resultText'] = 1, 'No value in the selected field'
            return result
        merge_field(record1, record2, fnum, findex1, findex2)
        resultText = 'Field merged'

    else:
        result['resultCode'], result['resultText'] = 1, 'Wrong request type'
        return result

    result['resultHtml'] = bibmerge_templates.BM_html_field_group(
        record1, record2, data['fieldTag'])
    result['resultText'] = resultText
    update_cache_file_contents(recid1, uid, rec_revision, record1,
                               pending_changes, disabled_hp_changes, undo_list,
                               redo_list)
    return result
Esempio n. 3
0
def perform_request_update_record(requestType, uid, data):
    """Handle record update requests for actions on a field level.
    Handle merging, adding, or replacing of fields.
    """
    result = {"resultCode": 0, "resultText": ""}
    recid1 = data["recID1"]
    recid2 = data["recID2"]
    record_content = get_cache_file_contents(recid1, uid)
    cache_dirty = record_content[0]
    rec_revision = record_content[1]
    record1 = record_content[2]
    pending_changes = record_content[3]
    disabled_hp_changes = record_content[4]
    # We will not be able to Undo/Redo correctly after any modifications
    # from the level of bibmerge are performed ! We clear all the undo/redo
    # lists
    undo_list = []
    redo_list = []

    mode = data["record2Mode"]
    record2 = _get_record_slave(recid2, result, mode, uid)
    if result["resultCode"] != 0:  # if record not accessible return error information
        return result

    if requestType == "getFieldGroup":
        result["resultHtml"] = bibmerge_templates.BM_html_field_group(record1, record2, data["fieldTag"])
        result["resultText"] = "Field group retrieved"
        return result
    elif requestType == "getFieldGroupDiff":
        result["resultHtml"] = bibmerge_templates.BM_html_field_group(record1, record2, data["fieldTag"], True)
        result["resultText"] = "Fields compared"
        return result
    elif requestType == "mergeFieldGroup" or requestType == "mergeNCFieldGroup":
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data["fieldTag"])
        if requestType == "mergeNCFieldGroup":
            merge_field_group(record1, record2, fnum, ind1, ind2, False)
        else:
            merge_field_group(record1, record2, fnum, ind1, ind2, True)
        resultText = "Field group merged"

    elif requestType == "replaceField" or requestType == "addField":
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data["fieldTag"])
        findex1 = _field_info(data["fieldCode1"])[1]
        findex2 = _field_info(data["fieldCode2"])[1]
        if findex2 == None:
            result["resultCode"], result["resultText"] = 1, "No value in the selected field"
            return result
        if requestType == "replaceField":
            replace_field(record1, record2, fnum, findex1, findex2)
            resultText = "Field replaced"
        else:  # requestType == 'addField'
            add_field(record1, record2, fnum, findex1, findex2)
            resultText = "Field added"

    elif requestType == "deleteField":
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data["fieldTag"])
        findex1 = _field_info(data["fieldCode1"])[1]
        if findex1 == None:
            result["resultCode"], result["resultText"] = 1, "No value in the selected field"
            return result
        delete_field(record1, fnum, findex1)
        resultText = "Field deleted"

    elif requestType == "mergeField":
        fnum, ind1, ind2 = _fieldtagNum_and_indicators(data["fieldTag"])
        findex1 = _field_info(data["fieldCode1"])[1]
        findex2 = _field_info(data["fieldCode2"])[1]
        if findex2 == None:
            result["resultCode"], result["resultText"] = 1, "No value in the selected field"
            return result
        merge_field(record1, record2, fnum, findex1, findex2)
        resultText = "Field merged"

    else:
        result["resultCode"], result["resultText"] = 1, "Wrong request type"
        return result

    result["resultHtml"] = bibmerge_templates.BM_html_field_group(record1, record2, data["fieldTag"])
    result["resultText"] = resultText
    update_cache_file_contents(
        recid1, uid, rec_revision, record1, pending_changes, disabled_hp_changes, undo_list, redo_list
    )
    return result