Esempio n. 1
0
class Affaire(WorkflowableEntityType):
    __permissions__ = {
        'read': ('managers', ERQLExpression('X owned_by U'),
                 ERQLExpression('X concerne S?, S owned_by U')),
        'add': ('managers', ERQLExpression('X concerne S, S owned_by U')),
        'update':
        ('managers', 'owners',
         ERQLExpression('X in_state S, S name in ("pitetre", "en cours")')),
        'delete':
        ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
    }

    ref = String(fulltextindexed=True,
                 indexed=True,
                 constraints=[SizeConstraint(16)])
    sujet = String(fulltextindexed=True, constraints=[SizeConstraint(256)])
    descr = RichString(fulltextindexed=True,
                       description=_('more detailed description'))

    duration = Int()
    invoiced = Float()
    opt_attr = Bytes()

    depends_on = SubjectRelation('Affaire')
    require_permission = SubjectRelation('CWPermission')
    concerne = SubjectRelation(('Societe', 'Note'))
    todo_by = SubjectRelation('Personne', cardinality='?*')
    documented_by = SubjectRelation('Card')
Esempio n. 2
0
class Affaire(EntityType):
    __permissions__ = {
        'read':   ('managers', 'users', 'guests'),
        'add':    ('managers', ERQLExpression('X concerne S, S owned_by U')),
        'update': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
        'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
        }

    ref = String(fulltextindexed=True, indexed=True,
                 constraints=[SizeConstraint(16)])
    sujet = String(fulltextindexed=True,
                 constraints=[SizeConstraint(256)])
    concerne = SubjectRelation('Societe')
    opt_attr = Bytes()
Esempio n. 3
0
class State(EntityType):
    """used to associate simple states to an entity
    type and/or to define workflows
    """
    __permissions__ = {
        'read': (
            'managers',
            'users',
            'guests',
        ),
        'add': (
            'managers',
            'users',
        ),
        'delete': (
            'managers',
            'owners',
        ),
        'update': (
            'managers',
            'owners',
        ),
    }

    # attributes
    eid = Int(required=True, uid=True)
    name = String(required=True,
                  indexed=True,
                  internationalizable=True,
                  constraints=[SizeConstraint(256)])
    description = String(fulltextindexed=True)
    # relations
    state_of = SubjectRelation('Eetype', cardinality='+*')
    next_state = SubjectRelation('State', cardinality='**')
Esempio n. 4
0
class Folder2(EntityType):
    """folders are used to classify entities. They may be defined as a tree.
    When you include the Folder entity, all application specific entities
    may then be classified using the "filed_under" relation.
    """
    name = String(required=True, indexed=True, internationalizable=True,
                  constraints=[UniqueConstraint(), SizeConstraint(64)])
    description = RichString(fulltextindexed=True)
Esempio n. 5
0
 def set_vocabulary(self, vocabulary, kwargs=None):
     if kwargs is None:
         kwargs = self.__dict__
     #constraints = kwargs.setdefault('constraints', [])
     _add_constraint(kwargs, StaticVocabularyConstraint(vocabulary))
     if self.__class__.__name__ == 'String':  # XXX
         maxsize = max(len(x) for x in vocabulary)
         _add_constraint(kwargs, SizeConstraint(max=maxsize))
Esempio n. 6
0
 def __init__(self, metadata=None, **kwargs):
     # Store metadata
     if metadata is None:
         metadata = {}
     self.metadata = metadata
     # transform "required" into "cardinality"
     required = kwargs.pop('required', False)
     if required:
         cardinality = '11'
     else:
         cardinality = '?1'
     kwargs['cardinality'] = cardinality
     # transform maxsize into SizeConstraint
     maxsize = kwargs.pop('maxsize', None)
     if maxsize is not None:
         _add_constraint(kwargs, SizeConstraint(max=maxsize))
     # formula
     self.formula = kwargs.pop('formula', MARKER)
     # transform vocabulary into StaticVocabularyConstraint
     vocabulary = kwargs.pop('vocabulary', None)
     if vocabulary is not None:
         self.set_vocabulary(vocabulary, kwargs)
     # transform unique into UniqueConstraint
     unique = kwargs.pop('unique', None)
     if unique:
         _add_constraint(kwargs, UniqueConstraint())
     # use the etype attribute provided by subclasses
     super(AbstractTypedAttribute, self).__init__(self.etype, **kwargs)
     # reassign creation rank
     #
     # Main attribute are marked as created before it's metadata.
     # order in meta data is preserved.
     if self.metadata:
         meta = sorted(metadata.values(), key=lambda x: x.creation_rank)
         if meta[0].creation_rank < self.creation_rank:
             m_iter = iter(meta)
             previous = self
             for next in meta:
                 if previous.creation_rank < next.creation_rank:
                     break
                 previous.creation_rank, next.creation_rank = next.creation_rank, previous.creation_rank
                 next = previous
