1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
from zope.security.proxy import isinstance as zope_isinstance
5
from lazr.enum import BaseItem
7
def value_string(item):
8
"""Return a unicode string representing an SQLObject value."""
11
elif zope_isinstance(item, BaseItem):
17
def text_delta(instance_delta, delta_names, state_names, interface):
18
"""Return a textual delta for a Delta object.
20
A list of strings is returned.
22
Only modified members of the delta will be shown.
24
:param instance_delta: The delta to generate a textual representation of.
25
:param delta_names: The names of all members to show changes to.
26
:param state_names: The names of all members to show only the new state
28
:param interface: The Zope interface that the input delta compared.
33
# Fields for which we have old and new values.
34
for field_name in delta_names:
35
delta = getattr(instance_delta, field_name, None)
38
title = interface[field_name].title
39
old_item = value_string(delta['old'])
40
new_item = value_string(delta['new'])
41
output.append("%s%s: %s => %s" % (indent, title, old_item, new_item))
42
for field_name in state_names:
43
delta = getattr(instance_delta, field_name, None)
46
title = interface[field_name].title
49
output.append('%s changed to:\n\n%s' % (title, delta))
50
return '\n'.join(output)
53
def append_footer(main, footer):
54
"""Append a footer to an email, following signature conventions.
56
If there is no footer, do nothing.
57
If there is already a signature, append an additional footer.
58
If there is no existing signature, append '-- \n' and a footer.
60
:param main: The main content, which may have a signature.
61
:param footer: An additional footer to append.
62
:return: a new version of main that includes the footer.
66
elif '\n-- \n' in main:
67
footer_separator = '\n'
69
footer_separator = '\n-- \n'
70
return ''.join((main, footer_separator, footer))