Passed
Push — 2.x ( 353ef7...3874f5 )
by Jordi
05:23
created

senaite.core.schema.richtextfield   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A RichTextField.set() 0 10 2
A RichTextField._validate() 0 4 1
A RichTextField.get() 0 8 1
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