Skip to content

Commit

Permalink
updated pending organisations list
Browse files Browse the repository at this point in the history
  • Loading branch information
sumandari committed Jan 21, 2022
1 parent 96977b0 commit a0680ee
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 277 deletions.
11 changes: 10 additions & 1 deletion django_project/certification/models/certifying_organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ def get_queryset(self):

return super(
UnapprovedCertifyingOrganisationManager, self).get_queryset(
).filter(approved=False, rejected=False)
).filter(approved=False, rejected=False).extra(
select={
'submit_date': (
'SELECT history_date '
'FROM certification_historicalcertifyingorganisation '
'WHERE id=certification_certifyingorganisation.id '
'ORDER BY history_date ASC LIMIT 1'
)
}
)


def validate_email_address(value):
Expand Down
3 changes: 3 additions & 0 deletions django_project/certification/models/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ def save(self, *args, **kwargs):

def __unicode__(self):
return '{}'.format(self.name)

def __str__(self):
return self.name
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
{% extends "project_base.html" %}
{% load thumbnail %}
{% load custom_markup %}
{% load sorting_tags %}
{% block title %}Certifying Organisations - {{ block.super }}{% endblock %}

{% block extra_head %}
<style>
table td {
background-color: white;
}
</style>
{% endblock %}

{% block page_title %}
<h1>Certifying Organisations (all)</h1>
{% endblock page_title %}

{% block content %}
<style>
.success {
text-align: center;
font-family: inherit;
color: inherit;
background: #adffd2;
padding: 10px;
border-radius: 5px;
border: 1px solid #96ffc5;
}
.status-wrapper {
border: 1px solid lightgrey;
float: right;
width: 100%;
margin-top: 5px;
padding: 5px;
box-shadow: 2px 2px grey;
cursor: pointer;
}
.status-wrapper:hover {
background-color: lightgray;
}
</style>

{% if messages %}
<div class="messages">
Expand Down Expand Up @@ -79,258 +62,28 @@ <h3>No certifying organisations are defined, but you can <a
{% endif %}
{% endifequal %}

{% for certifyingorganisation in certifyingorganisations %}
<script>console.debug("{{ certifyingorganisation }}");</script>
<script>
function toggleDetails(id) {
$('#'+id).children().toggle();
$('#'+id).next().toggle();
}
</script>
<div class="row" style="margin-top:10px;">
<div class="col-lg-10">

<h3>{{ certifyingorganisation.name }}</h3>
<p id="{{ certifyingorganisation.pk }}" style="color: grey" onclick="toggleDetails(this.id)">
<span style="font-size: 8pt" class="glyphicon glyphicon-triangle-right"></span>
<span style="font-size: 8pt; display: none" class="glyphicon glyphicon-triangle-bottom"></span>
<span>Show details</span>
<span style="display: none">Hide details</span><br/>
</p>
<div style="color: grey; display: none">
<span class="grey-italic col-lg-4">Organisation name</span><span class="col-lg-8">{{ certifyingorganisation.name }}</span><br/>
<span class="grey-italic col-lg-4">Address</span><span class="col-lg-8">{{ certifyingorganisation.address }}</span><br/>
<span class="grey-italic col-lg-4">Country</span><span class="col-lg-8">{{ certifyingorganisation.country.name }}</span><br/>
<span class="grey-italic col-lg-4">Email</span><span class="col-lg-8">{{ certifyingorganisation.organisation_email }}</span><br/>
<span class="grey-italic col-lg-4">Phone</span><span class="col-lg-8">{{ certifyingorganisation.organisation_phone }}</span><br/>
<span class="grey-italic col-lg-4">Link</span><span class="col-lg-8"><a href="{{ certifyingorganisation.url }}">{{ certifyingorganisation.url }}</a></span><br/>

