Commit e6de613120e50eee0761ade2c3e43c73c47c33b6
1 parent
187e2bb3
Exists in
master
and in
3 other branches
Adding goals unanswered report
Showing
5 changed files
with
155 additions
and
37 deletions
Show diff stats
amadeus/static/js/goals_reports.js
| ... | ... | @@ -4,8 +4,7 @@ $(function () { |
| 4 | 4 | |
| 5 | 5 | function getAnswered() { |
| 6 | 6 | var container = $("#reports"), |
| 7 | - list = container.find('.answered_data'), | |
| 8 | - holder = list.parent().find('.holder'); | |
| 7 | + list = container.find('.answered_data'); | |
| 9 | 8 | |
| 10 | 9 | if (list.children().length == 0) { |
| 11 | 10 | var url = list.parent().data('url'); |
| ... | ... | @@ -15,13 +14,6 @@ function getAnswered() { |
| 15 | 14 | success: function (data) { |
| 16 | 15 | list.html(data); |
| 17 | 16 | |
| 18 | - // var form = list.find('.form_search'); | |
| 19 | - | |
| 20 | - // form.submit(function () { | |
| 21 | - // searchHistory(panel_id); | |
| 22 | - | |
| 23 | - // return false; | |
| 24 | - // }); | |
| 25 | 17 | $('#answered_table').DataTable({ |
| 26 | 18 | "dom": "Bfrtip", |
| 27 | 19 | "language": dataTablei18n, |
| ... | ... | @@ -44,35 +36,82 @@ function getAnswered() { |
| 44 | 36 | ] |
| 45 | 37 | } |
| 46 | 38 | }); |
| 47 | - // var items = $("#answered_table").children(":visible").length; | |
| 48 | - | |
| 49 | - // if (items > 10) { | |
| 50 | - // holder.jPages({ | |
| 51 | - // containerID : "answered_table", | |
| 52 | - // perPage: 10, | |
| 53 | - // previous: "«", | |
| 54 | - // next: "»", | |
| 55 | - // midRange: 5 | |
| 56 | - // }); | |
| 57 | - // } | |
| 58 | 39 | } |
| 59 | 40 | }); |
| 60 | - } else { | |
| 61 | - $('#answered_table').DataTable(); | |
| 62 | - // var items = $("#answered_table").children(":visible").length; | |
| 63 | - | |
| 64 | - // if (items > 10) { | |
| 65 | - // holder.jPages({ | |
| 66 | - // containerID : "answered_table", | |
| 67 | - // perPage: 10, | |
| 68 | - // previous: "«", | |
| 69 | - // next: "»", | |
| 70 | - // midRange: 5 | |
| 71 | - // }); | |
| 72 | - // } | |
| 73 | 41 | } |
| 74 | 42 | |
| 75 | 43 | container.find('.answered_link').addClass('active'); |
| 44 | + container.find('.answered').show(); | |
| 45 | + | |
| 46 | + container.find('.unanswered_link').removeClass('active'); | |
| 47 | + container.find('.unanswered').hide(); | |
| 48 | + | |
| 49 | + setBreadcrumb(answeredBread); | |
| 50 | +} | |
| 51 | + | |
| 52 | +function getUnanswered() { | |
| 53 | + var container = $("#reports"), | |
| 54 | + list = container.find('.unanswered_data'); | |
| 55 | + | |
| 56 | + if (list.children().length == 0) { | |
| 57 | + var url = list.parent().data('url'); | |
| 58 | + | |
| 59 | + $.ajax({ | |
| 60 | + url: url, | |
| 61 | + success: function (data) { | |
| 62 | + list.html(data); | |
| 63 | + | |
| 64 | + $('#unanswered_table').DataTable({ | |
| 65 | + "dom": "Bfrtip", | |
| 66 | + "language": dataTablei18n, | |
| 67 | + buttons: { | |
| 68 | + dom: { | |
| 69 | + container: { | |
| 70 | + className: 'col-md-3' | |
| 71 | + }, | |
| 72 | + buttonContainer: { | |
| 73 | + tag: 'h4', | |
| 74 | + className: 'history-header' | |
| 75 | + }, | |
| 76 | + }, | |
| 77 | + buttons: [ | |
| 78 | + { | |
| 79 | + extend: 'csv', | |
| 80 | + text: csvBtnLabeli18n, | |
| 81 | + filename: 'report-unanswered' | |
| 82 | + } | |
| 83 | + ], | |
| 84 | + }, | |
| 85 | + "columns": [ | |
| 86 | + null, | |
| 87 | + null, | |
| 88 | + { "orderable": false }, | |
| 89 | + ] | |
| 90 | + }); | |
| 91 | + | |
| 92 | + $("#check_all_rows").click(function () { | |
| 93 | + var checked = this.checked; | |
| 94 | + | |
| 95 | + $('#unanswered_table').find('input[type="checkbox"]').each(function() { | |
| 96 | + this.checked = checked; | |
| 97 | + }); | |
| 98 | + }); | |
| 99 | + } | |
| 100 | + }); | |
| 101 | + } | |
| 102 | + | |
| 103 | + container.find('.answered_link').removeClass('active'); | |
| 104 | + container.find('.answered').hide(); | |
| 105 | + | |
| 106 | + container.find('.unanswered_link').addClass('active'); | |
| 107 | + container.find('.unanswered').show(); | |
| 108 | + | |
| 109 | + setBreadcrumb(unansweredBread); | |
| 110 | +} | |
| 76 | 111 | |
| 77 | - container.find('.answered').attr('style', 'display: block'); | |
| 112 | +function setBreadcrumb(text) { | |
| 113 | + var breadcrumb = $(".breadcrumb")[0], | |
| 114 | + li = $(breadcrumb).find('li:last-child'); | |
| 115 | + | |
| 116 | + $(li).html(text); | |
| 78 | 117 | } |
| 79 | 118 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +{% load i18n goals_filters %} | |
| 2 | + | |
| 3 | +<div class="row"> | |
| 4 | + <div class="col-md-12"> | |
| 5 | + <table id="unanswered_table" class="table table-striped table-bordered"> | |
| 6 | + <thead> | |
| 7 | + <th> | |
| 8 | + {% trans 'Student' %} | |
| 9 | + </th> | |
| 10 | + <th> | |
| 11 | + {% trans 'Group' %} | |
| 12 | + </th> | |
| 13 | + <th> | |
| 14 | + <input type="checkbox" id="check_all_rows" /> {% trans 'Select All' %} | |
| 15 | + </th> | |
| 16 | + </thead> | |
| 17 | + <tbody> | |
| 18 | + {% for student in students %} | |
| 19 | + <tr> | |
| 20 | + <td>{{ student }}</td> | |
| 21 | + <td>{{ student|groups }}</td> | |
| 22 | + <td class="text-center"><input type="checkbox" /></td> | |
| 23 | + </tr> | |
| 24 | + {% endfor %} | |
| 25 | + </tbody> | |
| 26 | + </table> | |
| 27 | + </div> | |
| 28 | +</div> | |
| 0 | 29 | \ No newline at end of file | ... | ... |
goals/templates/goals/reports.html
| ... | ... | @@ -54,8 +54,8 @@ |
| 54 | 54 | <div id="reports" class="panel-collapse in collapse category-panel-content"> |
| 55 | 55 | <div id="core-subjects-options-div"> |
| 56 | 56 | <ul class="core-subjects-options"> |
| 57 | - <a href=""><li class="answered_link active">{% trans "Answered" %} ({{ totals.answered }})</li></a> | |
| 58 | - <a href=""><li class="">{% trans "Unanswered" %} ({{ totals.unanswered }})</li></a> | |
| 57 | + <a href="javascript:getAnswered()"><li class="answered_link active">{% trans "Answered" %} ({{ totals.answered }})</li></a> | |
| 58 | + <a href="javascript:getUnanswered()"><li class="unanswered_link">{% trans "Unanswered" %} ({{ totals.unanswered }})</li></a> | |
| 59 | 59 | <a href=""><li class="">{% trans "Resource History" %}</li></a> |
| 60 | 60 | </ul> |
| 61 | 61 | </div> |
| ... | ... | @@ -66,6 +66,13 @@ |
| 66 | 66 | <div class="holder"></div> |
| 67 | 67 | </div> |
| 68 | 68 | </div> |
| 69 | + | |
| 70 | + <div class="unanswered" data-url="{% url 'goals:unanswered_report' goal.slug %}"> | |
| 71 | + <div class="unanswered_data"></div> | |
| 72 | + <div class="text-center"> | |
| 73 | + <div class="holder"></div> | |
| 74 | + </div> | |
| 75 | + </div> | |
| 69 | 76 | </div> |
| 70 | 77 | </div> |
| 71 | 78 | |
| ... | ... | @@ -95,7 +102,9 @@ |
| 95 | 102 | } |
| 96 | 103 | }; |
| 97 | 104 | |
| 98 | - var csvBtnLabeli18n = "<i class='fa fa-download'></i> {% trans 'Download .csv file' %}"; | |
| 105 | + var csvBtnLabeli18n = "<i class='fa fa-download'></i> {% trans 'Download .csv file' %}", | |
| 106 | + answeredBread = "{% trans 'Reports: Answered' %}", | |
| 107 | + unansweredBread = "{% trans 'Reports: Unanswered' %}"; | |
| 99 | 108 | </script> |
| 100 | 109 | <script type="text/javascript" src="{% static 'js/goals_reports.js' %}"></script> |
| 101 | 110 | {% endblock %} |
| 102 | 111 | \ No newline at end of file | ... | ... |
goals/urls.py
| ... | ... | @@ -13,4 +13,5 @@ urlpatterns = [ |
| 13 | 13 | url(r'^update_submit/(?P<slug>[\w_-]+)/$', views.UpdateSubmit.as_view(), name = 'update_submit'), |
| 14 | 14 | url(r'^reports/(?P<slug>[\w_-]+)/$', views.Reports.as_view(), name = 'reports'), |
| 15 | 15 | url(r'^answered_report/(?P<slug>[\w_-]+)/$', views.AnsweredReport.as_view(), name = 'answered_report'), |
| 16 | + url(r'^unanswered_report/(?P<slug>[\w_-]+)/$', views.UnansweredReport.as_view(), name = 'unanswered_report'), | |
| 16 | 17 | ] | ... | ... |
goals/views.py
| ... | ... | @@ -105,6 +105,47 @@ class AnsweredReport(LoginRequiredMixin, generic.ListView): |
| 105 | 105 | |
| 106 | 106 | return context |
| 107 | 107 | |
| 108 | +class UnansweredReport(LoginRequiredMixin, generic.ListView): | |
| 109 | + login_url = reverse_lazy("users:login") | |
| 110 | + redirect_field_name = 'next' | |
| 111 | + | |
| 112 | + template_name = 'goals/_unanswered.html' | |
| 113 | + model = MyGoals | |
| 114 | + context_object_name = 'students' | |
| 115 | + | |
| 116 | + def get_queryset(self): | |
| 117 | + slug = self.kwargs.get('slug', '') | |
| 118 | + goal = get_object_or_404(Goals, slug = slug) | |
| 119 | + | |
| 120 | + users = goal.topic.subject.students.values_list('id', flat = True) | |
| 121 | + | |
| 122 | + submited = Log.objects.filter(user_id__in = users, action = 'submit', resource = 'goals', context__contains = {"goals_id": goal.id}).values_list('user_id', flat = True) | |
| 123 | + | |
| 124 | + users = [i for i in users if i not in submited] | |
| 125 | + | |
| 126 | + submited_users = User.objects.filter(id__in = users) | |
| 127 | + | |
| 128 | + return submited_users | |
| 129 | + | |
| 130 | + def dispatch(self, request, *args, **kwargs): | |
| 131 | + slug = self.kwargs.get('slug', '') | |
| 132 | + goals = get_object_or_404(Goals, slug = slug) | |
| 133 | + | |
| 134 | + if not has_resource_permissions(request.user, goals): | |
| 135 | + return redirect(reverse_lazy('subjects:home')) | |
| 136 | + | |
| 137 | + return super(UnansweredReport, self).dispatch(request, *args, **kwargs) | |
| 138 | + | |
| 139 | + def get_context_data(self, **kwargs): | |
| 140 | + context = super(UnansweredReport, self).get_context_data(**kwargs) | |
| 141 | + | |
| 142 | + slug = self.kwargs.get('slug', '') | |
| 143 | + goals = get_object_or_404(Goals, slug = slug) | |
| 144 | + | |
| 145 | + context['goal'] = goals | |
| 146 | + | |
| 147 | + return context | |
| 148 | + | |
| 108 | 149 | class InsideView(LoginRequiredMixin, LogMixin, generic.ListView): |
| 109 | 150 | log_component = "resources" |
| 110 | 151 | log_action = "view" | ... | ... |