from __future__ import absolute_import, unicode_literals

from wagtail.wagtailadmin.edit_handlers import BaseChooserPanel

from .widgets import AdminDocumentChooser


class BaseDocumentChooserPanel(BaseChooserPanel):
    object_type_name = "document"

    @classmethod
    def widget_overrides(cls):
        return {cls.field_name: AdminDocumentChooser}


class DocumentChooserPanel(object):
    def __init__(self, field_name):
        self.field_name = field_name

    def bind_to_model(self, model):
        return type(str('_DocumentChooserPanel'), (BaseDocumentChooserPanel,), {
            'model': model,
            'field_name': self.field_name,
        })

@@ -51,16 +51,140 @@
 terals%0A%0A
+from django.utils.translation import ugettext_lazy as _%0A%0Afrom wagtail.wagtailadmin.compare import FieldComparison, TextDiff%0A
 from wag
@@ -238,16 +238,74 @@
 serPanel
+%0Afrom wagtail.wagtaildocs.models import get_document_model
 %0A%0Afrom .
@@ -530,16 +530,108 @@
 ooser%7D%0A%0A
+    @classmethod%0A    def get_comparison_class(cls):%0A        return DocumentFieldComparison%0A%0A
 %0Aclass D
@@ -921,16 +921,16 @@
 d_name,%0A
-
         
@@ -932,8 +932,785 @@
      %7D)%0A
+%0A%0Aclass DocumentFieldComparison(FieldComparison):%0A    def htmldiff(self):%0A        model = get_document_model()%0A        doc_a = model.objects.filter(id=self.val_a).first()%0A        doc_b = model.objects.filter(id=self.val_b).first()%0A%0A        if doc_a != doc_b:%0A            if doc_a and doc_b:%0A                # Changed%0A                return TextDiff(%5B('deletion', doc_a.title), ('addition', doc_b.title)%5D).to_html()%0A            elif doc_b:%0A                # Added%0A                return TextDiff(%5B('addition', doc_b.title)%5D).to_html()%0A            elif doc_a:%0A                # Removed%0A                return TextDiff(%5B('deletion', doc_a.title)%5D).to_html()%0A        else:%0A            if doc_a:%0A                return doc_a.title%0A            else:%0A                return _(%22None%22)%0A

Document chooser diff