sobjects/supervising.py
changeset 2968 0e3460341023
parent 2841 107ba1c45227
parent 2920 64322aa83a1d
child 3163 edfe43ceaa35
equal deleted inserted replaced
2902:dd9f2dd02f85 2968:0e3460341023
    32         if event == 'add_entity':
    32         if event == 'add_entity':
    33             entity = changedescr.entity
    33             entity = changedescr.entity
    34             added.add(entity.eid)
    34             added.add(entity.eid)
    35             if entity.e_schema == 'TrInfo':
    35             if entity.e_schema == 'TrInfo':
    36                 changes.remove(change)
    36                 changes.remove(change)
    37                 if entity.from_state:
    37                 event = 'change_state'
    38                     try:
    38                 change = (event,
    39                         changes.remove( ('delete_relation',
    39                           (entity.wf_info_for[0],
    40                                          (entity.wf_info_for[0].eid, 'in_state',
    40                            entity.from_state[0], entity.to_state[0]))
    41                                           entity.from_state[0].eid)) )
    41                 changes.append(change)
    42                     except ValueError:
       
    43                         pass
       
    44                     try:
       
    45                         changes.remove( ('add_relation',
       
    46                                          (entity.wf_info_for[0].eid, 'in_state',
       
    47                                           entity.to_state[0].eid)) )
       
    48                     except ValueError:
       
    49                         pass
       
    50                     event = 'change_state'
       
    51                     change = (event,
       
    52                               (entity.wf_info_for[0],
       
    53                                entity.from_state[0], entity.to_state[0]))
       
    54                     changes.append(change)
       
    55         elif event == 'delete_entity':
    42         elif event == 'delete_entity':
    56             deleted.add(changedescr[0])
    43             deleted.add(changedescr[0])
    57         index.setdefault(event, set()).add(change)
    44         index.setdefault(event, set()).add(change)
       
    45     for key in ('delete_relation', 'add_relation'):
       
    46         for change in index.get(key, {}).copy():
       
    47             if change[1].rtype == 'in_state':
       
    48                 index[key].remove(change)
    58     # filter changes
    49     # filter changes
    59     for eid in added:
    50     for eid in added:
    60         try:
    51         try:
    61             for change in index['add_relation'].copy():
    52             for change in index['add_relation'].copy():
    62                 changedescr = change[1]
    53                 changedescr = change[1]
    63                 # skip meta-relations which are set automatically
    54                 # skip meta-relations which are set automatically
    64                 # XXX generate list below using rtags (category = 'generated')
    55                 # XXX generate list below using rtags (category = 'generated')
    65                 if changedescr.rtype in ('created_by', 'owned_by', 'is', 'is_instance_of',
    56                 if changedescr.rtype in ('created_by', 'owned_by', 'is', 'is_instance_of',
    66                                       'from_state', 'to_state', 'wf_info_for',) \
    57                                       'from_state', 'to_state', 'by_transition',
       
    58                                       'wf_info_for') \
    67                        and changedescr.eidfrom == eid:
    59                        and changedescr.eidfrom == eid:
    68                     index['add_relation'].remove(change)
    60                     index['add_relation'].remove(change)
    69                 # skip in_state relation if the entity is being created
       
    70                 # XXX this may be automatized by skipping all mandatory relation
       
    71                 #     at entity creation time
       
    72                 elif changedescr.rtype == 'in_state' and changedescr.eidfrom in added:
       
    73                     index['add_relation'].remove(change)
       
    74 
       
    75         except KeyError:
    61         except KeyError:
    76             break
    62             break
    77     for eid in deleted:
    63     for eid in deleted:
    78         try:
    64         try:
    79             for change in index['delete_relation'].copy():
    65             for change in index['delete_relation'].copy():