<span class="grey-italic col-lg-4">Organisation owners</span>
<span class="col-lg-8">{% for organisation_owners in certifyingorganisation.organisation_owners.all %}
{% if organisation_owners.first_name %}
{{ organisation_owners.first_name }} {{ organisation_owners.last_name }}{{ ", " }}
{% else %}
{{ organisation_owners }}{{ ", " }}
{% endif %}
{% endfor %}</span>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>{% sort_link "Organisation Name" "name" %}</th>
<th>{% sort_link "Application Date" "submit_date" %}</th>
<th>{% sort_link "Status" "status" %}</th>
</tr>
</thead>
<tbody>
{% for certifyingorganisation in certifyingorganisations %}
<tr>
<td>
<a href="{% url 'certifyingorganisation-detail' project_slug=certifyingorganisation.project.slug slug=certifyingorganisation.slug %}">
{{ certifyingorganisation.name }}
</a>
</td>
<td>{{ certifyingorganisation.submit_date }}</td>
<td>{% if certifyingorganisation.status %}{{ certifyingorganisation.status }}{% else %}-{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>

</div>
<div class="col-lg-2">
<div class="btn-group pull-right">
{% if not certifyingorganisation.approved and user.is_staff or user == project.owner or user in certifyingorganisation.project.certification_managers.all %}
<a class="btn btn-default btn-mini btn-approved tooltip-toggle"
href='{% url "certifyingorganisation-approve" project_slug=certifyingorganisation.project.slug slug=certifyingorganisation.slug %}'
data-title="Approve {{ certifyingorganisation.name }}">
<span class="glyphicon glyphicon-thumbs-up"></span>
</a>
<a class="btn btn-default btn-delete btn-mini tooltip-toggle btn-reject"
organisation_name="{{ certifyingorganisation.name }}"
organisation_country="{{ certifyingorganisation.country.name }}"
organisation_slug="{{ certifyingorganisation.slug }}"
organisation_project_slug="{{ certifyingorganisation.project.slug }}"
data-title="Reject {{ certifyingorganisation.name }}">
<span class="glyphicon glyphicon-thumbs-down"></span>
</a>
{% endif %}
{% if not certifyingorganisation.approved and user.is_staff or user == project.owner or user in certifyingorganisation.project.certification_managers.all or user in certifyingorganisation.organisation_owners.all %}
<a class="btn btn-default btn-mini tooltip-toggle"
href='{% url "certifyingorganisation-update" project_slug=certifyingorganisation.project.slug slug=certifyingorganisation.slug %}'
data-title="Edit {{ certifyingorganisation.name }}">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a class="btn btn-default btn-mini btn-delete tooltip-toggle"
href='{% url "certifyingorganisation-delete" project_slug=certifyingorganisation.project.slug slug=certifyingorganisation.slug %}'
data-title="Delete {{ certifyingorganisation.name }}">
<span class="glyphicon glyphicon-minus"></span>
</a>
{% endif %}
</div>
{% if not certifyingorganisation.approved and user.is_staff or user == project.owner or user in certifyingorganisation.project.certification_managers.all %}
<div class="status-wrapper tooltip-toggle"
organisation_name="{{ certifyingorganisation.name }}"
organisation_country="{{ certifyingorganisation.country.name }}"
organisation_slug="{{ certifyingorganisation.slug }}"
organisation_project_slug="{{ certifyingorganisation.project.slug }}"
organisation_status="{{ certifyingorganisation.status.id }}"
organisation_remarks="{{ certifyingorganisation.remarks }}"
data-title="Click to edit">
<b>Status</b>: <span class="status-info">{{ certifyingorganisation.status }}</span><br/>
<b>Remarks</b>: <span class="remarks-info">{{ certifyingorganisation.remarks }}</span>
</div>
{% endif %}
</div>
</div>
{% endfor %}
<hr/>
{% include "_pagination.html" %}

<!-- Modal -->
<div class="modal fade" id="rejectionModal" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><b>Rejection Form</b></h4>
</div>
<div class="modal-body">
<p>You are going to reject this organisation below:</p>
<ul>
<li><span>Organisation: </span><span class="rejection-form-info" id="rejected-organisation-name"></span></li>
<li><span>Country: </span><span class="rejection-form-info" id="rejected-organisation-country"></span></li>
</ul>
<form id="rejectionForm" role="form">
<label>Please indicate your reason of this rejection.</label><br>
<input name="status" class="form-control" value="Rejected, because ">
<input name="rejected-organisation-slug" hidden>
<input name="rejected-organisation-project-slug" hidden>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" onclick="closeRejectionForm()">Cancel</button>
<button type="button" class="btn btn-primary" onclick="submitRejectionForm()">Submit</button>
</div>
</div>

</div>
</div>

<!-- Modal -->
<div class="modal fade" id="updateStatusModal" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><b>Update Status Form</b></h4>
</div>
<div class="modal-body">
<p>You are going to update the status of this organisation below:</p>
<ul>
<li><span>Organisation: </span><span class="status-form-info" id="status-organisation-name"></span></li>
<li><span>Country: </span><span class="status-form-info" id="status-organisation-country"></span></li>
</ul>
<form id="updateStatusForm" role="form">
<label>Status:</label><br>
<select name="update-status" class="form-control">
</select><br/>
<label>Remarks:</label><br>
<input name="update-remarks" class="form-control">
<input name="status-organisation-slug" hidden>
<input name="status-organisation-project-slug" hidden>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" onclick="closeUpdateStatusForm()">Cancel</button>
<button type="button" class="btn btn-primary" onclick="submitUpdateStatusForm()">Submit</button>
</div>
</div>

</div>
</div>

<script>
$(document).click(function () {
$('.messages').fadeOut('fast')
});
$('.btn-delete').hover(
function (){
$(this).removeClass('btn-default').addClass('btn-danger')
},
function (){
$(this).removeClass('btn-danger').addClass('btn-default')
}
);
$('.btn-approved').hover(
function (){
$(this).removeClass('btn-default').addClass('btn-success')
},
function (){
$(this).removeClass('btn-success').addClass('btn-default')
}
);

$('.btn-reject').click(function () {
$('#rejected-organisation-name').html($(this).attr('organisation_name'));
$('#rejected-organisation-country').html($(this).attr('organisation_country'));
$('[name=rejected-organisation-slug]').val($(this).attr('organisation_slug'));
$('[name=rejected-organisation-project-slug]').val($(this).attr('organisation_project_slug'));
$('#rejectionModal').modal('show')
});

$('.status-wrapper').click(function () {
var initial_status = $(this).attr('organisation_status');
var project_slug = $(this).attr('organisation_project_slug');
$.ajax({
url: '/{{ LANGUAGE_CODE }}/' + project_slug + '/get-status-list/',
method: 'GET',
success: function (data) {
var $selectStatus = $('[name="update-status"]');
$selectStatus.empty();
$selectStatus.append('<option value="">--------------------------</option>');
for(var i=0; i<data.length; i++){
if(data[i].id === parseInt(initial_status)){
$selectStatus.append('<option value=' + data[i].id + ' selected>' + data[i].name + '</option>')
}else {
$selectStatus.append('<option value=' + data[i].id + '>' + data[i].name + '</option>')
}

}
}
});
$('#status-organisation-name').html($(this).attr('organisation_name'));
$('#status-organisation-country').html($(this).attr('organisation_country'));
$('[name=status-organisation-slug]').val($(this).attr('organisation_slug'));
$('[name=status-organisation-project-slug]').val(project_slug);
$('[name=update-remarks]').val($(this).attr('organisation_remarks'));
$('#updateStatusModal').modal('show')
});

function closeRejectionForm() {
$('.rejection-form-info').html('');
document.forms['rejectionForm'].reset();
$('#rejectionModal').modal('hide')
}

function closeUpdateStatusForm() {
$('.status-form-info').html('');
document.forms['updateStatusForm'].reset();
$('#updateStatusModal').modal('hide')
}

function submitRejectionForm() {
var organisation_slug = $('[name=rejected-organisation-slug]').val();
var organisation_project_slug = $('[name=rejected-organisation-project-slug]').val();
$.ajax({
url: '/{{ LANGUAGE_CODE }}/' + organisation_project_slug + '/reject-certifyingorganisation/' + organisation_slug + '/',
data: {
'status': $('[name=status]').val()
},
success: function(){
location.reload()
}
});
}

function submitUpdateStatusForm() {
var organisation_slug = $('[name=status-organisation-slug]').val();
var organisation_project_slug = $('[name=status-organisation-project-slug]').val();
$.ajax({
url: '/{{ LANGUAGE_CODE }}/' + organisation_project_slug + '/update-status-certifyingorganisation/' + organisation_slug + '/',
method: 'POST',
data: {
'status': $('[name=update-status]').val(),
'remarks': $('[name=update-remarks]').val()
},
dataType: 'json',
success: function(){
location.reload()
}
});
}

</script>
{% endblock %}
13 changes: 12 additions & 1 deletion django_project/certification/views/certifying_organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.urls import reverse
from django.shortcuts import get_list_or_404
from django.db.models import Q
from django.db.models.functions import Lower
from django.http import HttpResponse
from django.views.generic import (
ListView,
Expand Down Expand Up @@ -660,7 +661,7 @@ class PendingCertifyingOrganisationListView(

context_object_name = 'certifyingorganisations'
template_name = 'certifying_organisation/pending-list.html'
paginate_by = 10
paginate_by = 20

def __init__(self):
"""
Expand Down Expand Up @@ -693,6 +694,8 @@ def get_context_data(self, **kwargs):
context['the_project'] = \
Project.objects.get(slug=self.project_slug)
context['project'] = context['the_project']
if "sort_by" in self.request.GET:
context["current_sort_field"] = self.request.GET.get("sort_by")
return context

# noinspection PyAttributeOutsideInit
Expand Down Expand Up @@ -721,6 +724,14 @@ def get_queryset(self):
Q(organisation_owners=self.request.user) |
Q(project__certification_managers=
self.request.user))).distinct()
if 'sort_by' in self.request.GET:
sort_by = self.request.GET.get('sort_by')
if sort_by == 'name':
queryset = queryset.order_by(Lower('name'))
elif sort_by == '-name':
queryset = queryset.order_by(Lower('name').desc())
else:
queryset = queryset.order_by(sort_by)
return queryset
else:
raise Http404(
Expand Down

0 comments on commit a0680ee

Please sign in to comment.