Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion statistics_app/templates/statistics_app/workshop_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@
dateToday.setDate(dateToday.getDate() - 1);
upto.setFullYear(dateToday.getFullYear() + 1);

function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

sort_date_by = getParameterByName('sort_by_date')
console.log(sort_date_by)
function sort_date(){
if(sort_date_by == 'asc')
window.location = '?sort_by_date=desc'
else
window.location = '?sort_by_date=asc'
}

$( function() {
from = $( "#from" )
.datepicker({
Expand Down Expand Up @@ -122,7 +141,7 @@
<th>Institute Name</th>
<th>Instructor Name</th>
<th>Workshop Name</th>
<th>Workshop Date</th>
<th><a onclick="sort_date()" style="cursor: pointer">Workshop Date</a></th>
<th>Requested/Proposed By</th>
</tr>
</thead>
Expand Down
22 changes: 16 additions & 6 deletions statistics_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
# Create your views here.
def check_workshop_type(x):
try:
y = datetime.strftime(x.proposed_workshop_date, '%d-%m-%Y')
y = x.proposed_workshop_date
except BaseException:
y = datetime.strftime(x.requested_workshop_date, '%d-%m-%Y')
y = x.requested_workshop_date
return y


Expand Down Expand Up @@ -203,8 +203,13 @@ def workshop_stats(request):
for workshop in requested_workshops:
upcoming_workshops.append(workshop)

upcoming_workshops = sorted(upcoming_workshops,
key=lambda x: check_workshop_type(x))
if 'sort_by_date' in request.GET:
if request.GET.get('sort_by_date') == 'asc':
upcoming_workshops = sorted(upcoming_workshops,
key=lambda x: check_workshop_type(x))
elif request.GET.get('sort_by_date') == 'desc':
upcoming_workshops = sorted(upcoming_workshops,
key=lambda x: check_workshop_type(x), reverse=True)

download = request.POST.get('Download')
if download:
Expand Down Expand Up @@ -286,8 +291,13 @@ def workshop_stats(request):
for workshop in requested_workshops:
upcoming_workshops.append(workshop)

upcoming_workshops = sorted(upcoming_workshops,
key=lambda x: check_workshop_type(x))
if 'sort_by_date' in request.GET:
if request.GET.get('sort_by_date') == 'asc':
upcoming_workshops = sorted(upcoming_workshops,
key=lambda x: check_workshop_type(x))
elif request.GET.get('sort_by_date') == 'desc':
upcoming_workshops = sorted(upcoming_workshops,
key=lambda x: check_workshop_type(x), reverse=True)

except BaseException:
upcoming_workshops = []
Expand Down