Esempio n. 7
0
class Eetype(EntityType):
    """define an entity type, used to build the application schema"""
    __permissions__ = {
        'read': (
            'managers',
            'users',
            'guests',
        ),
        'add': ('managers', ),
        'delete': ('managers', ),
        'update': (
            'managers',
            'owners',
        ),
    }
    name = String(required=True,
                  indexed=True,
                  internationalizable=True,
                  constraints=[UniqueConstraint(),
                               SizeConstraint(64)])
    description = String(fulltextindexed=True)
    meta = Boolean()
    final = Boolean()
Esempio n. 8
0
 class Entity(EntityType):
     attr = String(constraints=[StaticVocabularyConstraint(['ab', 'abc']),
                                SizeConstraint(2)])
Esempio n. 9
0
    def setUp(self):
        global schema, enote, eaffaire, eperson, esociete, estring, eint
        global rconcerne, rnom
        schema = Schema('Test Schema')
        register_base_types(schema)
        enote = schema.add_entity_type(EntityType('Note'))
        eaffaire = schema.add_entity_type(EntityType('Affaire'))
        eperson = schema.add_entity_type(EntityType('Person'))
        esociete = schema.add_entity_type(EntityType('Societe'))

        RELS = (
            # attribute relations
            ('Note date Datetime'),
            ('Note type String'),
            ('Affaire sujet String'),
            ('Affaire ref String'),
            ('Affaire starton Time'),
            ('Person nom String'),
            ('Person prenom String'),
            ('Person sexe Float'),
            ('Person tel Int'),
            ('Person fax Int'),
            ('Person datenaiss Date'),
            ('Person TEST Boolean'),
            ('Person promo String'),
            ('Person promo_enlarged String'),
            ('Person promo_encoding String'),
            ('Person promo_format String'),
            # real relations
            ('Person  travaille Societe'),
            ('Person  evaluee   Note'),
            ('Societe evaluee   Note'),
            ('Person  concerne  Affaire'),
            ('Person  concerne  Societe'),
            ('Affaire concerne  Societe'),
        )
        for i, rel in enumerate(RELS):
            _from, _type, _to = rel.split()
            try:
                schema.rschema(_type)
            except KeyError:
                schema.add_relation_type(RelationType(_type))
            schema.add_relation_def(
                RelationDefinition(_from, _type, _to, order=i))
        schema.rschema('nom').rdef('Person',
                                   'String').cardinality = '11'  # not null

        enote.rdef('type').constraints = [
            StaticVocabularyConstraint(
                (u'bon', u'pasbon', u'bof', u'peux mieux faire'))
        ]
        enote.rdef('date').cardinality = '11'

        eaffaire.rdef('sujet').constraints = [SizeConstraint(128)]
        eaffaire.rdef('ref').constraints = [
            SizeConstraint(12),
            RegexpConstraint(r'[A-Z]+\d+')
        ]
        eperson.rdef('nom').constraints = [SizeConstraint(20, 10)]
        eperson.rdef('prenom').constraints = [SizeConstraint(64)]
        eperson.rdef('tel').constraints = [
            IntervalBoundConstraint(maxvalue=999999)
        ]
        eperson.rdef('fax').constraints = [
            IntervalBoundConstraint(minvalue=12, maxvalue=999999)
        ]
        eperson.rdef('promo').constraints = [
            StaticVocabularyConstraint((u'bon', u'pasbon'))
        ]
        eperson.rdef('promo_format').constraints = [FormatConstraint()]

        estring = schema.eschema('String')
        eint = schema.eschema('Int')
        rconcerne = schema.rschema('concerne')
        rnom = schema.rschema('nom')