Permalink
Browse files

Improved diff.

  • Loading branch information...
1 parent 95cd990 commit 1651786afa22977985f157a123d992de429b9da9 Anand Chitipothu committed with Open Library Oct 3, 2011
Showing with 53 additions and 7 deletions.
  1. +53 −7 openlibrary/plugins/upstream/templates/diff.html
@@ -51,6 +51,43 @@ <h2 class="collapse"><a href="$a.key">$title</a> &rarr; Diff</h2>
<img src="$get_coverstore_url()/b/id/$img-M.jpg"/>
</td>
</tr>
+
+$def listdiff(name, a, b):
+ $ diffresults = better_diff(a or [], b or [])
+ <tr>
+ <td class="diff-header-side" valign="top">$name</td>
+ <td colspan="2">
+ <table style="width: 100%">
+ $for key, ai, a, bi, b in diffresults:
+ <tbody class="$key">
+ <tr>
+ <td class="diff-number">$ai</td>
+ <td class='l'>$:diff_display(name, a)</td>
+ <td class="diff-number">$bi</td>
+ <td class='r'>$:diff_display(name, b)</td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+
+$def diff_display(name, value):
+ $if isinstance(value, basestring):
+ $value
+ $elif isinstance(value, dict):
+ $value
+ $else:
+ $if name == "links":
+ <a href="$value.url">$value.title</a>
+ <span style="display: block" class="link wrap">$value.url</span>
+ $elif name == "excerpts":
+ <span>$value.excerpt</span>
+ $elif value.key:
+ <a href="$value.key">$(value.name or value.title or value.key)</a>
+ <span style="display: block" class="link wrap">$value.key</span>
+ $else:
+ $ value = value.dict()
+ $value
<div id="contentBody" class="diff">
@@ -77,17 +114,26 @@ <h2 class="collapse"><a href="$a.key">$title</a> &rarr; Diff</h2>
elif p == "title_prefix":
return thingdiff("/type/string", "title_prefix", a[p].strip(), b[p].strip())
elif p == "authors":
- return thingdiff("/type/author", "authors", a.get_authors(), b.get_authors())
+ label = "authors"
+ t = "/type/author"
+ ap = a.get_authors()
+ bp = b.get_authors()
else:
ap = a[p]
bp = b[p]
t = get_expected_type(a, p)
- if t == "/type/string":
- if is_thing(ap):
- ap = ap.dict()
- if is_thing(bp):
- bp = bp.dict()
- return thingdiff(t, label, ap, bp)
+
+ if isinstance(ap, list) or isinstance(bp, list):
+ if ap == bp:
+ return ""
+ else:
+ return listdiff(label, ap, bp)
+ elif t == "/type/string":
+ if is_thing(ap):
+ ap = ap.dict()
+ if is_thing(bp):
+ bp = bp.dict()
+ return thingdiff(t, label, ap, bp)
$ diff_count = 0

0 comments on commit 1651786

Please sign in to comment.