Commit 0a1f0e75d3a50c700e0a0a866ad3f9209d19c21a

Authored by pyros_astroguita
1 parent 673ff098
Exists in dev

update quota view

src/core/pyros_django/scp_mgmt/templates/scp_mgmt/quota_sp.html
@@ -91,9 +91,9 @@ @@ -91,9 +91,9 @@
91 <td>{{institute.quota.d_nextq}}</td> 91 <td>{{institute.quota.d_nextq}}</td>
92 <td>{{institute.quota.d_nextx}}</td> 92 <td>{{institute.quota.d_nextx}}</td>
93 </tr> 93 </tr>
94 - {% for sp in institute.scientific_programs.all %} 94 + {% for sp in sp_periods_per_institute|get_item:institute.name %}
95 <tr class="sp"> 95 <tr class="sp">
96 - <td>Scientific program: {{sp.name}} </td> 96 + <td>Scientific program: {{sp.scientific_program.name}} </td>
97 <td>{{sp.quota_f}} </td> 97 <td>{{sp.quota_f}} </td>
98 <td> <b>{{sp.quota.d_total}}</b> </td> 98 <td> <b>{{sp.quota.d_total}}</b> </td>
99 <td>{{sp.quota.d_totalq}}</td> 99 <td>{{sp.quota.d_totalq}}</td>
@@ -119,6 +119,35 @@ @@ -119,6 +119,35 @@
119 <td>{{sp.quota.d_nextq}}</td> 119 <td>{{sp.quota.d_nextq}}</td>
120 <td>{{sp.quota.d_nextx}}</td> 120 <td>{{sp.quota.d_nextx}}</td>
121 </tr> 121 </tr>
  122 + {% for sequence in sequences|get_item:sp.scientific_program.name %}
  123 + <tr class="sequence">
  124 + <td> Sequence: {{sequence.name}} </td>
  125 + <td> </td>
  126 + <td> <b>{{sequence.quota.d_total}}</b> </td>
  127 + <td>{{sequence.quota.d_totalq}}</td>
  128 + <td>{{sequence.quota.d_totalx}}</td>
  129 +
  130 + <td> <b>{{sequence.quota.d_previous}}</b> </td>
  131 + <td>{{sequence.quota.d_previousq}}</td>
  132 + <td>{{sequence.quota.d_previousx}}</td>
  133 +
  134 + <td> <b>{{sequence.quota.d_current}}</b> </td>
  135 + <td>{{sequence.quota.d_currentq}}</td>
  136 + <td>{{sequence.quota.d_currentx}}</td>
  137 +
  138 + <td> <b>{{sequence.quota.d_passed}}</b> </td>
  139 + <td>{{sequence.quota.d_passedq}}</td>
  140 + <td>{{sequence.quota.d_passedx}}</td>
  141 +
  142 + <td> <b>{{sequence.quota.d_schedule}}</b> </td>
  143 + <td>{{sequence.quota.d_scheduleq}}</td>
  144 + <td>{{sequence.quota.d_schedulex}} </td>
  145 +
  146 + <td> <b>{{sequence.quota.d_next}}</b> </td>
  147 + <td>{{sequence.quota.d_nextq}}</td>
  148 + <td>{{sequence.quota.d_nextx}}</td>
  149 + </tr>
  150 + {% endfor %}
122 {% endfor %} 151 {% endfor %}
123 152
124 {% endfor %} 153 {% endfor %}
src/core/pyros_django/scp_mgmt/views.py
@@ -21,7 +21,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger @@ -21,7 +21,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
21 # Project imports 21 # Project imports
22 from dashboard.config_pyros import ConfigPyros 22 from dashboard.config_pyros import ConfigPyros
23 from .functions import get_global_svg_timeline, get_svg_timeline, get_proposal_svg_timeline 23 from .functions import get_global_svg_timeline, get_svg_timeline, get_proposal_svg_timeline
24 -from user_mgmt.models import ScientificProgram, Institute, Period, SP_Period_User, SP_Period, PyrosUser, SP_Period_Guest, ScienceTheme #, UserLevel 24 +from user_mgmt.models import ScientificProgram, Institute, Period, SP_Period_User, SP_Period, PyrosUser, SP_Period_Guest, ScienceTheme, UserLevel #, UserLevel
25 from seq_submit.models import Sequence, Quota 25 from seq_submit.models import Sequence, Quota
26 #from src.core.pyros_django import scientific_program 26 #from src.core.pyros_django import scientific_program
27 from .forms import PeriodForm, ScienceThemeForm, ScientificProgramForm, InstituteForm, SP_PeriodForm,TACAssociationForm 27 from .forms import PeriodForm, ScienceThemeForm, ScientificProgramForm, InstituteForm, SP_PeriodForm,TACAssociationForm
@@ -810,11 +810,31 @@ def institute_list(request): @@ -810,11 +810,31 @@ def institute_list(request):
810 @login_required 810 @login_required
811 @level_required("Admin", "Unit-PI", "Observer", "Operator", "TAC", "Management board member") 811 @level_required("Admin", "Unit-PI", "Observer", "Operator", "TAC", "Management board member")
812 def quota_sp(request): 812 def quota_sp(request):
813 - institutes = Institute.objects.all()  
814 - scientific_programs = ScientificProgram.objects.all()  
815 config = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"]) 813 config = OBSConfig(os.environ["PATH_TO_OBSCONF_FILE"],os.environ["unit_name"])
  814 + CAN_VIEW_ALL_QUOTA = request.session.get("role") in ("Admin", "Unit-PI", "Unit-board", "Management board member")
816 current_night = config.fn.date2night("now") 815 current_night = config.fn.date2night("now")
817 current_period = Period.objects.exploitation_period() 816 current_period = Period.objects.exploitation_period()
  817 + sp_periods_per_institute = {}
  818 + if CAN_VIEW_ALL_QUOTA:
  819 + institutes = Institute.objects.all()
  820 + sp_period = SP_Period.objects.filter(period=current_period)
  821 + else:
  822 + user_sp = request.user.get_scientific_programs()
  823 + sp_period = SP_Period.objects.filter(scientific_program__in=user_sp, period=current_period)
  824 + institutes = []
  825 + # regroup sp_period per institute
  826 + for sp in sp_period:
  827 + if sp_periods_per_institute.get(sp.scientific_program.institute.name) is None:
  828 + sp_periods_per_institute[sp.scientific_program.institute.name] = []
  829 + if sp not in sp_periods_per_institute.get(sp.scientific_program.institute.name):
  830 + sp_periods_per_institute[sp.scientific_program.institute.name].append(sp)
  831 + sequences = {}
  832 + # regroup institutes and regroup sequence per scientific_program
  833 + for institute, sp_list in sp_periods_per_institute.items():
  834 + if not CAN_VIEW_ALL_QUOTA and institute not in institutes:
  835 + institutes.append(Institute.objects.get(name=institute))
  836 + for sp_period in sp_list:
  837 + sequences[sp_period.scientific_program.name] = sp_period.scientific_program.sequences.all()
818 # lowest id is period line 838 # lowest id is period line
819 quota_current_night = Quota.objects.filter(id_period=current_period.id, night_id=current_night).order_by("id").first() 839 quota_current_night = Quota.objects.filter(id_period=current_period.id, night_id=current_night).order_by("id").first()
820 return render(request, 'scp_mgmt/quota_sp.html', locals()) 840 return render(request, 'scp_mgmt/quota_sp.html', locals())