Commit 783ade4457b90544357ee18452a650bff79765e3
1 parent
0eff5356
Exists in
master
and in
3 other branches
improved algorithm to select resource types, now only shows the available for th…
…e choosen topic or all topics if choose that way, still has to think about when the user modifies topic
Showing
2 changed files
with
33 additions
and
11 deletions
Show diff stats
reports/templates/reports/create.html
@@ -55,7 +55,9 @@ | @@ -55,7 +55,9 @@ | ||
55 | addText: 'add data source', | 55 | addText: 'add data source', |
56 | deleteText: 'remove data source', | 56 | deleteText: 'remove data source', |
57 | added: function(object){ | 57 | added: function(object){ |
58 | - $.get("{% url 'subjects:reports:get_resource_and_tags' %}?subject_id={{subject.id}}", function(data){ | 58 | + var form_topic = $("select#id_topic :selected").filter(":selected").val(); //get user selected topic option |
59 | + | ||
60 | + $.get("{% url 'subjects:reports:get_resource_and_tags' %}?subject_id={{subject.id}}"+"&topic_choice="+form_topic, function(data){ | ||
59 | fields = object.children("select"); | 61 | fields = object.children("select"); |
60 | 62 | ||
61 | for(var j = 0; j < data.resources.length; j++){ | 63 | for(var j = 0; j < data.resources.length; j++){ |
@@ -63,7 +65,6 @@ | @@ -63,7 +65,6 @@ | ||
63 | 65 | ||
64 | } | 66 | } |
65 | //Set initial tag options | 67 | //Set initial tag options |
66 | - var form_topic = $("select#id_topic :selected").filter(":selected").val(); //get user selected topic option | ||
67 | $.get("{% url 'subjects:reports:get_tags' %}?resource_class_name="+fields[0].value+"&subject_id={{subject.id}}"+"&topic_choice="+form_topic, function(data){ | 68 | $.get("{% url 'subjects:reports:get_tags' %}?resource_class_name="+fields[0].value+"&subject_id={{subject.id}}"+"&topic_choice="+form_topic, function(data){ |
68 | fields[1].options.length = 0; | 69 | fields[1].options.length = 0; |
69 | for(var j = 0; j < data.tags.length; j++){ | 70 | for(var j = 0; j < data.tags.length; j++){ |
@@ -86,5 +87,7 @@ | @@ -86,5 +87,7 @@ | ||
86 | }); | 87 | }); |
87 | }, | 88 | }, |
88 | }); | 89 | }); |
90 | + | ||
91 | + $('.resource-tag-formset').remove(); //I remove the element so there is no empty form with no data, I can't override this behavior on the previous function call | ||
89 | </script> | 92 | </script> |
90 | {% endblock content %} | 93 | {% endblock content %} |
91 | \ No newline at end of file | 94 | \ No newline at end of file |
reports/views.py
@@ -58,7 +58,7 @@ class ReportView(LoginRequiredMixin, generic.FormView): | @@ -58,7 +58,7 @@ class ReportView(LoginRequiredMixin, generic.FormView): | ||
58 | 58 | ||
59 | #set formset | 59 | #set formset |
60 | resourceTagFormSet = formset_factory(ResourceAndTagForm, formset=BaseResourceAndTagFormset) | 60 | resourceTagFormSet = formset_factory(ResourceAndTagForm, formset=BaseResourceAndTagFormset) |
61 | - resourceTagFormSet = resourceTagFormSet(initial=[{'class_name': classes, 'tag':tags}]) | 61 | + resourceTagFormSet = resourceTagFormSet() |
62 | context['resource_tag_formset'] = resourceTagFormSet | 62 | context['resource_tag_formset'] = resourceTagFormSet |
63 | return context | 63 | return context |
64 | 64 | ||
@@ -131,6 +131,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -131,6 +131,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
131 | context['end_date'] = params_data['end_date'] | 131 | context['end_date'] = params_data['end_date'] |
132 | context['subject'] = subject | 132 | context['subject'] = subject |
133 | if params_data['from_mural']: | 133 | if params_data['from_mural']: |
134 | + #I used getlist method so it can get more than one tag and one resource class_name | ||
134 | context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date'], | 135 | context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date'], |
135 | params_data.getlist('resource'), params_data.getlist('tag')) | 136 | params_data.getlist('resource'), params_data.getlist('tag')) |
136 | return context | 137 | return context |
@@ -148,6 +149,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -148,6 +149,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
148 | 149 | ||
149 | header = ['User'] | 150 | header = ['User'] |
150 | 151 | ||
152 | + #For each student in the subject | ||
151 | for student in students: | 153 | for student in students: |
152 | data[student] = [] | 154 | data[student] = [] |
153 | 155 | ||
@@ -202,7 +204,6 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -202,7 +204,6 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
202 | 204 | ||
203 | 205 | ||
204 | #VAR08 through VAR_019 of documenttation: | 206 | #VAR08 through VAR_019 of documenttation: |
205 | - print(resources_id) | ||
206 | resources_data = self.get_resources_and_tags_data(resources_id, tags_id, student, subject) | 207 | resources_data = self.get_resources_and_tags_data(resources_id, tags_id, student, subject) |
207 | 208 | ||
208 | interactions = {**interactions, **resources_data} | 209 | interactions = {**interactions, **resources_data} |
@@ -246,29 +247,47 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | @@ -246,29 +247,47 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): | ||
246 | data = {} | 247 | data = {} |
247 | 248 | ||
248 | for i in range(len(resources)): | 249 | for i in range(len(resources)): |
249 | - print(data) | ||
250 | - print(resources) | ||
251 | - print(resources[i]) | ||
252 | - print(tags[i]) | ||
253 | data[str(resources[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = Log.objects.filter(action="view", resource=resources[i].lower(), | 250 | data[str(resources[i]) + " with tag " + Tag.objects.get(id=int(tags[i])).name] = Log.objects.filter(action="view", resource=resources[i].lower(), |
254 | user_id = student.id, context__contains = {'subject_id': subject.id}).count() | 251 | user_id = student.id, context__contains = {'subject_id': subject.id}).count() |
255 | 252 | ||
256 | return data | 253 | return data |
257 | 254 | ||
258 | 255 | ||
259 | - | 256 | +""" |
257 | +Get all possible resource subclasses available for that topic selected | ||
258 | +""" | ||
260 | def get_resources(request): | 259 | def get_resources(request): |
261 | 260 | ||
262 | #get all possible resources | 261 | #get all possible resources |
263 | classes = Resource.__subclasses__() | 262 | classes = Resource.__subclasses__() |
264 | 263 | ||
265 | data = {} | 264 | data = {} |
266 | - | 265 | + subject = Subject.objects.get(id=request.GET['subject_id']) |
267 | 266 | ||
268 | - data['resources']= [ {'id':class_name.__name__, 'name':class_name.__name__} for class_name in classes] | 267 | + topic_choice = request.GET["topic_choice"] |
268 | + if topic_choice.lower() == "all": | ||
269 | + topics = subject.topic_subject.all() | ||
270 | + else: | ||
271 | + topics = [Topic.objects.get(id=int(topic_choice))] | ||
272 | + | ||
273 | + resources_class_names = [] | ||
274 | + for topic in topics: | ||
275 | + resource_set = Resource.objects.filter(topic = topic) | ||
276 | + for resource in resource_set: | ||
277 | + resources_class_names.append(resource._my_subclass) | ||
278 | + | ||
279 | + #remove duplicates | ||
280 | + resources = set(resources_class_names) | ||
281 | + | ||
282 | + data['resources']= [ {'id':resource_type, 'name':resource_type} for resource_type in resources] | ||
269 | return JsonResponse(data) | 283 | return JsonResponse(data) |
270 | 284 | ||
271 | 285 | ||
286 | + | ||
287 | +""" | ||
288 | +This function returns all the tags associated | ||
289 | +with a resource that is of the type of of the resource_class_name provided. | ||
290 | +""" | ||
272 | def get_tags(request): | 291 | def get_tags(request): |
273 | resource_type = request.GET['resource_class_name'] | 292 | resource_type = request.GET['resource_class_name'] |
274 | subject = Subject.objects.get(id=request.GET['subject_id']) | 293 | subject = Subject.objects.get(id=request.GET['subject_id']) |