コード例 #1
0
ファイル: handlers.py プロジェクト: opendream/openkala
    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
コード例 #2
0
ファイル: handlers.py プロジェクト: opendream/openkala
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})
コード例 #3
0
ファイル: handlers.py プロジェクト: opendream/openkala
    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
コード例 #4
0
ファイル: handlers.py プロジェクト: opendream/openkala
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
        })
コード例 #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
コード例 #6
0
ファイル: __init__.py プロジェクト: opendream/openkala
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