Ejemplo n.º 1
0
    def inline_diff(self):
        if self.same:
            return None

        css_class = 'InlineDiff'

        old_reprs = self._parseField(self.oldValue, None)
        new_reprs = self._parseField(self.newValue, None)

        old_data = [
            {'repr': repr, 'data': value.data, 'filename': value.filename}
            for (repr, value) in zip(old_reprs, self.oldValue or [])
        ]
        new_data = [
            {'repr': repr, 'data': value.data, 'filename': value.filename}
            for (repr, value) in zip(new_reprs, self.newValue or [])
        ]

        dummy_dict = {'repr': '', 'data': None, 'filename': None}
        make_lists_same_length(old_data, new_data, dummy_dict)

        is_same_dict = lambda d1, d2: is_same(
            d1['data'], d1['filename'], d2['data'], d2['filename']
        )

        return '\n'.join([
            (
                (self.same_fmt % (css_class, d_old['repr'])) if is_same_dict(d_old, d_new)
                else self.inlinediff_fmt % (css_class, d_old['repr'], d_new['repr'])
            ) for (d_old, d_new) in zip(old_data, new_data)
        ])
Ejemplo n.º 2
0
    def __init__(self,
                 obj1,
                 obj2,
                 field,
                 id1=None,
                 id2=None,
                 field_name=None,
                 field_label=None,
                 schemata=None):

        self.field = field
        self.label = field_label or field
        self.schemata = schemata or 'default'
        self.field_name = field_name or field

        old_field = getattr(obj1, field)
        new_field = getattr(obj2, field)

        self.oldValue = getattr(old_field, 'data', None)
        self.newValue = getattr(new_field, 'data', None)

        self.id1 = id1 or getattr(obj1, 'getId', lambda: None)()
        self.id2 = id2 or getattr(obj2, 'getId', lambda: None)()

        self.oldFilename = getattr(old_field, 'filename', None)
        self.newFilename = getattr(new_field, 'filename', None)

        self.same = is_same(self.oldValue, self.oldFilename, self.newValue,
                            self.newFilename)
Ejemplo n.º 3
0
    def __init__(self, obj1, obj2, field, id1=None, id2=None, field_name=None,
                 field_label=None, schemata=None):
        ListDiff.__init__(self, obj1, obj2, field, id1, id2, field_name,
                          field_label, schemata)
        old_values = list(self.oldValue or [])
        new_values = list(self.newValue or [])

        self.same = True
        if len(old_values) != len(new_values):
            self.same = False
        else:
            for (old, new) in zip(old_values, new_values):
                if not is_same(old.data, old.filename, new.data, new.filename):
                    self.same = False
                    break
    def __init__(self, obj1, obj2, field, id1=None, id2=None, field_name=None,
                 field_label=None, schemata=None):

        self.field = field
        self.label = field_label or field
        self.schemata = schemata or 'default'
        self.field_name = field_name or field

        old_field = getattr(obj1, field)
        new_field = getattr(obj2, field)

        self.oldValue = getattr(old_field, 'data', None)
        self.newValue = getattr(new_field, 'data', None)

        self.id1 = id1 or getattr(obj1, 'getId', lambda: None)()
        self.id2 = id2 or getattr(obj2, 'getId', lambda: None)()

        self.oldFilename = getattr(old_field, 'filename', None)
        self.newFilename = getattr(new_field, 'filename', None)

        self.same = is_same(
            self.oldValue, self.oldFilename, self.newValue, self.newFilename)