From 0a1f0e75d3a50c700e0a0a866ad3f9209d19c21a Mon Sep 17 00:00:00 2001 From: pyros_astroguita Date: Fri, 20 Oct 2023 17:19:25 +0200 Subject: [PATCH] update quota view --- src/core/pyros_django/scp_mgmt/templates/scp_mgmt/quota_sp.html | 33 +++++++++++++++++++++++++++++++-- src/core/pyros_django/scp_mgmt/views.py | 26 +++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/core/pyros_django/scp_mgmt/templates/scp_mgmt/quota_sp.html b/src/core/pyros_django/scp_mgmt/templates/scp_mgmt/quota_sp.html index aa33038..3358aec 100644 --- a/src/core/pyros_django/scp_mgmt/templates/scp_mgmt/quota_sp.html +++ b/src/core/pyros_django/scp_mgmt/templates/scp_mgmt/quota_sp.html @@ -91,9 +91,9 @@ {{institute.quota.d_nextq}} {{institute.quota.d_nextx}} - {% for sp in institute.scientific_programs.all %} + {% for sp in sp_periods_per_institute|get_item:institute.name %} - Scientific program: {{sp.name}} + Scientific program: {{sp.scientific_program.name}} {{sp.quota_f}} {{sp.quota.d_total}} {{sp.quota.d_totalq}} @@ -119,6 +119,35 @@ {{sp.quota.d_nextq}} {{sp.quota.d_nextx}} + {% for sequence in sequences|get_item:sp.scientific_program.name %} + + Sequence: {{sequence.name}} + + {{sequence.quota.d_total}} + {{sequence.quota.d_totalq}} + {{sequence.quota.d_totalx}} + + {{sequence.quota.d_previous}} + {{sequence.quota.d_previousq}} + {{sequence.quota.d_previousx}} + + {{sequence.quota.d_current}} + {{sequence.quota.d_currentq}} + {{sequence.quota.d_currentx}} + + {{sequence.quota.d_passed}} + {{sequence.quota.d_passedq}} + {{sequence.quota.d_passedx}} + + {{sequence.quota.d_schedule}} + {{sequence.quota.d_scheduleq}} + {{sequence.quota.d_schedulex}} + + {{sequence.quota.d_next}} + {{sequence.quota.d_nextq}} + {{sequence.quota.d_nextx}} + + {% endfor %} {% endfor %} {% endfor %} diff --git a/src/core/pyros_django/scp_mgmt/views.py b/src/core/pyros_django/scp_mgmt/views.py index 67667a8..2825341 100644 --- a/src/core/pyros_django/scp_mgmt/views.py +++ b/src/core/pyros_django/scp_mgmt/views.py @@ -21,7 +21,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger # Project imports from dashboard.config_pyros import ConfigPyros from .functions import get_global_svg_timeline, get_svg_timeline, get_proposal_svg_timeline -from user_mgmt.models import ScientificProgram, Institute, Period, SP_Period_User, SP_Period, PyrosUser, SP_Period_Guest, ScienceTheme #, UserLevel +from user_mgmt.models import ScientificProgram, Institute, Period, SP_Period_User, SP_Period, PyrosUser, SP_Period_Guest, ScienceTheme, UserLevel #, UserLevel from seq_submit.models import Sequence, Quota #from src.core.pyros_django import scientific_program from .forms import PeriodForm, ScienceThemeForm, ScientificProgramForm, InstituteForm, SP_PeriodForm,TACAssociationForm @@ -810,11 +810,31 @@ def institute_list(request): @login_required @level_required("Admin", "Unit-PI", "Observer", "Operator", "TAC", "Management board member") def quota_sp(request): - institutes = Institute.objects.all() - scientific_programs = ScientificProgram.objects.all() config = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) + CAN_VIEW_ALL_QUOTA = request.session.get("role") in ("Admin", "Unit-PI", "Unit-board", "Management board member") current_night = config.fn.date2night("now") current_period = Period.objects.exploitation_period() + sp_periods_per_institute = {} + if CAN_VIEW_ALL_QUOTA: + institutes = Institute.objects.all() + sp_period = SP_Period.objects.filter(period=current_period) + else: + user_sp = request.user.get_scientific_programs() + sp_period = SP_Period.objects.filter(scientific_program__in=user_sp, period=current_period) + institutes = [] + # regroup sp_period per institute + for sp in sp_period: + if sp_periods_per_institute.get(sp.scientific_program.institute.name) is None: + sp_periods_per_institute[sp.scientific_program.institute.name] = [] + if sp not in sp_periods_per_institute.get(sp.scientific_program.institute.name): + sp_periods_per_institute[sp.scientific_program.institute.name].append(sp) + sequences = {} + # regroup institutes and regroup sequence per scientific_program + for institute, sp_list in sp_periods_per_institute.items(): + if not CAN_VIEW_ALL_QUOTA and institute not in institutes: + institutes.append(Institute.objects.get(name=institute)) + for sp_period in sp_list: + sequences[sp_period.scientific_program.name] = sp_period.scientific_program.sequences.all() # lowest id is period line quota_current_night = Quota.objects.filter(id_period=current_period.id, night_id=current_night).order_by("id").first() return render(request, 'scp_mgmt/quota_sp.html', locals()) -- libgit2 0.21.2