From bb66ccdb0c8fb26a20b1d9f2cf3ac8d659415dee Mon Sep 17 00:00:00 2001 From: Flavio Tarsetti <flavio.tarsetti@idiap.ch> Date: Thu, 3 Aug 2017 15:31:28 +0200 Subject: [PATCH] [accounts] added all functionalities to change/add supervisor and for godfather to validate/remove supervisee --- .../accounts/static/accounts/css/dialogs.css | 50 +++ .../accounts/static/accounts/js/dialogs.js | 337 +++++++++++++++++- .../accounts/dialogs/change_supervisor.html | 32 ++ .../accounts/dialogs/remove_supervisee.html | 28 ++ .../accounts/dialogs/validate_supervisee.html | 28 ++ .../accounts/templates/accounts/settings.html | 121 ++++++- .../web/accounts/templatetags/account_tags.py | 15 + beat/web/accounts/views.py | 10 + 8 files changed, 617 insertions(+), 4 deletions(-) create mode 100644 beat/web/accounts/templates/accounts/dialogs/change_supervisor.html create mode 100644 beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html create mode 100644 beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html diff --git a/beat/web/accounts/static/accounts/css/dialogs.css b/beat/web/accounts/static/accounts/css/dialogs.css index 14ea486ea..004a329b9 100644 --- a/beat/web/accounts/static/accounts/css/dialogs.css +++ b/beat/web/accounts/static/accounts/css/dialogs.css @@ -44,3 +44,53 @@ div.renew_account span.documentation color: #AAAAAA; font-size: 0.8em; } + +div.change_supervisor.progress +{ + margin: 40px auto; +} + + +div.change_supervisor #infos +{ + text-align: center; + display: block; + margin-top: 10px; + margin-bottom: 10px; + color: #777777; +} + + +div.change_supervisor span.label +{ + display: inline-block; + width: 50%; + color: black; + font-size: 1em; +} + + +div.change_supervisor input#new_godfather_username +{ + display: inline-block; + width: 50%; +} + + +div.change_supervisor input#new_godfather_username +{ + margin-top: 10px; +} + + +div.change_supervisor span.documentation +{ + color: #AAAAAA; + font-size: 0.8em; +} + +.btn-supervisee +{ + padding-top: 0em; + padding-bottom: 0em; +} diff --git a/beat/web/accounts/static/accounts/js/dialogs.js b/beat/web/accounts/static/accounts/js/dialogs.js index 78e3d728f..484c69ed3 100644 --- a/beat/web/accounts/static/accounts/js/dialogs.js +++ b/beat/web/accounts/static/accounts/js/dialogs.js @@ -30,8 +30,8 @@ if (beat.accounts.dialogs === undefined) beat.accounts.dialogs = {}; /** * Implements a modal dialog to renew a user account. * The user is presented with a small modal window that will allow - * him to set the new experiment name. It is possible to cancel the action at - * any moment by pressing "Cancel" or hitting the ESC key. + * him to certify the wish to renew his account. It is possible to cancel + * the action at any moment by pressing "Cancel" or hitting the ESC key. * * Parameters: * @@ -65,7 +65,338 @@ beat.accounts.dialogs.modal_renew_account = function(dialog_id, api_url, redirec $.ajax({ type: "PUT", - url: api_url /*+ experiment_fullname + '/' */, + url: api_url, + data: JSON.stringify({ + name: name, + }), + contentType: "application/json; charset=utf-8", + dataType: "json", + + success: function(data) { + $('#' + dialog_id).dialog("close"); + window.location.href = redirect_url; + }, + + error: function(jqXHR, textStatus, errorThrown) { + if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0)) + alert(jqXHR.responseText); + else + alert('Error: ' + errorThrown); + + $(this).dialog("close"); + } + }); + } + }, + { + id: 'button-' + dialog_id + '-cancel', + text: 'Cancel', + click: function() { + $(this).dialog("close"); + } + } + ] + }); + + // Display the dialog + $('#' + dialog_id).dialog("open"); +} + +/** + * Implements a modal dialog to change supervisor. + * The user is presented with a small modal window that will allow + * him to add the new supervisor username. It is possible to cancel the action at + * any moment by pressing "Cancel" or hitting the ESC key. + * + * Parameters: + * + * dialog_id: ID of the DOM element to use + * old_godfather_username: previous supervisor username + * api_url (str): The URL towards the API for changing the supervisor + * redirect_url (str): The URL where to redirect the user if the operation is + * successful + */ +beat.accounts.dialogs.modal_change_supervisor = function(dialog_id, old_godfather_username, api_url, redirect_url) { + + var split_api_url = api_url.split(old_godfather_username); + + // Create the dialog + $('#' + dialog_id).dialog({ + autoOpen: false, + resizable: false, + width: Math.min($(window).width() * 0.6, 700), + position: { my: "center", at: "center", of: window }, + modal: true, + closeOnEscape: true, + buttons: [ + { + id: 'button-' + dialog_id + '-renameit', + text: 'New supervision request', + click: function() { + + var new_godfather_username = $('#' + dialog_id + ' #new_godfather_username')[0].value; + + var name = $('#' + dialog_id + ' input')[0].value.trim(); + + if (name.length == 0) + { + alert("You can't enter an empty godfather username!"); + return; + } + + if (new_godfather_username == old_godfather_username) + { + alert("The new godfather username is the same as the previous one!"); + return; + } + + $.ajaxSetup({ + beforeSend: function(xhr, settings) { + var csrftoken = $.cookie('csrftoken'); + xhr.setRequestHeader('X-CSRFToken', csrftoken); + } + }); + + $.ajax({ + type: "POST", + url: split_api_url[0] + new_godfather_username + split_api_url[1], + data: JSON.stringify({ + name: name, + }), + contentType: "application/json; charset=utf-8", + dataType: "json", + + success: function(data) { + $('#' + dialog_id).dialog("close"); + window.location.href = redirect_url; + }, + + error: function(jqXHR, textStatus, errorThrown) { + if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0)) + alert(jqXHR.responseText); + else + alert('Error: ' + errorThrown); + } + }); + } + }, + { + id: 'button-' + dialog_id + '-cancel', + text: 'Cancel', + click: function() { + $(this).dialog("close"); + } + } + ] + }); + + // Initialise the dialog content + $('#' + dialog_id + ' input')[0].value = old_godfather_username; + + // Display the dialog + $('#' + dialog_id).dialog("open"); +} + +/** + * Implements a modal dialog to add a supervisor. + * The user is presented with a small modal window that will allow + * him to add to set the supervisor username. It is possible to cancel the action at + * any moment by pressing "Cancel" or hitting the ESC key. + * + * Parameters: + * + * dialog_id: ID of the DOM element to use + * api_url (str): The URL towards the API for adding a supervisor + * redirect_url (str): The URL where to redirect the user if the operation is + * successful + */ +beat.accounts.dialogs.modal_add_supervisor = function(dialog_id, api_url, redirect_url) { + + var split_api_url = api_url.split("nogodfather"); + + // Create the dialog + $('#' + dialog_id).dialog({ + autoOpen: false, + resizable: false, + width: Math.min($(window).width() * 0.6, 700), + position: { my: "center", at: "center", of: window }, + modal: true, + closeOnEscape: true, + buttons: [ + { + id: 'button-' + dialog_id + '-renameit', + text: 'New supervision request', + click: function() { + + var new_godfather_username = $('#' + dialog_id + ' #new_godfather_username')[0].value; + + var name = $('#' + dialog_id + ' input')[0].value.trim(); + + if (name.length == 0) + { + alert("You can't enter an empty godfather username!"); + return; + } + + $.ajaxSetup({ + beforeSend: function(xhr, settings) { + var csrftoken = $.cookie('csrftoken'); + xhr.setRequestHeader('X-CSRFToken', csrftoken); + } + }); + + $.ajax({ + type: "POST", + url: split_api_url[0] + new_godfather_username + split_api_url[1], + data: JSON.stringify({ + name: name, + }), + contentType: "application/json; charset=utf-8", + dataType: "json", + + success: function(data) { + $('#' + dialog_id).dialog("close"); + window.location.href = redirect_url; + }, + + error: function(jqXHR, textStatus, errorThrown) { + if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0)) + alert(jqXHR.responseText); + else + alert('Error: ' + errorThrown); + } + }); + } + }, + { + id: 'button-' + dialog_id + '-cancel', + text: 'Cancel', + click: function() { + $(this).dialog("close"); + } + } + ] + }); + + // Initialise the dialog content + $('#' + dialog_id + ' input')[0].value = ''; + + // Display the dialog + $('#' + dialog_id).dialog("open"); +} + +/** + * Implements a modal dialog for the supervisor to validate a supervisee + * account. It is possible to cancel the action at any moment by pressing + * "Cancel" or hitting the ESC key. + * + * Parameters: + * + * dialog_id: ID of the DOM element to use + * api_url (str): The URL towards the API to validate a supervisee + * redirect_url (str): The URL where to redirect the user if the operation is + * successful + */ +beat.accounts.dialogs.modal_validate_supervisee = function(dialog_id, api_url, redirect_url) { + + // Create the dialog + $('#' + dialog_id).dialog({ + autoOpen: false, + resizable: false, + width: Math.min($(window).width() * 0.6, 700), + position: { my: "center", at: "center", of: window }, + modal: true, + closeOnEscape: true, + buttons: [ + { + id: 'button-' + dialog_id + '-renameit', + text: 'Validation of supervisee account', + click: function() { + + $.ajaxSetup({ + beforeSend: function(xhr, settings) { + var csrftoken = $.cookie('csrftoken'); + xhr.setRequestHeader('X-CSRFToken', csrftoken); + } + }); + + $.ajax({ + type: "PUT", + url: api_url, + data: JSON.stringify({ + name: name, + }), + contentType: "application/json; charset=utf-8", + dataType: "json", + + success: function(data) { + $('#' + dialog_id).dialog("close"); + window.location.href = redirect_url; + }, + + error: function(jqXHR, textStatus, errorThrown) { + if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0)) + alert(jqXHR.responseText); + else + alert('Error: ' + errorThrown); + + $(this).dialog("close"); + } + }); + } + }, + { + id: 'button-' + dialog_id + '-cancel', + text: 'Cancel', + click: function() { + $(this).dialog("close"); + } + } + ] + }); + + // Display the dialog + $('#' + dialog_id).dialog("open"); +} + +/** + * Implements a modal dialog for the supervisor to remove a supervisee + * account. It is possible to cancel the action at any moment by pressing + * "Cancel" or hitting the ESC key. + * + * Parameters: + * + * dialog_id: ID of the DOM element to use + * api_url (str): The URL towards the API to remove a supervisee + * redirect_url (str): The URL where to redirect the user if the operation is + * successful + */ +beat.accounts.dialogs.modal_remove_supervisee = function(dialog_id, api_url, redirect_url) { + + // Create the dialog + $('#' + dialog_id).dialog({ + autoOpen: false, + resizable: false, + width: Math.min($(window).width() * 0.6, 700), + position: { my: "center", at: "center", of: window }, + modal: true, + closeOnEscape: true, + buttons: [ + { + id: 'button-' + dialog_id + '-renameit', + text: 'Removal of supervisee account', + click: function() { + + $.ajaxSetup({ + beforeSend: function(xhr, settings) { + var csrftoken = $.cookie('csrftoken'); + xhr.setRequestHeader('X-CSRFToken', csrftoken); + } + }); + + $.ajax({ + type: "PUT", + url: api_url, data: JSON.stringify({ name: name, }), diff --git a/beat/web/accounts/templates/accounts/dialogs/change_supervisor.html b/beat/web/accounts/templates/accounts/dialogs/change_supervisor.html new file mode 100644 index 000000000..8c94ed47d --- /dev/null +++ b/beat/web/accounts/templates/accounts/dialogs/change_supervisor.html @@ -0,0 +1,32 @@ +{% comment %} + * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ + * Contact: beat.support@idiap.ch + * + * This file is part of the beat.web module of the BEAT platform. + * + * Commercial License Usage + * Licensees holding valid commercial BEAT licenses may use this file in + * accordance with the terms contained in a written agreement between you + * and Idiap. For further information contact tto@idiap.ch + * + * Alternatively, this file may be used under the terms of the GNU Affero + * Public License version 3 as published by the Free Software and appearing + * in the file LICENSE.AGPL included in the packaging of this file. + * The BEAT platform is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero Public License along + * with the BEAT platform. If not, see http://www.gnu.org/licenses/. +{% endcomment %} + +<div id="{{ dialog_id }}" class="change_supervisor" style="display:none;" title="Supervision update"> + <div class="settings"> + <div><span id="infos"></span></div> + Take into account that requesting a new supervision will temporarely set your account in a rejected state until the request is validated by your new supervisor.<br> + If your new supervisor rejects your supervision request, you need to find another supervisor.<br> + If no supervisor is found after a specific date, your account will be blocked and you will need to proceed with an unblock account request<br> + <div><span class="label">New supervisor username: </span><input id="new_godfather_username" type="text" /></div> + <div><span class="documentation">A request for supervision will be sent to the new supervisor</span></div> + </div> +</div> diff --git a/beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html b/beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html new file mode 100644 index 000000000..a4743fbe2 --- /dev/null +++ b/beat/web/accounts/templates/accounts/dialogs/remove_supervisee.html @@ -0,0 +1,28 @@ +{% comment %} + * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ + * Contact: beat.support@idiap.ch + * + * This file is part of the beat.web module of the BEAT platform. + * + * Commercial License Usage + * Licensees holding valid commercial BEAT licenses may use this file in + * accordance with the terms contained in a written agreement between you + * and Idiap. For further information contact tto@idiap.ch + * + * Alternatively, this file may be used under the terms of the GNU Affero + * Public License version 3 as published by the Free Software and appearing + * in the file LICENSE.AGPL included in the packaging of this file. + * The BEAT platform is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero Public License along + * with the BEAT platform. If not, see http://www.gnu.org/licenses/. +{% endcomment %} + +<div id="{{ dialog_id }}" class="renew_account" style="display:none;" title="Remove supervisee"> + <div class="settings"> + <div><span id="infos"></span></div> + This action will remove the supervisee from your supervision list. + </div> +</div> diff --git a/beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html b/beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html new file mode 100644 index 000000000..5cc138c50 --- /dev/null +++ b/beat/web/accounts/templates/accounts/dialogs/validate_supervisee.html @@ -0,0 +1,28 @@ +{% comment %} + * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ + * Contact: beat.support@idiap.ch + * + * This file is part of the beat.web module of the BEAT platform. + * + * Commercial License Usage + * Licensees holding valid commercial BEAT licenses may use this file in + * accordance with the terms contained in a written agreement between you + * and Idiap. For further information contact tto@idiap.ch + * + * Alternatively, this file may be used under the terms of the GNU Affero + * Public License version 3 as published by the Free Software and appearing + * in the file LICENSE.AGPL included in the packaging of this file. + * The BEAT platform is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero Public License along + * with the BEAT platform. If not, see http://www.gnu.org/licenses/. +{% endcomment %} + +<div id="{{ dialog_id }}" class="renew_account alert-warning" style="display:none;" title="Validate supervisee"> + <div class="settings"> + <div><span id="infos"></span></div> + This action will add the supervisee to your supervision list. You therefore acknowledge that this user is under your responsability. + </div> +</div> diff --git a/beat/web/accounts/templates/accounts/settings.html b/beat/web/accounts/templates/accounts/settings.html index 012a82157..93246b318 100644 --- a/beat/web/accounts/templates/accounts/settings.html +++ b/beat/web/accounts/templates/accounts/settings.html @@ -226,8 +226,34 @@ <li class="list-group-item"><b>Supervision Track last validation date:</b> {{ supervisiontrack.last_validation_date }}</li> <li class="list-group-item"><b>Supervision Track expiration date:</b> {{ supervisiontrack.expiration_date }}</li> </ul> + <div class="form-group" style="text-align: center;"> + <input type="hidden" name="token" value="true"> + <button type="button" class="btn btn-warning" onclick="beat.accounts.dialogs.modal_change_supervisor('change_supervisor', '{{ supervisiontrack.godfather.username }}', '{% url 'api_accounts:add_supervisor' supervisiontrack.godfather.username %}', '{% url 'accounts:settings' %}');"><i class="fa fa-refresh fa-fw fa-lg"></i> Wish to update supervision?</button> + </div> {% elif user.profile.status == 'R' %} - <li class="list-group-item list-group-item-warning" style="text-align:center;">Rejected: You need to find a new supervisor</li> + <li class="list-group-item list-group-item-danger" style="text-align:center;">Status is rejected: You need to find a new supervisor</li> + <br> + {% if user.profile.supervision_key == None %} + <h4>General Information</h4> + <ul class="list-group"> + <li class="list-group-item"><b>You need to find a new supervisor to continue using your account</b></li> + <li class="list-group-item"><b>Deadline account blockage date (if no supervisor):</b> {{ user.profile.rejection_date }}</li> + <li class="list-group-item"><i>If your account gets blocked you can still follow the unblock procedure to re-activate it.</i></li> + </ul> + <div class="form-group" style="text-align: center;"> + <input type="hidden" name="token" value="true"> + <button type="button" class="btn btn-danger" onclick="beat.accounts.dialogs.modal_add_supervisor('change_supervisor', '{% url 'api_accounts:add_supervisor' 'nogodfather' %}', '{% url 'accounts:settings' %}');"><i class="fa fa-plus fa-fw fa-lg"></i> Add a supervisor</button> + </div> + {% else %} + <h4>General Information about a pending request</h4> + <ul class="list-group"> + <li class="list-group-item"><b>Pending request made to supervisor:</b> {{ supervisiontrack.godfather.username }}</li> + <li class="list-group-item"><b>Deadline account blockage date (if no supervisor):</b> {{ user.profile.rejection_date }}</li> + <li class="list-group-item"><i>You need to be patient until this supervisor accepts your request. An email was sent about your request, but in the meantime you can remind him to accept your supervision.<br> + If this supervisor rejects your supervision request, you will be informed and you will get the opportunity to make a new one.<br> + If your account gets blocked you can still follow the unblock procedure to re-activate it.</i></li> + </ul> + {% endif %} <br> {% elif user.profile.status == 'Y' %} <li class="list-group-item list-group-item-warning" style="text-align:center;">Revalidation required: You need to confirm that you wish to revalidate your account (year basis check)</li> @@ -254,8 +280,101 @@ </div> {% else %} +<div class="row"> + + <div class="col-sm-6 col-sm-offset-1"> + + <div class="panel panel-default"> + <div class="panel-heading"><i class="fa fa-users"></i> Supervision management + </div> + <div class="panel-body"> + <form id="token" method="post" action="" class="form"> + {% csrf_token %} + <div class="form-group" style="text-align: justify;"> + {% if supervisiontracks_pending|length > 0 %} + <li class="list-group-item list-group-item-danger" style="text-align:center;">Pending requests: You have a few days to accept or reject these supervision requests</li> + <br> + <table class="table"> + <thead> + <tr> + <th>Firstname</th> + <th>Lastname</th> + <th>Username</th> + <th>Email</th> + <th>Actions</th> + </tr> + </thead> + <tbody> + {% for supervisiontrack_pending in supervisiontracks_pending%} + <tr class="danger"> + <td>{{supervisiontrack_pending.supervisee.first_name}}</td> + <td>{{supervisiontrack_pending.supervisee.last_name}}</td> + <td>{{supervisiontrack_pending.supervisee.username}}</td> + <td>{{supervisiontrack_pending.supervisee.email}}</td> + <td> + + <button type="button" class="btn btn-success btn-supervisee" onclick="beat.accounts.dialogs.modal_validate_supervisee('validate_supervisee', '{% url 'api_accounts:validate_supervisee' supervisiontrack_pending.supervisee.username %}', '{% url 'accounts:settings' %}');"> Accept</button> + <button type="button" class="btn btn-danger btn-supervisee" onclick="beat.accounts.dialogs.modal_remove_supervisee('remove_supervisee', '{% url 'api_accounts:remove_supervisee' supervisiontrack_pending.supervisee.username %}', '{% url 'accounts:settings' %}');"> Reject</button> + </td> + </tr> + {% endfor %} + </tbody> + </table> + <hr /> + {% endif %} + + <li class="list-group-item" style="text-align:center;"><b>Supervision list</b></li> + <table class="table"> + <thead> + <tr> + <th>Firstname</th> + <th>Lastname</th> + <th>Username</th> + <th>Email</th> + <th>Start Date</th> + <th>Expiration Date</th> + <th>Actions</th> + </tr> + </thead> + <tbody> + {% for supervisiontrack_valid in supervisiontracks_valid%} + {% if supervisiontrack_valid.supervisee.profile.status == 'A' %} + <tr class="success"> + {% else %} + <tr class="warning"> + {% endif %} + <td>{{supervisiontrack_valid.supervisee.first_name}}</td> + <td>{{supervisiontrack_valid.supervisee.last_name}}</td> + <td>{{supervisiontrack_valid.supervisee.username}}</td> + <td>{{supervisiontrack_valid.supervisee.email}}</td> + <td>{{supervisiontrack_valid.start_date}}</td> + <td>{{supervisiontrack_valid.expiration_date}}</td> + <td> + <button type="button" class="btn btn-danger btn-supervisee" onclick="beat.accounts.dialogs.modal_remove_supervisee('remove_supervisee', '{% url 'api_accounts:remove_supervisee' supervisiontrack_valid.supervisee.username %}', '{% url 'accounts:settings' %}');"> Reject</button> + + </td> + </tr> + {% endfor %} + </tbody> + </table> + + <li class="list-group-item"><i>Valid supervisees are marked in green and supervisees that are under a revalidation process (yearly basis) are marked in yellow. +You can remind them to revalidate there account before the expiration date or else their account will get blocked (and need to pass through an unblock procedure)</i><br> + </div> + </form> + </div> + + </div> + + </div> +</div> + {% endif %} + +{% change_supervisor "change_supervisor" %} {% account_renew "account_renew" %} +{% validate_supervisee "validate_supervisee" %} +{% remove_supervisee "remove_supervisee" %} <script type="text/javascript"> jQuery(document).ready(function() { diff --git a/beat/web/accounts/templatetags/account_tags.py b/beat/web/accounts/templatetags/account_tags.py index 4fa3958c0..fbfe7d492 100644 --- a/beat/web/accounts/templatetags/account_tags.py +++ b/beat/web/accounts/templatetags/account_tags.py @@ -38,3 +38,18 @@ register = template.Library() def account_renew(id): return { 'dialog_id': id, } + +@register.inclusion_tag('accounts/dialogs/change_supervisor.html') +def change_supervisor(id): + return { 'dialog_id': id, + } + +@register.inclusion_tag('accounts/dialogs/validate_supervisee.html') +def validate_supervisee(id): + return { 'dialog_id': id, + } + +@register.inclusion_tag('accounts/dialogs/remove_supervisee.html') +def remove_supervisee(id): + return { 'dialog_id': id, + } diff --git a/beat/web/accounts/views.py b/beat/web/accounts/views.py index a3eab03a5..823516c60 100644 --- a/beat/web/accounts/views.py +++ b/beat/web/accounts/views.py @@ -30,6 +30,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import PasswordChangeForm from django.contrib import messages from django.db import models +from django.db.models import Q from rest_framework.authtoken.models import Token @@ -68,6 +69,8 @@ def account_settings(request): password_change_form = PasswordChangeForm(user=user) supervisiontrack = None + supervisiontracks_valid = None + supervisiontracks_pending = None if user.profile.is_godfather == False: supervisee = user if supervisee.profile.supervision_key is not None: @@ -75,6 +78,11 @@ def account_settings(request): supervisiontrack = SupervisionTrack.objects.get(supervisee=supervisee, supervisee__profile__supervision_key=models.F('supervision_key')) else: supervisiontrack = None + else: + godfather = user + #Filter and get all supervision tracks valid and + supervisiontracks_valid = SupervisionTrack.objects.filter(godfather=godfather, is_valid=True) + supervisiontracks_pending = SupervisionTrack.objects.filter(godfather=godfather, is_valid=False, start_date=None) return render(request, 'accounts/settings.html', @@ -82,4 +90,6 @@ def account_settings(request): 'password_change_form': password_change_form, 'user': user, 'supervisiontrack': supervisiontrack, + 'supervisiontracks_valid': supervisiontracks_valid, + 'supervisiontracks_pending': supervisiontracks_pending, 'token' : user.auth_token}) -- GitLab