server/test/data-schema2sql/schema/schema.py
author Rémi Cardona <remi.cardona@logilab.fr>
Fri, 18 Sep 2015 11:54:12 +0200
changeset 10706 b261d90149d0
parent 10443 2d3834df64ab
child 10907 9ae707db5265
permissions -rw-r--r--
[server] Port BFSS to py3k The BFSS API changes in python 3: * 'defaultdir' MUST be a unicode object * 'fsencoding' MUST NOT be set In python 2, fsencoding handles both the encoding of file paths on the file system (utf-8 by default, but the system may actually be using something else) and the encoding of file paths that will be stored in the database. So in python 3, we wipe the slate clean: * rely on sys.getfilesystemencoding() to convert unicode objects to bytes * always encode paths to utf-8 for storage in the database Caveat emptor / here be dragons: * sys.getfilesystemencoding() depends on the current locale, which therefore MUST be set properly * when migrating an existing instance from py2 to py3, one MAY need to reencode file paths stored in the database

# copyright 2004-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of yams.
#
# yams is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# yams is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with yams. If not, see <http://www.gnu.org/licenses/>.
from yams.buildobjs import (EntityType, RelationDefinition, RelationType,
                            SubjectRelation, String, Int, Float, Date, Boolean)
from yams.constraints import Attribute, BoundaryConstraint

class Affaire(EntityType):
    sujet = String(maxsize=128)
    ref = String(maxsize=12)

    concerne = SubjectRelation('Societe')
    obj_wildcard = SubjectRelation('*')
    sym_rel = SubjectRelation('Person', symmetric=True)
    inline_rel = SubjectRelation('Person', inlined=True, cardinality='?*')

class subj_wildcard(RelationDefinition):
    subject = '*'
    object = 'Affaire'


class Person(EntityType):
    __unique_together__ = [('nom', 'prenom')]
    nom    = String(maxsize=64, fulltextindexed=True, required=True)
    prenom = String(maxsize=64, fulltextindexed=True)
    sexe   = String(maxsize=1, default='M')
    promo  = String(vocabulary=('bon','pasbon'))
    titre  = String(maxsize=128, fulltextindexed=True)
    adel   = String(maxsize=128)
    ass    = String(maxsize=128)
    web    = String(maxsize=128)
    tel    = Int(__permissions__={'read': (),
                                  'add': ('managers',),
                                  'update': ('managers',)})
    fax    = Int()
    datenaiss = Date()
    test   = Boolean()
    salary = Float()
    travaille = SubjectRelation('Societe',
                                __permissions__={'read': (),
                                                 'add': (),
                                                 'delete': ('managers',),
                                                 })

    evaluee = SubjectRelation('Note')

class Salaried(Person):
    __specializes_schema__ = True

class Societe(EntityType):
    nom  = String(maxsize=64, fulltextindexed=True)
    web = String(maxsize=128)
    tel  = Int()
    fax  = Int(constraints=[BoundaryConstraint('<=', Attribute('tel'))])
    rncs = String(maxsize=32)
    ad1  = String(maxsize=128)
    ad2  = String(maxsize=128)
    ad3  = String(maxsize=128)
    cp   = String(maxsize=12)
    ville = String(maxsize=32)

    evaluee = SubjectRelation('Note')


class Note(EntityType):
    date = String(maxsize=10)
    type = String(maxsize=1)
    para = String(maxsize=512)


class pkginfo(EntityType):
    modname = String(maxsize=30, required=True)
    version = String(maxsize=10, required=True, default='0.1')
    copyright = String(required=True)
    license = String(vocabulary=('GPL', 'ZPL'))
    short_desc = String(maxsize=80, required=True)
    long_desc = String(required=True, fulltextindexed=True)
    author = String(maxsize=100, required=True)
    author_email = String(maxsize=100, required=True)
    mailinglist = String(maxsize=100)
    debian_handler = String(vocabulary=('machin', 'bidule'))


class evaluee(RelationType):
    __permissions__ = {
        'read': ('managers',),
        'add': ('managers',),
        'delete': ('managers',),
        }

class concerne(RelationDefinition):
    subject = 'Person'
    object = 'Affaire'
    __permissions__ = {
        'read': ('managers',),
        'add': ('managers',),
        'delete': ('managers',),
        }