def perform_small_request_update_record(requestType, uid, data):
    """Handle record update requests for actions on a subfield level.
    Handle adding, replacing or deleting of subfields.
    """
    result = {'resultCode': 0, 'resultText': '', 'resultHtml': ''}
    recid1 = data["recID1"]
    recid2 = data["recID2"]
    cache_content = get_cache_file_contents(recid1,
                                            uid)  #TODO: check mtime, existence
    cache_dirty = cache_content[0]
    rec_revision = cache_content[1]
    record1 = cache_content[2]
    pending_changes = cache_content[3]
    disabled_hp_changes = cache_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

    ftag, findex1 = _field_info(data['fieldCode1'])
    fnum = ftag[:3]
    findex2 = _field_info(data['fieldCode2'])[1]
    sfindex1 = data['sfindex1']
    sfindex2 = data['sfindex2']

    if requestType == 'deleteSubfield':
        delete_subfield(record1, fnum, findex1, sfindex1)
        result['resultText'] = 'Subfield deleted'
    elif requestType == 'addSubfield':
        add_subfield(record1, record2, fnum, findex1, findex2, sfindex1,
                     sfindex2)
        result['resultText'] = 'Subfield added'
    elif requestType == 'replaceSubfield':
        replace_subfield(record1, record2, fnum, findex1, findex2, sfindex1,
                         sfindex2)
        result['resultText'] = 'Subfield replaced'
    elif requestType == 'diffSubfield':
        result['resultHtml'] = bibmerge_templates.BM_html_subfield_row_diffed(
            record1, record2, fnum, findex1, findex2, sfindex1, sfindex2)
        result['resultText'] = 'Subfields diffed'

    update_cache_file_contents(recid1, uid, rec_revision, record1,
                               pending_changes, disabled_hp_changes, [], [])
    return result
def perform_small_request_update_record(requestType, uid, data):
    """Handle record update requests for actions on a subfield level.
    Handle adding, replacing or deleting of subfields.
    """
    result = {
        'resultCode': 0,
        'resultText': '',
        'resultHtml': ''
        }
    recid1 = data["recID1"]
    recid2 = data["recID2"]
    cache_content = get_cache_file_contents(recid1, uid) #TODO: check mtime, existence
    cache_dirty = cache_content[0]
    rec_revision = cache_content[1] 
    record1 = cache_content[2]
    pending_changes = cache_content[3]
    disabled_hp_changes = cache_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

    ftag, findex1 = _field_info(data['fieldCode1'])
    fnum = ftag[:3]
    findex2 = _field_info(data['fieldCode2'])[1]
    sfindex1 = data['sfindex1']
    sfindex2 = data['sfindex2']

    if requestType == 'deleteSubfield':
        delete_subfield(record1, fnum, findex1, sfindex1)
        result['resultText'] = 'Subfield deleted'
    elif requestType == 'addSubfield':
        add_subfield(record1, record2, fnum, findex1, findex2, sfindex1, sfindex2)
        result['resultText'] = 'Subfield added'
    elif requestType == 'replaceSubfield':
        replace_subfield(record1, record2, fnum, findex1, findex2, sfindex1, sfindex2)
        result['resultText'] = 'Subfield replaced'
    elif requestType == 'diffSubfield':
        result['resultHtml'] = bibmerge_templates.BM_html_subfield_row_diffed(record1, record2, fnum, findex1, findex2, sfindex1, sfindex2)
        result['resultText'] = 'Subfields diffed'

    update_cache_file_contents(recid1, uid, rec_revision, record1, pending_changes, disabled_hp_changes)
    return result