Provide a way to show enum display text for some version diff fields
master view must explicitly declare which enums for which fields
This commit is contained in:
parent
2a9d5f74ce
commit
35131c8732
7 changed files with 172 additions and 26 deletions
|
@ -597,7 +597,6 @@ class MasterView(View):
|
|||
return defaults
|
||||
|
||||
def configure_row_grid(self, grid):
|
||||
# super(MasterView, self).configure_row_grid(grid)
|
||||
self.set_row_labels(grid)
|
||||
|
||||
self.configure_column_customer_key(grid)
|
||||
|
@ -1528,6 +1527,15 @@ class MasterView(View):
|
|||
})
|
||||
|
||||
def title_for_version(self, version):
|
||||
"""
|
||||
Must return the title text for the given version. By default
|
||||
this will be the :term:`rattail:model title` for the version's
|
||||
data class.
|
||||
|
||||
:param version: Reference to a Continuum version object.
|
||||
|
||||
:returns: Title text for the version, as string.
|
||||
"""
|
||||
cls = continuum.parent_class(version.__class__)
|
||||
return cls.get_model_title()
|
||||
|
||||
|
@ -4962,13 +4970,52 @@ class MasterView(View):
|
|||
return diffs.Diff(old_data, new_data, **kwargs)
|
||||
|
||||
def get_version_diff_factory(self, **kwargs):
|
||||
"""
|
||||
Must return the factory to be used when creating version diff
|
||||
objects.
|
||||
|
||||
By default this returns the
|
||||
:class:`tailbone.diffs.VersionDiff` class, unless
|
||||
:attr:`version_diff_factory` is set, in which case that is
|
||||
returned as-is.
|
||||
|
||||
:returns: A factory which can produce
|
||||
:class:`~tailbone.diffs.VersionDiff` objects.
|
||||
"""
|
||||
if hasattr(self, 'version_diff_factory'):
|
||||
return self.version_diff_factory
|
||||
return diffs.VersionDiff
|
||||
|
||||
def get_version_diff_enums(self, version):
|
||||
"""
|
||||
This can optionally return a dict of field enums, to be passed
|
||||
to the version diff factory. This method is called as part of
|
||||
:meth:`make_version_diff()`.
|
||||
"""
|
||||
|
||||
def make_version_diff(self, version, *args, **kwargs):
|
||||
"""
|
||||
Make a version diff object, using the factory returned by
|
||||
:meth:`get_version_diff_factory()`.
|
||||
|
||||
:param version: Reference to a Continuum version object.
|
||||
|
||||
:param title: If specified, must be as a kwarg. Optional
|
||||
override for the version title text. If not specified,
|
||||
:meth:`title_for_version()` is called for the title.
|
||||
|
||||
:param \*args: Additional args to pass to the factory.
|
||||
|
||||
:param \*\*kwargs: Additional kwargs to pass to the factory.
|
||||
|
||||
:returns: A :class:`~tailbone.diffs.VersionDiff` object.
|
||||
"""
|
||||
if 'title' not in kwargs:
|
||||
kwargs['title'] = self.title_for_version(version)
|
||||
|
||||
if 'enums' not in kwargs:
|
||||
kwargs['enums'] = self.get_version_diff_enums(version)
|
||||
|
||||
factory = self.get_version_diff_factory()
|
||||
return factory(version, *args, **kwargs)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue