-
Notifications
You must be signed in to change notification settings - Fork 490
Compare history versions #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9290db2
Added initial 'compare view' work
macro1 463aa07
Removed use of 'render_to_response' from admin
macro1 a62abde
Cleanup, refactor logic
macro1 9057b8a
Added test to access compare view
macro1 11ecb17
Fix admin compatability-related coverage
macro1 935ae9a
Added coverage for delta helper method
macro1 756d481
Compatability fixes
macro1 63113aa
Removed Django 1.3 from the test matrix
macro1 3592ee0
Fixed line length
macro1 0777640
Added Python 3.4 to the matrix, bumped tested Django versions
macro1 03fcf59
Use HhtmlDiff to generate the diff table
macro1 5cfe69e
Removed unused custom delta sequence generator
macro1 aa5c915
Added the templatetags package to the list of project packages
macro1 b71a5d4
Simple output check for `diff_table` templatetag
macro1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
simple_history/templates/simple_history/history_compare.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{% extends "admin/change_form.html" %} | ||
{% load i18n %} | ||
{% load url from future %} | ||
{% load admin_urls %} | ||
{% load simple_history_compare %} | ||
|
||
{% block breadcrumbs %} | ||
<div class="breadcrumbs"> | ||
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> | ||
› <a href="{% url 'admin:app_list' app_label=app_label %}">{{ app_label|capfirst|escape }}</a> | ||
› <a href="{% url opts|admin_urlname:'changelist' %}">{{ module_name }}</a> | ||
› <a href="{% url opts|admin_urlname:'change' object_id %}">{{ object|truncatewords:"18" }}</a> | ||
› {% trans 'Compare History' %} | ||
</div> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<style> | ||
.diff_sub { | ||
background: DarkSalmon; | ||
} | ||
.diff_add { | ||
background: YellowGreen; | ||
} | ||
.diff_chg { | ||
background: Khaki; | ||
} | ||
</style> | ||
|
||
<div id="content-main"> | ||
<div class="module"> | ||
|
||
{% for field in fields %} | ||
<div class="form-row field-{{ field.name }}"> | ||
{% if field.name %}<h4>{{ field.name }}</h4>{% endif %} | ||
{% if field.description %} | ||
<div class="description">{{ field.description|safe }}</div> | ||
{% endif %} | ||
<div> | ||
{{ field.label_tag }} | ||
<div> | ||
{% diff_table field.content field.prev_content field.section_break %} | ||
</div> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
|
||
</div> | ||
</div> | ||
{% endblock content %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import unicode_literals | ||
|
||
import difflib | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.simple_tag | ||
def diff_table(a, b, line_split="\n"): | ||
differ = difflib.HtmlDiff(wrapcolumn=80) | ||
try: | ||
return differ.make_table(a.split(line_split), b.split(line_split)) | ||
except AttributeError: | ||
if a != b: | ||
a = '<span class="diff_sub">{a}</span>'.format(a=a) | ||
b = '<span class="diff_add">{b}</span>'.format(b=b) | ||
return """<table class="diff" id="difflib_chg_to0__top" cellspacing="0" cellpadding="0" rules="groups"> | ||
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> | ||
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> | ||
|
||
<tbody> | ||
<tr><td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td><td class="diff_header" id="from0_1">1</td><td nowrap="nowrap">{a}</td><td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td><td class="diff_header" id="to0_1">1</td><td nowrap="nowrap">{b}</td></tr> | ||
</tbody> | ||
</table> | ||
""".format(a=a, b=b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from datetime import datetime, timedelta | ||
from django_webtest import WebTest | ||
from django.test import TestCase | ||
from django import VERSION | ||
from django.core.urlresolvers import reverse | ||
try: | ||
|
@@ -8,6 +9,7 @@ | |
except ImportError: # django 1.4 compatibility | ||
from django.contrib.auth.models import User | ||
from django.contrib.admin.util import quote | ||
from simple_history.templatetags import simple_history_compare | ||
|
||
from ..models import Book, Person, Poll | ||
|
||
|
@@ -29,7 +31,8 @@ def get_history_url(model, history_index=None): | |
return reverse('admin:%s_%s_history' % info, args=[quote(model.pk)]) | ||
|
||
|
||
class AdminSiteTest(WebTest): | ||
class AdminTest(WebTest): | ||
|
||
def setUp(self): | ||
self.user = User.objects.create_superuser('user_login', | ||
'u@example.com', 'pass') | ||
|
@@ -42,6 +45,9 @@ def login(self, user=None): | |
form['password'] = 'pass' | ||
return form.submit() | ||
|
||
|
||
class AdminSiteTest(AdminTest): | ||
|
||
def test_history_list(self): | ||
if VERSION >= (1, 5): | ||
try: | ||
|
@@ -156,3 +162,40 @@ def test_historical_user_with_setter(self): | |
self.login() | ||
add_page = self.app.get(reverse('admin:tests_paper_add')) | ||
add_page.form.submit() | ||
|
||
def test_compare_history(self): | ||
self.login() | ||
|
||
|
||
class CompareHistoryTest(AdminTest): | ||
|
||
def setUp(self): | ||
super(CompareHistoryTest, self).setUp() | ||
self.login() | ||
self.poll = Poll.objects.create(question="Who?", pub_date=today) | ||
for question in ("What?", "Where?", "When?", "Why?", "How?"): | ||
self.poll.question = question | ||
self.poll.save() | ||
|
||
def test_navigate_to_compare(self): | ||
response = self.app.get(get_history_url(self.poll)).form.submit() | ||
response.mustcontain("<title>Compare ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very rudimentary test. Should we check a comparison or two? |
||
|
||
|
||
class CompareTableTest(TestCase): | ||
|
||
def test_diff_table(self): | ||
table_markup = simple_history_compare.diff_table(a="this\nan\ntest", b="this\nis\na\ntest") | ||
self.assertEqual(table_markup, """ | ||
<table class="diff" id="difflib_chg_to1__top" | ||
cellspacing="0" cellpadding="0" rules="groups" > | ||
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> | ||
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> | ||
|
||
<tbody> | ||
<tr><td class="diff_next" id="difflib_chg_to1__0"><a href="#difflib_chg_to1__0">f</a></td><td class="diff_header" id="from1_1">1</td><td nowrap="nowrap">this</td><td class="diff_next"><a href="#difflib_chg_to1__0">f</a></td><td class="diff_header" id="to1_1">1</td><td nowrap="nowrap">this</td></tr> | ||
<tr><td class="diff_next"><a href="#difflib_chg_to1__top">t</a></td><td class="diff_header" id="from1_2">2</td><td nowrap="nowrap"><span class="diff_sub">an</span></td><td class="diff_next"><a href="#difflib_chg_to1__top">t</a></td><td class="diff_header" id="to1_2">2</td><td nowrap="nowrap"><span class="diff_add">is</span></td></tr> | ||
<tr><td class="diff_next"></td><td class="diff_header"></td><td nowrap="nowrap"></td><td class="diff_next"></td><td class="diff_header" id="to1_3">3</td><td nowrap="nowrap"><span class="diff_add">a</span></td></tr> | ||
<tr><td class="diff_next"></td><td class="diff_header" id="from1_3">3</td><td nowrap="nowrap">test</td><td class="diff_next"></td><td class="diff_header" id="to1_4">4</td><td nowrap="nowrap">test</td></tr> | ||
</tbody> | ||
</table>""") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add unit tests for this?