43 """tidy HTML in rich text strings""" |
43 """tidy HTML in rich text strings""" |
44 events = ('before_add_entity', 'before_update_entity') |
44 events = ('before_add_entity', 'before_update_entity') |
45 accepts = ('Any',) |
45 accepts = ('Any',) |
46 |
46 |
47 def call(self, session, entity): |
47 def call(self, session, entity): |
48 for formatattr, attr in entity.e_schema.format_fields.iteritems(): |
48 metaattrs = entity.e_schema.meta_attributes() |
49 try: |
49 for metaattr, (metadata, attr) in metaattrs.iteritems(): |
50 value = entity[attr] |
50 if metadata == 'format': |
51 except KeyError: |
51 try: |
52 continue # no text to tidy |
52 value = entity[attr] |
53 if isinstance(value, unicode): # filter out None and Binary |
53 except KeyError: |
54 if self.event == 'before_add_entity': |
54 continue # no text to tidy |
55 fmt = entity.get(formatattr) |
55 if isinstance(value, unicode): # filter out None and Binary |
56 else: |
56 if self.event == 'before_add_entity': |
57 fmt = entity.get_value(formatattr) |
57 fmt = entity.get(metaattr) |
58 if fmt == 'text/html': |
58 else: |
59 entity[attr] = soup2xhtml(value, session.encoding) |
59 fmt = entity.get_value(metaattr) |
|
60 if fmt == 'text/html': |
|
61 entity[attr] = soup2xhtml(value, session.encoding) |
60 |
62 |