schema.py 1.85 KB
Newer Older
Pierre-Yves David's avatar
Pierre-Yves David committed
1
2
from yams.buildobjs import (EntityType, SubjectRelation, String, RichString,
                            RelationDefinition)
Sylvain Thénault's avatar
Sylvain Thénault committed
3
from yams.reader import context
4
from cubicweb.schema import RRQLExpression, RQLConstraint
5

6
from cubicweb import _
7

Nicolas Chauvat's avatar
Nicolas Chauvat committed
8
9
10
11
12
13
14
15

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
16
17

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

Sylvain Thénault's avatar
Sylvain Thénault committed
19
20
21
22
23
24
    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
25

Sylvain Thénault's avatar
d-t-w    
Sylvain Thénault committed
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class use_email(RelationDefinition):
    """person's email account"""
    __permissions__ = {
        'read':   ('managers', 'users', 'guests',),
        'add':    ('managers', RRQLExpression('U has_update_permission S'),),
        'delete': ('managers', RRQLExpression('U has_update_permission S'),),
        }
    subject = "Person"
    object = "EmailAddress"
    cardinality = '*?'
    composite = 'subject'


class primary_email(RelationDefinition):
    """person's primary email account"""
    __permissions__ = {
        'read':   ('managers', 'users', 'guests',),
        'add':    ('managers', RRQLExpression('U has_update_permission S'),),
        'delete': ('managers', RRQLExpression('U has_update_permission S'),),
        }
    subject = "Person"
    object = "EmailAddress"
    cardinality = '??'
    constraints= [RQLConstraint('S use_email O')]