Skip to content

Commit 66a7ea8

Browse files
Don't filter out codes when loaded from process
1 parent efc548d commit 66a7ea8

4 files changed

Lines changed: 41 additions & 31 deletions

File tree

src/aiidalab_qe/app/submission/model.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import ipywidgets as ipw
43
import traitlets as tl
54
from IPython.display import Javascript, display
65

@@ -64,6 +63,7 @@ def confirm(self):
6463
super().confirm()
6564
if not self.has_process:
6665
self._submit()
66+
self.lock()
6767

6868
def _update(self, specific=""):
6969
self.update_process_label()
@@ -150,7 +150,10 @@ def update_process_metadata(self):
150150
return
151151
self.process_label = self.process.label
152152
self.process_description = self.process.description
153-
self.locked = True
153+
154+
def refresh_codes(self, filter_codes_for_user: bool = True):
155+
for _, resource_model in self.get_models():
156+
resource_model.refresh_codes(filter_codes_for_user=filter_codes_for_user)
154157

155158
def get_model_state(self) -> dict:
156159
return {
@@ -207,20 +210,6 @@ def _submit(self):
207210
pk = process_node.pk
208211
display(Javascript(f"window.history.pushState(null, '', '?pk={pk}');"))
209212

210-
def _link_model(self, model: ResourceSettingsModel):
211-
for dependency in model.dependencies:
212-
dependency_parts = dependency.split(".")
213-
if len(dependency_parts) == 1: # from parent, e.g. input_structure
214-
target_model = self
215-
trait = dependency
216-
else: # from sibling, e.g. workchain.protocol
217-
sibling, trait = dependency_parts
218-
target_model = self.get_model(sibling)
219-
ipw.dlink(
220-
(target_model, trait),
221-
(model, trait),
222-
)
223-
224213
def _get_properties(self) -> list[str]:
225214
return self.input_parameters.get("workchain", {}).get("properties", [])
226215

src/aiidalab_qe/app/wizard/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def load_from_state(self, state: dict):
4545
SubmissionStepModel,
4646
self.get_model("submit"),
4747
)
48+
if process_uuid is not None:
49+
submission_model.refresh_codes(filter_codes_for_user=False)
4850
submission_model.set_model_state(resources_state)
4951

5052
if step_index >= 3:

src/aiidalab_qe/common/code/model.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ def activate(self):
6868
def deactivate(self):
6969
self.is_active = False
7070

71-
def update(self, user_email: str, default_code=None, refresh=False):
71+
def update(
72+
self,
73+
user_email: str,
74+
default_code: str | None = None,
75+
filter_codes_for_user: bool = True,
76+
refresh: bool = False,
77+
):
7278
if not self.options or refresh:
73-
self.options = self._get_codes(user_email)
79+
self.options = self._get_codes(user_email, filter_codes_for_user)
7480
if default_code:
7581
try:
7682
selected = orm.load_code(default_code).uuid
@@ -115,7 +121,11 @@ def _get_uuid(self, identifier):
115121
# in the app and thus will not be considered as an option!
116122
return uuid if uuid in [opt[1] for opt in self.options] else None
117123

118-
def _get_codes(self, user_email: str):
124+
def _get_codes(
125+
self,
126+
user_email: str,
127+
filter_codes_for_user: bool = True,
128+
) -> list[tuple[str, str]]:
119129
user = orm.User.collection.get(email=user_email)
120130

121131
filters = (
@@ -124,25 +134,33 @@ def _get_codes(self, user_email: str):
124134
else {}
125135
)
126136

127-
codes = (
128-
orm.QueryBuilder()
129-
.append(
130-
orm.Code,
131-
filters=filters,
132-
)
133-
.all(flat=True)
137+
codes = t.cast(
138+
list[orm.Code],
139+
(
140+
orm.QueryBuilder()
141+
.append(
142+
orm.Code,
143+
filters=filters,
144+
)
145+
.all(flat=True)
146+
),
134147
)
135148

136149
return [
137150
(self._full_code_label(code), code.uuid)
138151
for code in codes
139-
if code.computer.is_user_configured(user)
140-
and (self.allow_hidden_codes or not code.is_hidden)
141-
and (self.allow_disabled_computers or code.computer.is_user_enabled(user))
152+
if not filter_codes_for_user
153+
or (
154+
code.computer.is_user_configured(user)
155+
and (self.allow_hidden_codes or not code.is_hidden)
156+
and (
157+
self.allow_disabled_computers or code.computer.is_user_enabled(user)
158+
)
159+
)
142160
]
143161

144162
@staticmethod
145-
def _full_code_label(code):
163+
def _full_code_label(code: orm.Code) -> str:
146164
return f"{code.label}@{code.computer.label}"
147165

148166

src/aiidalab_qe/common/panel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ def update_active_codes(self):
172172
else:
173173
code_model.deactivate()
174174

175-
def refresh_codes(self):
175+
def refresh_codes(self, filter_codes_for_user: bool = True):
176176
for _, code_model in self.get_models():
177177
code_key = code_model.default_calc_job_plugin.split(".")[-1]
178178
code_model.update(
179179
user_email=self.default_user_email,
180180
default_code=self.default_codes.get(code_key, {}).get("code"),
181+
filter_codes_for_user=filter_codes_for_user,
181182
refresh=True,
182183
)
183184

0 commit comments

Comments
 (0)