1010from activity_browser .ui .widgets import (ActivityLinkingDialog ,
1111 ActivityLinkingResultsDialog )
1212
13-
1413class ActivityRelink (ABAction ):
1514 """
1615 ABAction to relink the exchanges of an activity to exchanges from another database.
1716
18- This action only uses the first key from activity_keys
17+ This action only uses the first key from activity_keys.
18+ Only shows databases relevant to activity.
1919 """
2020
2121 icon = qicons .edit
@@ -31,8 +31,10 @@ def run(activity_keys: List[tuple]):
3131 db = bd .Database (key [0 ])
3232 activity = bd .get_activity (key )
3333
34- # find the dependents for the database and construct the alternatives in tuple format
35- depends = db .find_dependents ()
34+ # find the dependents for the activity using bw2data method and construct the alternatives in tuple format
35+ data = {}
36+ data [activity .key ] = db .load ()[activity .key ]
37+ depends = db .find_dependents (data = data , ignore = [db .name ])
3638 options = [(depend , list (bd .databases )) for depend in depends ]
3739
3840 # present the alternatives to the user in a linking dialog
@@ -49,16 +51,15 @@ def run(activity_keys: List[tuple]):
4951
5052 # use the relink_activity_exchanges strategy to relink the exchanges of the activity
5153 relinking_results = {}
54+ failed = 0
5255 for old , new in dialog .relink .items ():
5356 other = bd .Database (new )
5457 failed , succeeded , examples = relink_activity_exchanges (
5558 activity , old , other
5659 )
5760 relinking_results [f"{ old } --> { other .name } " ] = (failed , succeeded )
58-
5961 # restore normal cursor
6062 QtWidgets .QApplication .restoreOverrideCursor ()
61-
6263 # if any relinks failed present them to the user
6364 if failed > 0 :
6465 relinking_dialog = ActivityLinkingResultsDialog .present_relinking_results (
0 commit comments