Exemplo n.º 1
0
    def read(self, request, project_id, old_id, diff_id):

        project_id, old_id, diff_id = [int(project_id), int(old_id), int(diff_id)]
        
        dmp = diff_match_patch()

        old = utility.prev_point_text(project_id, old_id)

        if diff_id:
            diff = utility.prev_point_text(project_id, diff_id)
        else:
            diff = utility.get_current_text(project_id, old.keys())

        result = {}
        for cell, html in old.iteritems():
            if cell in diff:
                d  = dmp.diff_main(html, diff[cell])
                #dmp.diff_cleanupEfficiency(d) # Suck
                dmp.diff_cleanupSemantic(d) # Damn it
                html = dmp.diff_prettyHtml(d)
                
                # I don't know why dmp replace this char
                html = html.replace("&amp;", "&").replace("&lt;", "<").replace("&gt;", ">").replace("&para;<br>", "\n").replace("<br>", "\n").replace("<br/>", "\n").replace("<br />", "\n")

                result[cell] = html

        return result
Exemplo n.º 2
0
def insertProjectHistory(project, cell, new_value, model, id, field, user): 
    current_value = getattr(model.objects.get(id=id), field)

    if current_value == None:
        current_value = ''
    elif type(current_value) == int:
        current_value = str(current_value)

    if new_value == None:
        new_value = ''
    elif type(new_value) == int:
        new_value = str(new_value)

    if new_value != current_value:
        dmp = diff_match_patch()
        patches = dmp.patch_make(new_value, current_value)
        project_history = ProjectHistory(project=project, cell=cell, patch=dmp.patch_toText(patches), user=user)
        project_history.save()
        # This is a bug
        if ProjectHistory.objects.filter(project=project).count() > 1:
            project_history.before = project_history.get_previous_by_datetime(project=project)
        else:
            project_history.before = {'id': 0}

        return render_to_string('history_item.html', {'project_id': project.id, 'history': project_history, 'is_new': True})
Exemplo n.º 3
0
    def read(self, request, project_id, old_id, diff_id):

        project_id, old_id, diff_id = [
            int(project_id), int(old_id),
            int(diff_id)
        ]

        dmp = diff_match_patch()

        old = utility.prev_point_text(project_id, old_id)

        if diff_id:
            diff = utility.prev_point_text(project_id, diff_id)
        else:
            diff = utility.get_current_text(project_id, old.keys())

        result = {}
        for cell, html in old.iteritems():
            if cell in diff:
                d = dmp.diff_main(html, diff[cell])
                #dmp.diff_cleanupEfficiency(d) # Suck
                dmp.diff_cleanupSemantic(d)  # Damn it
                html = dmp.diff_prettyHtml(d)

                # I don't know why dmp replace this char
                html = html.replace("&amp;", "&").replace("&lt;", "<").replace(
                    "&gt;", ">").replace("&para;<br>", "\n").replace(
                        "<br>", "\n").replace("<br/>",
                                              "\n").replace("<br />", "\n")

                result[cell] = html

        return result
Exemplo n.º 4
0
def insertProjectHistory(project, cell, new_value, model, id, field, user):
    current_value = getattr(model.objects.get(id=id), field)

    if current_value == None:
        current_value = ''
    elif type(current_value) == int:
        current_value = str(current_value)

    if new_value == None:
        new_value = ''
    elif type(new_value) == int:
        new_value = str(new_value)

    if new_value != current_value:
        dmp = diff_match_patch()
        patches = dmp.patch_make(new_value, current_value)
        project_history = ProjectHistory(project=project,
                                         cell=cell,
                                         patch=dmp.patch_toText(patches),
                                         user=user)
        project_history.save()
        # This is a bug
        if ProjectHistory.objects.filter(project=project).count() > 1:
            project_history.before = project_history.get_previous_by_datetime(
                project=project)
        else:
            project_history.before = {'id': 0}

        return render_to_string('history_item.html', {
            'project_id': project.id,
            'history': project_history,
            'is_new': True
        })
Exemplo n.º 5
0
def prev_point_text(project_id, history_id):
    dmp = diff_match_patch()
    histories = ProjectHistory.objects.filter(project__id=project_id, id__gte=history_id).order_by('-id')

    pre = {}
    for history in histories:
        cell = history.cell
        if not pre.get(cell):
            pre[cell] = []

        pre[cell].append(dmp.patch_fromText(history.patch)[0])

    result = {}
    for cell, patches in pre.iteritems():
        result[cell] = dmp.patch_apply(patches, get_field_from_cell(project_id, cell))[0]

    return result
Exemplo n.º 6
0
def prev_point_text(project_id, history_id):
    dmp = diff_match_patch()
    histories = ProjectHistory.objects.filter(
        project__id=project_id, id__gte=history_id).order_by('-id')

    pre = {}
    for history in histories:
        cell = history.cell
        if not pre.get(cell):
            pre[cell] = []

        pre[cell].append(dmp.patch_fromText(history.patch)[0])

    result = {}
    for cell, patches in pre.iteritems():
        result[cell] = dmp.patch_apply(patches,
                                       get_field_from_cell(project_id,
                                                           cell))[0]

    return result