schema.py 1.28 KB
Newer Older
Sylvain Thénault's avatar
Sylvain Thénault committed
1
2
from yams.buildobjs import EntityType, SubjectRelation, String, RichString
from yams.reader import context
3
4
5
from cubicweb.schema import RQLConstraint

_ = unicode
Nicolas Chauvat's avatar
Nicolas Chauvat committed
6
7
8
9
10
11
12
13

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
14
15

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

Sylvain Thénault's avatar
Sylvain Thénault committed
17
18
19
20
21
22
    if 'PhoneNumber' in context.defined: # from addressbook package
        phone = SubjectRelation('PhoneNumber', composite='subject')
    if 'PostalAddress' in context.defined:
        postal_address = SubjectRelation('PostalAddress', composite='subject')
    if 'IMAddress' in context.defined:
        im_address = SubjectRelation('IMAddress', composite='subject')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
23
24
25
26
27
28

    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')])
Sylvain Thénault's avatar
d-t-w    
Sylvain Thénault committed
29

Nicolas Chauvat's avatar
Nicolas Chauvat committed
30