From 2c98ce2f0fbadca81f99a11fdf924e145e16d52b Mon Sep 17 00:00:00 2001 From: luissian Date: Sat, 28 Sep 2024 12:45:30 +0200 Subject: [PATCH] solved issue #300 Error when sample proyects has no parameters --- .github/workflows/python_lint.yml | 2 +- core/utils/samples.py | 11 ++++++++--- wetlab/views.py | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python_lint.yml b/.github/workflows/python_lint.yml index 82357e97..128c97c9 100644 --- a/.github/workflows/python_lint.yml +++ b/.github/workflows/python_lint.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: python-version: 3.9.x architecture: x64 diff --git a/core/utils/samples.py b/core/utils/samples.py index 6fbf59ff..a2a0dbf1 100644 --- a/core/utils/samples.py +++ b/core/utils/samples.py @@ -173,13 +173,18 @@ def save_recorded_samples(samples_data, req_user, app_name): sample["sample_project"] = core.models.SampleProjects.objects.get( sample_project_name__exact=sample["sample_project"] ) - # If only recorded set sample to completed state if sample["only_recorded"] and sample["sample_project"] is None: sample["sample_state"] = "Completed" sample["completed_date"] = datetime.datetime.now() - # If no sample project data needed set to defined - elif sample["sample_project"] is None: + # If no sample project data needed or sample projects has no parameters + # then set the sample state to defined + elif ( + sample["sample_project"] is None + or core.models.SampleProjects.objects.filter( + sample_project_name__exact=sample["sample_project"] + ).exists() + ): sample["sample_state"] = "Defined" else: sample["sample_state"] = "Pre-Defined" diff --git a/wetlab/views.py b/wetlab/views.py index 7dbf4fb2..eb3fa039 100644 --- a/wetlab/views.py +++ b/wetlab/views.py @@ -2225,7 +2225,13 @@ def record_samples(request): sample["sample_project"] not in project_ids and sample["sample_project"] is not None ): - project_ids.append(sample["sample_project"]) + # check if sample project has defined parameters + if core.models.SampleProjectsFields.objects.filter( + sample_projects_id__sample_project_name__exact=sample[ + "sample_project" + ] + ).exists(): + project_ids.append(sample["sample_project"]) # If no sample Pre-Defined just show result if not project_ids: return render(