Get label files from project and attach to job want full project_directory object for label_file_colour_map A key part of the rationale here is that a job may have labels that are distinct from the project. Main point of having this here is flexability that if we chan
(session,
task_template,
project_directory=None,
)
| 15 | |
| 16 | |
| 17 | def task_template_label_attach(session, |
| 18 | task_template, |
| 19 | project_directory=None, |
| 20 | ): |
| 21 | """ |
| 22 | Get label files from project and attach |
| 23 | to job |
| 24 | |
| 25 | want full project_directory object for label_file_colour_map |
| 26 | |
| 27 | A key part of the rationale here is that a |
| 28 | job may have labels that are distinct from the project. |
| 29 | |
| 30 | Main point of having this here is flexability that |
| 31 | if we change the way we represent jobs, we don't have to change |
| 32 | the "upfront" logic in terms of attach ids. |
| 33 | ie decouple which ids are attached to a job to whatever muck we |
| 34 | need to do at launch time / "run" time. |
| 35 | |
| 36 | """ |
| 37 | |
| 38 | if task_template.label_mode == "closed_all_available": |
| 39 | |
| 40 | label_file_list_serialized = [] |
| 41 | |
| 42 | # Provided |
| 43 | label_file_list = task_template.label_dict.get('label_file_list') |
| 44 | |
| 45 | if label_file_list: |
| 46 | file_list = File.get_by_id_list(session, label_file_list) |
| 47 | |
| 48 | else: |
| 49 | # Temporary fall back for migration |
| 50 | file_list = WorkingDirFileLink.file_list( |
| 51 | session=session, |
| 52 | working_dir_id=project_directory.id, |
| 53 | limit=25, |
| 54 | type="label") |
| 55 | |
| 56 | # Store for future reference here |
| 57 | task_template.label_dict['label_file_list'] = [file.id for file in file_list] |
| 58 | |
| 59 | # Work |
| 60 | for file in file_list: |
| 61 | file_serialized = file.serialize_with_label_and_colour(session=session) |
| 62 | |
| 63 | # Make sure time stamps are wrapped in str() to avoid nested json / dict issues |
| 64 | |
| 65 | label_file_list_serialized.append(file_serialized) |
| 66 | |
| 67 | # For debugging issue with serailization here. |
| 68 | # print(label_file_list_serialized) |
| 69 | |
| 70 | task_template.label_dict['label_file_list_serialized'] = label_file_list_serialized |
| 71 | |
| 72 | # Now in context of users being able to choose labels, |
| 73 | # We rebuild this on launching |
| 74 |
no test coverage detected