goa/__init__.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1133 8a409ea0c9ec
child 1977 606923dff11b
equal deleted inserted replaced
1801:672acc730ce5 1802:d628defebc17
    15 except ImportError:
    15 except ImportError:
    16     # not in google app environment
    16     # not in google app environment
    17     pass
    17     pass
    18 else:
    18 else:
    19 
    19 
    20     import os    
    20     import os
    21     _SS = os.environ.get('SERVER_SOFTWARE')
    21     _SS = os.environ.get('SERVER_SOFTWARE')
    22     if _SS is None:
    22     if _SS is None:
    23         MODE = 'test'
    23         MODE = 'test'
    24     elif _SS.startswith('Dev'):
    24     elif _SS.startswith('Dev'):
    25         MODE = 'dev'
    25         MODE = 'dev'
    28 
    28 
    29     from cubicweb.server import SOURCE_TYPES
    29     from cubicweb.server import SOURCE_TYPES
    30     from cubicweb.goa.gaesource import GAESource
    30     from cubicweb.goa.gaesource import GAESource
    31     SOURCE_TYPES['gae'] = GAESource
    31     SOURCE_TYPES['gae'] = GAESource
    32 
    32 
    33     
    33 
    34     def do_monkey_patch():
    34     def do_monkey_patch():
    35 
    35 
    36         # monkey patch yams Bytes validator since it should take a bytes string with gae
    36         # monkey patch yams Bytes validator since it should take a bytes string with gae
    37         # and not a StringIO
    37         # and not a StringIO
    38         def check_bytes(eschema, value):
    38         def check_bytes(eschema, value):
    54         import cubicweb
    54         import cubicweb
    55         cubicweb.typed_eid = typed_eid
    55         cubicweb.typed_eid = typed_eid
    56 
    56 
    57         # XXX monkey patch cubicweb.schema.CubicWebSchema to have string eid with
    57         # XXX monkey patch cubicweb.schema.CubicWebSchema to have string eid with
    58         #     optional cardinality (since eid is set after the validation)
    58         #     optional cardinality (since eid is set after the validation)
    59         
    59 
    60         import re
    60         import re
    61         from yams import buildobjs as ybo
    61         from yams import buildobjs as ybo
    62         
    62 
    63         def add_entity_type(self, edef):
    63         def add_entity_type(self, edef):
    64             edef.name = edef.name.encode()
    64             edef.name = edef.name.encode()
    65             assert re.match(r'[A-Z][A-Za-z0-9]*[a-z]+[0-9]*$', edef.name), repr(edef.name)
    65             assert re.match(r'[A-Z][A-Za-z0-9]*[a-z]+[0-9]*$', edef.name), repr(edef.name)
    66             eschema = super(CubicWebSchema, self).add_entity_type(edef)
    66             eschema = super(CubicWebSchema, self).add_entity_type(edef)
    67             if not eschema.is_final():
    67             if not eschema.is_final():
    68                 # automatically add the eid relation to non final entity types 
    68                 # automatically add the eid relation to non final entity types
    69                 rdef = ybo.RelationDefinition(eschema.type, 'eid', 'Bytes',
    69                 rdef = ybo.RelationDefinition(eschema.type, 'eid', 'Bytes',
    70                                               cardinality='?1', uid=True)
    70                                               cardinality='?1', uid=True)
    71                 self.add_relation_def(rdef)
    71                 self.add_relation_def(rdef)
    72                 rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type)
    72                 rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type)
    73                 self.add_relation_def(rdef)
    73                 self.add_relation_def(rdef)
    74             self._eid_index[eschema.eid] = eschema
    74             self._eid_index[eschema.eid] = eschema
    75             return eschema
    75             return eschema
    76         
    76 
    77         from cubicweb.schema import CubicWebSchema
    77         from cubicweb.schema import CubicWebSchema
    78         CubicWebSchema.add_entity_type = add_entity_type
    78         CubicWebSchema.add_entity_type = add_entity_type
    79 
    79 
    80 
    80 
    81         # don't reset vreg on repository set_schema
    81         # don't reset vreg on repository set_schema
    91             """return the list of top level cubes used by this instance"""
    91             """return the list of top level cubes used by this instance"""
    92             config = self.config
    92             config = self.config
    93             cubes = config['included-cubes'] + config['included-yams-cubes']
    93             cubes = config['included-cubes'] + config['included-yams-cubes']
    94             return config.expand_cubes(cubes)
    94             return config.expand_cubes(cubes)
    95         repository.Repository.get_cubes = get_cubes
    95         repository.Repository.get_cubes = get_cubes
    96         
    96 
    97         from rql import RQLHelper
    97         from rql import RQLHelper
    98         RQLHelper.simplify = lambda x, r: None
    98         RQLHelper.simplify = lambda x, r: None
    99 
    99 
   100         # activate entity caching on the server side
   100         # activate entity caching on the server side
   101 
   101