| Total Complexity | 4 | 
| Total Lines | 39 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | |||
| 3 | from bika.lims import api | ||
| 4 | from plone.app.textfield import RichText | ||
| 5 | from senaite.core.schema.fields import BaseField | ||
| 6 | from senaite.core.schema.interfaces import IRichTextField | ||
| 7 | from zope.interface import implementer | ||
| 8 | |||
| 9 | |||
| 10 | @implementer(IRichTextField) | ||
| 11 | class RichTextField(RichText, BaseField): | ||
| 12 | """A field that handles markup texts | ||
| 13 | """ | ||
| 14 | |||
| 15 | def set(self, object, value): | ||
| 16 | """Set field value | ||
| 17 | |||
| 18 | :param object: the instance of the field | ||
| 19 | :param value: value to set | ||
| 20 | """ | ||
| 21 | # always ensure unicode | ||
| 22 | if isinstance(value, str): | ||
| 23 | value = api.safe_unicode(value) | ||
| 24 | super(RichTextField, self).set(object, value) | ||
| 25 | |||
| 26 | def get(self, object): | ||
| 27 | """Get the field value | ||
| 28 | |||
| 29 | :param object: the instance of the field | ||
| 30 | :returns: RichTextValue | ||
| 31 | """ | ||
| 32 | value = super(RichTextField, self).get(object) | ||
| 33 | return value | ||
| 34 | |||
| 35 | def _validate(self, value): | ||
| 36 | """Validator when called from form submission | ||
| 37 | """ | ||
| 38 | super(RichTextField, self)._validate(value) | ||
| 39 |