schema.py 1.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
from yams.buildobjs import EntityType, SubjectRelation, String

try:
    from yams.buildobjs import RichString
    from yams.reader import context
    defined_types = context.defined
except ImportError:
    from cubicweb.schema import RichString

from cubicweb.schema import RQLConstraint

_ = unicode
Nicolas Chauvat's avatar
Nicolas Chauvat committed
13
14
15
16
17
18
19
20

class Person(EntityType):
    """a physical person"""
    surname   = String(required=True, fulltextindexed=True, indexed=True, maxsize=64)
    firstname = String(fulltextindexed=True, maxsize=64)
    civility  = String(required=True, internationalizable=True,
                       vocabulary=(_('Mr'), _('Ms'), _('Mrs')),
                       default='Mr')
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
21
22

    description        = RichString(fulltextindexed=True)
Nicolas Chauvat's avatar
Nicolas Chauvat committed
23
24

    if 'PhoneNumber' in defined_types: # from addressbook package
25
26
27
        phone           = SubjectRelation('PhoneNumber', composite='subject')
    if 'PostalAddress' in defined_types:
        postal_address  = SubjectRelation('PostalAddress', composite='subject')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
28
29
30
31
32
33

    use_email     = SubjectRelation('EmailAddress', cardinality='*1', composite='subject')
    # allowing an email to be the primary email of multiple persons is necessary for
    # test at least :-/
    primary_email = SubjectRelation('EmailAddress', cardinality='??',
                                    constraints= [RQLConstraint('S use_email O')])
34
   
Nicolas Chauvat's avatar
Nicolas Chauvat committed
35