Commit 42790782dea7f8be3fcbae45b8f08a5f9578e50c
1 parent
44a958fb
Exists in
master
and in
2 other branches
modified resource pie chart for better loooking and readbility
Showing
1 changed file
with
13 additions
and
2 deletions
Show diff stats
topics/views.py
| ... | ... | @@ -20,6 +20,8 @@ from subjects.models import Subject |
| 20 | 20 | from .models import Topic, Resource |
| 21 | 21 | from .forms import TopicForm |
| 22 | 22 | |
| 23 | +import operator | |
| 24 | + | |
| 23 | 25 | class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 24 | 26 | log_component = 'topic' |
| 25 | 27 | log_action = 'create' |
| ... | ... | @@ -285,7 +287,16 @@ def getResourceCount(request): |
| 285 | 287 | else: |
| 286 | 288 | data[key] = 1 |
| 287 | 289 | |
| 290 | + data = [(key,value) for key,value in sorted(data.items(), key=operator.itemgetter(1), reverse=True)] | |
| 291 | + | |
| 292 | + others = data[4:] | |
| 293 | + total_others = 0 | |
| 294 | + for key,value in others: | |
| 295 | + total_others += value | |
| 296 | + | |
| 297 | + del data[4:] #remove from the 5th element | |
| 298 | + data.append(("others", total_others)) #so I have the sum of all other resources added up | |
| 288 | 299 | real_data = [] |
| 289 | - for item in data.items(): | |
| 290 | - real_data.append(item) | |
| 300 | + for key,value in data: | |
| 301 | + real_data.append((key,value)) | |
| 291 | 302 | return JsonResponse(real_data, safe=False) | ... | ... |