# HG changeset patch # User Sylvain Thénault # Date 1245419735 -7200 # Node ID 464edb198faa274ffed464a26fd8477cda82106e # Parent bc86aa68cc437384f15f74a20c26d27016053a5c drop @ wildcard in relation subject/object, override main_attribute for proper behaviour diff -r bc86aa68cc43 -r 464edb198faa schema.py --- a/schema.py Fri Jun 19 15:54:55 2009 +0200 +++ b/schema.py Fri Jun 19 15:55:35 2009 +0200 @@ -63,32 +63,6 @@ etype = ETYPE_NAME_MAP[etype] return etype -# monkey path yams.builder.RelationDefinition to support a new wildcard type '@' -# corresponding to system entity (ie meta but not schema) -def _actual_types(self, schema, etype): - # two bits of error checking & reporting : - if type(etype) not in (str, list, tuple): - raise RuntimeError, ('Entity types must not be instances but strings or' - ' list/tuples thereof. Ex. (bad, good) : ' - 'SubjectRelation(Foo), SubjectRelation("Foo"). ' - 'Hence, %r is not acceptable.' % etype) - # real work : - if etype == '**': - return self._pow_etypes(schema) - if isinstance(etype, (tuple, list)): - return etype - if '*' in etype or '@' in etype: - assert len(etype) in (1, 2) - etypes = () - if '*' in etype: - etypes += tuple(self._wildcard_etypes(schema)) - # XXX deprecate, too clumsy - if '@' in etype: - etypes += tuple(system_etypes(schema)) - return etypes - return (etype,) -ybo.RelationDefinition._actual_types = _actual_types - ## cubicweb provides a RichString class for convenience class RichString(ybo.String): @@ -297,6 +271,15 @@ continue yield rschema, attrschema + def main_attribute(self): + """convenience method that returns the *main* (i.e. the first non meta) + attribute defined in the entity schema + """ + for rschema, _ in self.attribute_definitions(): + if not (rschema in META_RELATIONS_TYPES + or self.is_metadata(rschema)): + return rschema + def add_subject_relation(self, rschema): """register the relation schema as possible subject relation""" super(CubicWebEntitySchema, self).add_subject_relation(rschema)