schema.py
changeset 3293 69c0ba095536
parent 2968 0e3460341023
parent 3287 19c1011736a6
child 3369 7b88d12b4ee2
equal deleted inserted replaced
3230:1d25e928c299 3293:69c0ba095536
    42 #  set of meta-relations available for every entity types
    42 #  set of meta-relations available for every entity types
    43 META_RTYPES = set((
    43 META_RTYPES = set((
    44     'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
    44     'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
    45     'eid', 'creation_date', 'modification_date', 'has_text', 'cwuri',
    45     'eid', 'creation_date', 'modification_date', 'has_text', 'cwuri',
    46     ))
    46     ))
       
    47 SYSTEM_RTYPES = set(('require_permission', 'custom_workflow', 'in_state', 'wf_info_for'))
    47 
    48 
    48 #  set of entity and relation types used to build the schema
    49 #  set of entity and relation types used to build the schema
    49 SCHEMA_TYPES = set((
    50 SCHEMA_TYPES = set((
    50     'CWEType', 'CWRType', 'CWAttribute', 'CWRelation',
    51     'CWEType', 'CWRType', 'CWAttribute', 'CWRelation',
    51     'CWConstraint', 'CWConstraintType', 'RQLExpression',
    52     'CWConstraint', 'CWConstraintType', 'RQLExpression',
    98             etype, ETYPE_NAME_MAP[etype])
    99             etype, ETYPE_NAME_MAP[etype])
    99         warn(msg, DeprecationWarning, stacklevel=4)
   100         warn(msg, DeprecationWarning, stacklevel=4)
   100         etype = ETYPE_NAME_MAP[etype]
   101         etype = ETYPE_NAME_MAP[etype]
   101     return etype
   102     return etype
   102 
   103 
   103 def display_name(req, key, form=''):
   104 def display_name(req, key, form='', context=None):
   104     """return a internationalized string for the key (schema entity or relation
   105     """return a internationalized string for the key (schema entity or relation
   105     name) in a given form
   106     name) in a given form
   106     """
   107     """
   107     assert form in ('', 'plural', 'subject', 'object')
   108     assert form in ('', 'plural', 'subject', 'object')
   108     if form == 'subject':
   109     if form == 'subject':
   109         form = ''
   110         form = ''
   110     if form:
   111     if form:
   111         key = key + '_' + form
   112         key = key + '_' + form
   112     # ensure unicode
   113     # ensure unicode
   113     # added .lower() in case no translation are available
   114     # .lower() in case no translation are available XXX done whatever a translation is there or not!
   114     return unicode(req._(key)).lower()
   115     if context is not None:
       
   116         return unicode(req.pgettext(context, key)).lower()
       
   117     else:
       
   118         return unicode(req._(key)).lower()
       
   119 
   115 __builtins__['display_name'] = deprecated('[3.4] display_name should be imported from cubicweb.schema')(display_name)
   120 __builtins__['display_name'] = deprecated('[3.4] display_name should be imported from cubicweb.schema')(display_name)
   116 
   121 
   117 def ERSchema_display_name(self, req, form=''):
   122 def ERSchema_display_name(self, req, form=''):
   118     """return a internationalized string for the entity/relation type name in
   123     """return a internationalized string for the entity/relation type name in
   119     a given form
   124     a given form
   640             raise RQLSyntaxError(expression)
   645             raise RQLSyntaxError(expression)
   641         for mainvar in mainvars.split(','):
   646         for mainvar in mainvars.split(','):
   642             if len(self.rqlst.defined_vars[mainvar].references()) <= 2:
   647             if len(self.rqlst.defined_vars[mainvar].references()) <= 2:
   643                 _LOGGER.warn('You did not use the %s variable in your RQL '
   648                 _LOGGER.warn('You did not use the %s variable in your RQL '
   644                              'expression %s', mainvar, self)
   649                              'expression %s', mainvar, self)
       
   650         # syntax tree used by read security (inserted in queries when necessary
       
   651         self.snippet_rqlst = parse(self.minimal_rql, print_errors=False).children[0]
   645 
   652 
   646     def __str__(self):
   653     def __str__(self):
   647         return self.full_rql
   654         return self.full_rql
   648     def __repr__(self):
   655     def __repr__(self):
   649         return '%s(%s)' % (self.__class__.__name__, self.full_rql)
   656         return '%s(%s)' % (self.__class__.__name__, self.full_rql)
   765 
   772 
   766 
   773 
   767 class ERQLExpression(RQLExpression):
   774 class ERQLExpression(RQLExpression):
   768     def __init__(self, expression, mainvars=None, eid=None):
   775     def __init__(self, expression, mainvars=None, eid=None):
   769         RQLExpression.__init__(self, expression, mainvars or 'X', eid)
   776         RQLExpression.__init__(self, expression, mainvars or 'X', eid)
   770         # syntax tree used by read security (inserted in queries when necessary
       
   771         self.snippet_rqlst = parse(self.minimal_rql, print_errors=False).children[0]
       
   772 
   777 
   773     @property
   778     @property
   774     def full_rql(self):
   779     def full_rql(self):
   775         rql = self.minimal_rql
   780         rql = self.minimal_rql
   776         rqlst = getattr(self, 'rqlst', None) # may be not set yet
   781         rqlst = getattr(self, 'rqlst', None) # may be not set yet