838 kwargs['o'] = toeid |
838 kwargs['o'] = toeid |
839 return self._check(session, **kwargs) |
839 return self._check(session, **kwargs) |
840 |
840 |
841 PyFileReader.context['RRQLExpression'] = RRQLExpression |
841 PyFileReader.context['RRQLExpression'] = RRQLExpression |
842 |
842 |
843 |
843 # workflow extensions ######################################################### |
|
844 |
|
845 class workflowable_definition(ybo.metadefinition): |
|
846 """extends default EntityType's metaclass to add workflow relations |
|
847 (i.e. in_state and wf_info_for). |
|
848 This is the default metaclass for WorkflowableEntityType |
|
849 """ |
|
850 def __new__(mcs, name, bases, classdict): |
|
851 abstract = classdict.pop('abstract', False) |
|
852 defclass = super(workflowable_definition, mcs).__new__(mcs, name, bases, classdict) |
|
853 if not abstract: |
|
854 existing_rels = set(rdef.name for rdef in defclass.__relations__) |
|
855 if 'in_state' not in existing_rels and 'wf_info_for' not in existing_rels: |
|
856 in_state = ybo.SubjectRelation('State', cardinality='1*', |
|
857 # XXX automatize this |
|
858 constraints=[RQLConstraint('S is ET, O state_of ET')], |
|
859 description=_('account state')) |
|
860 yams_add_relation(defclass.__relations__, in_state, 'in_state') |
|
861 wf_info_for = ybo.ObjectRelation('TrInfo', cardinality='1*', composite='object') |
|
862 yams_add_relation(defclass.__relations__, wf_info_for, 'wf_info_for') |
|
863 return defclass |
|
864 |
|
865 class WorkflowableEntityType(ybo.EntityType): |
|
866 __metaclass__ = workflowable_definition |
|
867 abstract = True |
|
868 |
|
869 PyFileReader.context['WorkflowableEntityType'] = WorkflowableEntityType |
|
870 |
844 # schema loading ############################################################## |
871 # schema loading ############################################################## |
845 |
872 |
846 class CubicWebRelationFileReader(RelationFileReader): |
873 class CubicWebRelationFileReader(RelationFileReader): |
847 """cubicweb specific relation file reader, handling additional RQL |
874 """cubicweb specific relation file reader, handling additional RQL |
848 constraints on a relation definition |
875 constraints on a relation definition |