kopia lustrzana https://github.com/wagtail/wagtail
Added ChoiceFieldComparison for fields with choices
rodzic
1127e9ae45
commit
a231bcba2d
|
|
@ -60,6 +60,17 @@ class StreamFieldComparison(RichTextFieldComparison):
|
|||
pass
|
||||
|
||||
|
||||
class ChoiceFieldComparison(FieldComparison):
|
||||
def htmldiff(self):
|
||||
val_a = force_text(dict(self.field.flatchoices).get(self.val_a, self.val_a), strings_only=True)
|
||||
val_b = force_text(dict(self.field.flatchoices).get(self.val_b, self.val_b), strings_only=True)
|
||||
|
||||
if self.val_a != self.val_b:
|
||||
return TextDiff([('deletion', val_a), ('addition', val_b)]).to_html()
|
||||
else:
|
||||
return val_a
|
||||
|
||||
|
||||
class PageFieldComparison(FieldComparison):
|
||||
def htmldiff(self):
|
||||
page_a = Page.objects.filter(id=self.val_a).first()
|
||||
|
|
|
|||
|
|
@ -474,6 +474,9 @@ class BaseFieldPanel(EditHandler):
|
|||
try:
|
||||
field = cls.model._meta.get_field(cls.field_name)
|
||||
|
||||
if field.choices:
|
||||
return compare.ChoiceFieldComparison
|
||||
|
||||
if field.get_internal_type() in ['CharField', 'TextField']:
|
||||
return compare.RichTextFieldComparison
|
||||
except FieldDoesNotExist:
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue