Commit 641ec71764d3dde96d3fdd9468f9b0163e93ab3e

Authored by Alexis Koralewski
1 parent 53ce3372
Exists in dev

add form to associate TAC users to scientific programs

src/core/pyros_django/scientific_program/forms.py
... ... @@ -68,4 +68,28 @@ class InstituteForm(forms.ModelForm):
68 68 class ScienceThemeForm(forms.ModelForm):
69 69 class Meta:
70 70 model = ScienceTheme
71   - fields = "__all__"
72 71 \ No newline at end of file
  72 + fields = "__all__"
  73 +
  74 +class TACAssociationForm(forms.ModelForm):
  75 + #tac_referees = forms.ModelMultipleChoiceField(queryset=None,widget=forms.CheckboxSelectMultiple())
  76 + class Meta:
  77 + model = SP_Period
  78 + fields = ["referee1","referee2"]
  79 +
  80 +
  81 + def clean(self):
  82 + super(TACAssociationForm, self).clean()
  83 + referee1 = self.cleaned_data.get("referee1")
  84 + referee2 = self.cleaned_data.get("referee2")
  85 + if referee1 == referee2:
  86 + self._errors['referee2'] = self.error_class([
  87 + 'Referee 2 must be different of referee 1'])
  88 + if referee1 == None:
  89 + self._errors['referee1'] = self.error_class([
  90 + 'Choose someone as referee 1'])
  91 + if referee2 == None:
  92 + self._errors['referee2'] = self.error_class([
  93 + 'Choose someone as referee 2'])
  94 + return self.cleaned_data
  95 +
  96 +
73 97 \ No newline at end of file
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/associate_tac_to_sp.html 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +{% extends 'base.html' %}
  2 +
  3 +{% block content %}
  4 +
  5 +<form id="associate_tac_to_sp_form" action="" method="post">
  6 + {% csrf_token %}
  7 + {{ form.as_p }}
  8 + <input id="submit" class="btn btn-info" type="submit" value="Submit" />
  9 + <a href="{% url "list_drafted_scientific_program" %}" class="btn btn-info" role="button">Cancel</a>
  10 +</form>
  11 +
  12 +{% endblock %}
0 13 \ No newline at end of file
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/index.html
... ... @@ -240,95 +240,7 @@ p{
240 240 {{ svg|safe }}
241 241  
242 242 <div id="detail_proposal_period"></div>
243   - {% comment %}
244   - <div id="timeline">
245   - <div id="life">
246   -
247   - {% if current_period.submission_start_date <= today and current_period.start_date >= today %}
248   - <section class="date" style="left: 15.5vw;color:red;top:1vw">today({{ today }})</section>
249   -
250   - {% elif current_period.start_date <= today and current_period.end_date >= today %}
251   - <section class="date" style="left: 44.5vw;color:red;top:1vw">today({{ today }})</section>
252   - {% elif current_period.end_date <= today and current_period.property_of_data_end_date >= today %}
253   - <section class="date" style="left: 55.5vw;color:red;top:1vw">today({{ today }})</section>
254   - {% elif current_period.property_of_data_end_date <= today %}
255   - <section class="date" style="left: 75.5vw;color:red;top:1vw">today({{ today }})</section>
256   - {% endif %}
257   - <section class="date" style="left: 19.5vw">{{ current_period.submission_start_date}}</section>
258   - <section class="date" style="left: 41.5vw">{{ current_period.start_date }}</section>
259   - <section class="date" style="left: 64.5vw">{{ current_period.end_date }}</section>
260   - <section class="date" style="left: 86.5vw">{{ current_period.property_of_data_end_date }}</section>
261   - </div>
262   - </div>
263   - {% endcomment %}
264   - {% comment %}
265   -
266   - <table id="table_dates">
267   - <tr>
268   - <td>
269   - {{ current_period.submission_start_date}}
270   - </td>
271   - <td>
272   - {{ current_period.start_date}}
273   - </td>
274   - <td>
275   - {{ current_period.end_date}}
276   - </td>
277   - <td colspan="2">
278   - {{ current_period.property_of_data_end_date}}
279   - </td>
280   - </tr>
281   - </table>
282   - <table id="table_period">
283   - <tbody>
284   - {% if previous_period %}
285   - <tr>
286   - <td>P{{previous_period.id}}</td>
287   - <td class="old">Exploitation</td>
288   - <td colspan="2" class="current">Data access</td>
289   - </tr>
290   - {% endif %}
291   - {% if current_period %}
292   - <tr>
293   - <td>P{{current_period.id}}</td>
294   - <td class="old"> Proposal </td>
295   - <td class="current"> Exploitation </td>
296   - <td class="future"> Data access </td>
297   - </tr>
298   - {% endif %}
299   - {% if future_period %}
300   - <tr>
301   - <td>P{{future_period.id}}</td>
302   - <td class="old"></td>
303   - <td class="current"> Proposal </td>
304   - <td class="future"> Exploitation </td>
305   - </tr>
306   - {% endif %}
307   - </tbody>
308   - </table>
309   - {% if future_period %}
310   - <div class="container">
311   - <h3>For next period : {{ future_period }}</h3>
312   - <ul class="progressbar">
313   - {% if future_period.submission_start_date|is_past_due %}
314   - <li class="active">{{ future_period.submission_start_date }} Submission start </li>
315   - {% else %}
316   - <li>{{ future_period.submission_start_date }} Submission start </li=>
317   - {% endif %}
318   - {% if future_period.submission_end_date|is_past_due %}
319   - <li class="active">{{ future_period.submission_end_date }} Submission end </li>
320   - {% else %}
321   - <li>{{ future_period.submission_end_date }} Submission end </li>
322   - {% endif %}
323   - {% if future_period.unit_pi_validation_start_date|is_past_due %}
324   - <li class="active">{{ future_period.unit_pi_validation_start_date }} Proposal validation date</li>
325   - {% else %}
326   - <li> {{ future_period.unit_pi_validation_start_date }} Proposal validation date</li>
327   - {% endif %}
328   - </ul>
329   - </div>
330   - {% endif %}
331   - {% endcomment %}
  243 +
332 244 <h3> Current exploitation Exploitation Period : {{current_period}}</h3>
333 245 <div class="all-grid d-flex flex-column">
334 246 {% if CAN_EVALUATE_SP or CAN_VALIDATE_SP %}
... ... @@ -343,6 +255,12 @@ p{
343 255 </li>
344 256 {% endif %}
345 257 {% endif %}
  258 + {% if CAN_ASSOCIATE_TAC_TO_SP %}
  259 + <p> Associate TAC to scientific programs</p>
  260 + <li>
  261 + <a href="{% url 'list_drafted_scientific_program' %}">SP validation</a>
  262 + </li>
  263 + {% endif %}
346 264 {% if CAN_SUBMIT_SP %}
347 265 <p> SP Submission </p>
348 266 <li>
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/list_of_scientific_program_select.html
... ... @@ -28,7 +28,9 @@
28 28 {# SUBMIT SP AGAIN FOR A NEW PERIOD but we're using SP_Period objects #}
29 29 <li><a href="{% url 'repropose_scientific_program' id_SP=sp.scientific_program.id id_SP_Period=sp.id %}"> {{ sp.scientific_program.name }} </a></li>
30 30 {% endif %}
31   -
  31 + {% elif associate_tac_to_sp %}
  32 + {# ASSOCIATE TAC USERS TO SP FOR NEXT PERIOD #}
  33 + <li><a href="{% url 'associate_tac_to_scientific_program' id_sp=sp.scientific_program.id id_period=sp.period.id %}"> {{ sp.scientific_program.name }} </a></li>
32 34 {% else %}
33 35 <li><a href="{% url 'edit_scientific_program_period' id_sp=sp.scientific_program.id id_period=sp.period.id %}"> {{ sp.scientific_program.name }} </a></li>
34 36 {% endif %}
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_detail_edit.html
... ... @@ -55,7 +55,7 @@
55 55 {% endif %}
56 56 {% endif %}
57 57 {% elif "referee2" in field.label_tag %}
58   - {% if SP_PeriodForm.reason_referee1.value != "" and SP_PeriodForm.reason_referee2.value == "" %}
  58 + {% if SP_PeriodForm.reason_referee1.value != "" and SP_PeriodForm.reason_referee2.value == "" and request.user != sp_period.referee1 %}
59 59 {% if sp_period.status == "Submitted" and USER_LEVEL|ifinlist:"TAC,Admin"%}
60 60 <div class="fieldWrapper">
61 61 {{ field.label_tag }} {{ field }}
... ...
src/core/pyros_django/scientific_program/templates/scientific_program/scientific_program_period_detail.html
... ... @@ -21,10 +21,10 @@
21 21 <p><strong>Token: </strong>{{ sp_period.token }}</p>
22 22 {% if CAN_VIEW_TAC_VOTES %}
23 23 {% if sp_period.referee1 != None %}
24   - <p><strong>Vote referee 1: </strong>{{ sp_period.vote_referee1 }} </p> <p> <strong> Reason: </strong> {{ sp_period.reason_referee1 }} </p> <p> <strong> Referee 1: </strong>{{ sp_period.referee1.first_name }} {{ sp_period.referee1.last_name}} </p>
  24 + <p> <strong> Referee 1: </strong>{{ sp_period.referee1.first_name }} {{ sp_period.referee1.last_name}} </p> <p><strong>Vote referee 1: </strong>{{ sp_period.vote_referee1 }} </p> <p> <strong> Reason: </strong> {{ sp_period.reason_referee1 }} </p>
25 25 {% endif %}
26 26 {% if sp_period.referee2 != None %}
27   - <p><strong>Vote referee 2: </strong>{{ sp_period.vote_referee1 }} </p> <p> <strong> Reason: </strong> {{ sp_period.reason_referee1 }} </p> <p> <strong> Referee 2: </strong> {{ sp_period.referee1.first_name }} {{ sp_period.referee1.last_name}} </p>
  27 + <p> <strong> Referee 2: </strong> {{ sp_period.referee2.first_name }} {{ sp_period.referee2.last_name}} </p> <p><strong>Vote referee 2: </strong>{{ sp_period.vote_referee2 }} </p> <p> <strong> Reason: </strong> {{ sp_period.reason_referee2 }} </p>
28 28 {% endif %}
29 29 {% endif %}
30 30 {% if sp_period.status in "Accepted,Rejected" %}
... ...
src/core/pyros_django/scientific_program/urls.py
... ... @@ -15,6 +15,7 @@ urlpatterns = [
15 15 path('delete_scientific_program_period/<int:id_sp>/<int:id_period>', views.delete_scientific_program_period,name='delete_scientific_program_period'),
16 16 path('delete_scientific_program/<int:id_sp>', views.delete_scientific_program,name='delete_scientific_program'),
17 17 path('submit_proposal/<int:id>/',views.submit_proposal,name="submit_proposal"),
  18 + path('associate_tac_to_scientific_program/<int:id_sp>/<int:id_period>/',views.associate_tac_to_scientific_program,name="associate_tac_to_scientific_program"),
18 19 path('scientific_program_list', views.scientific_program_list,name='scientific_program_list'),
19 20 path('own_scientific_program_list', views.own_scientific_program_list,name='own_scientific_program_list'),
20 21 path('detail_scientific_program/<int:id>/', views.detail_scientific_program,name='detail_scientific_program'),
... ... @@ -22,6 +23,7 @@ urlpatterns = [
22 23 path("list_submitted_scientific_program",views.list_submitted_scientific_program,name="list_submitted_scientific_program"),
23 24 path("list_scientific_program_as_template",views.list_scientific_program_as_template,name="list_scientific_program_as_template"),
24 25 path("list_scientific_program_period_repropose",views.list_scientific_program_period_repropose,name="list_scientific_program_period_repropose"),
  26 + path("list_drafted_scientific_program",views.list_drafted_scientific_program,name="list_drafted_scientific_program"),
25 27 path("get_proposal_timeline",views.get_proposal_timeline,name="get_proposal_timeline"),
26 28 # institute
27 29 path('create_institute', views.create_institute,name='create_institute'),
... ...
src/core/pyros_django/scientific_program/views.py
... ... @@ -3,7 +3,7 @@ from src.core.pyros_django import scientific_program
3 3 from django.shortcuts import render, redirect, get_object_or_404, reverse
4 4 from django.contrib.auth import authenticate, login
5 5 from django.contrib.auth.decorators import login_required
6   -from .forms import PeriodForm, ScienceThemeForm, ScientificProgramForm, InstituteForm, SP_PeriodForm
  6 +from .forms import PeriodForm, ScienceThemeForm, ScientificProgramForm, InstituteForm, SP_PeriodForm,TACAssociationForm
7 7 from src.core.pyros_django.dashboard.decorator import level_required
8 8 from common.models import ScientificProgram, Institute, Period, SP_Period_User, SP_Period, PyrosUser, UserLevel, SP_Period_Guest, ScienceTheme
9 9 from django.http import HttpResponseRedirect
... ... @@ -65,6 +65,7 @@ def index_scientific_program(request):
65 65 CAN_VIEW_ALL_SP = request.session.get("role") in ("Admin","Unit-PI","Unit-board")
66 66 CAN_VIEW_EXPLOITATION_PERIOD = request.session.get("role") in ("Admin","Observer","Unit-PI","Unit-board")
67 67 CAN_CREATE_EXPLOITATION_PERIOD = request.session.get("role") in ("Admin","Unit-PI","Unit-board")
  68 + CAN_ASSOCIATE_TAC_TO_SP = request.session.get("role") in ("Admin","Unit-PI","Unit-board")
68 69 svg = get_svg_timeline(previous_period,current_period,future_period)
69 70 global_svg = get_global_svg_timeline(previous_period,current_period,future_period)
70 71 #global_svg = get_global_svg_timeline(current_period,current_period,future_period)
... ... @@ -83,7 +84,8 @@ def index_scientific_program(request):
83 84 "CAN_VIEW_SP": CAN_VIEW_SP,
84 85 "CAN_VIEW_EXPLOITATION_PERIOD": CAN_VIEW_EXPLOITATION_PERIOD,
85 86 "CAN_CREATE_EXPLOITATION_PERIOD": CAN_CREATE_EXPLOITATION_PERIOD,
86   - "CAN_VIEW_ALL_SP": CAN_VIEW_ALL_SP
  87 + "CAN_VIEW_ALL_SP": CAN_VIEW_ALL_SP,
  88 + "CAN_ASSOCIATE_TAC_TO_SP":CAN_ASSOCIATE_TAC_TO_SP
87 89 })
88 90  
89 91 @login_required
... ... @@ -229,6 +231,21 @@ def create_scientific_program_with_template(request, id_SP):
229 231 "SPForm": SP_form,
230 232 })
231 233  
  234 +
  235 +@login_required
  236 +@level_required("Admin","Unit-PI","Unit-board")
  237 +def list_drafted_scientific_program(request):
  238 + select_message = "Select an SP to associate TAC users to it for the incomming evaluation time"
  239 + none_message = f"There is no existing SP to be associated with TAC users for a new exploitation period"
  240 + non_autovalidated_sp = ScientificProgram.objects.exclude(is_auto_validated=True)
  241 + sp_periods_without_tac = SP_Period.objects.filter(scientific_program__in=non_autovalidated_sp,period=Period.objects.submission_periods().first()).filter(Q(referee1=None)|Q(referee2=None)).order_by("scientific_program__science_theme")
  242 + return render(request, "scientific_program/list_of_scientific_program_select.html", {
  243 + "select_message": select_message,
  244 + "none_message": none_message,
  245 + "list_of_sp": sp_periods_without_tac,
  246 + "associate_tac_to_sp":True
  247 + })
  248 +
232 249 @login_required
233 250 @level_required("Admin", "Observer")
234 251 def list_scientific_program_period_repropose(request):
... ... @@ -373,7 +390,30 @@ def accept_sp_invitation(request, id_SP, id_period):
373 390 SP_Period=sp_period, email=current_user.email).delete()
374 391 return HttpResponseRedirect(reverse("detail_scientific_program_period", kwargs={"id_sp": id_SP, "id_period": id_period}))
375 392 return HttpResponseRedirect(reverse("index"))
376   -
  393 +@login_required
  394 +@level_required("Admin", "Unit-PI", "Unit-board")
  395 +def associate_tac_to_scientific_program(request,id_sp,id_period):
  396 + scientific_program = ScientificProgram.objects.get(id=id_sp)
  397 + period = Period.objects.get(id=id_period)
  398 + sp_period = SP_Period.objects.get(scientific_program=scientific_program,period=period)
  399 + form = TACAssociationForm(request.POST or None,instance=sp_period)
  400 + tac_users_of_science_theme = PyrosUser.objects.filter(user_level__name="TAC",referee_themes=scientific_program.science_theme)
  401 + form.fields["referee1"].queryset = tac_users_of_science_theme
  402 + form.fields["referee2"].queryset = tac_users_of_science_theme
  403 + if request.POST:
  404 + form = TACAssociationForm(request.POST)
  405 + form.fields["referee1"].queryset = tac_users_of_science_theme
  406 + form.fields["referee2"].queryset = tac_users_of_science_theme
  407 + if form.is_valid():
  408 + referee1 = PyrosUser.objects.get(id=request.POST.get("referee1"))
  409 + referee2 = PyrosUser.objects.get(id=request.POST.get("referee2"))
  410 + sp_period.referee1 = referee1
  411 + sp_period.referee2 = referee2
  412 + sp_period.save()
  413 + return HttpResponseRedirect(reverse("list_drafted_scientific_program"))
  414 + return render(request,"scientific_program/associate_tac_to_sp.html",{
  415 + "form":form
  416 + })
377 417  
378 418 @level_required("Admin", "Unit-PI", "Observer", "TAC")
379 419 @login_required
... ... @@ -472,27 +512,25 @@ def edit_scientific_program_period(request, id_sp, id_period):
472 512 return redirect('detail_scientific_program_period', id_sp=scientific_program.id, id_period=id_period)
473 513 if SP_Period_form.is_valid() and request.session.get("role") == "TAC" and sp_period.status != SP_Period.STATUSES_DRAFT:
474 514 # vote TAC
475   - if sp_period.referee1 == None or sp_period.referee1 == request.user and request.POST.get("vote_referee1") and request.POST.get("reason_referee1"):
476   - tac = request.user.id
  515 + if sp_period.referee1 == request.user:
  516 + print("vote referee 1 ")
477 517 SP_Period_form.save(commit=False)
478 518 SP_Period_form.vote_referee1 = request.POST.get(
479 519 "vote_referee1")
480 520 SP_Period_form.reason_referee1 = request.POST.get(
481 521 "reason_referee1")
482 522 SP_Period_form.save()
483   - sp_period.referee1 = PyrosUser.objects.get(id=tac)
484 523 #if sp_period.referee2 != None:
485 524 #sp_period.status = SP_Period.STATUSES_EVALUATED
486 525 sp_period.save()
487   - if sp_period.referee1 != None and sp_period.referee2 == None or sp_period.referee2 == request.user and request.POST.get("vote_referee2") and len(request.POST.get("reason_referee2")) > 0:
488   - tac = request.user.id
  526 + if sp_period.referee2 == request.user:
  527 + print("vote referee 2 ")
489 528 SP_Period_form.save(commit=False)
490 529 SP_Period_form.vote_referee2 = request.POST.get(
491 530 "vote_referee2")
492 531 SP_Period_form.reason_referee2 = request.POST.get(
493 532 "reason_referee2")
494 533 SP_Period_form.save()
495   - sp_period.referee2 = PyrosUser.objects.get(id=tac)
496 534 #if sp_period.referee1 != None:
497 535 #sp_period.status = SP_Period.STATUSES_EVALUATED
498 536 sp_period.save()
... ...