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 | 55 | addText: 'add data source', |
56 | 56 | deleteText: 'remove data source', |
57 | 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 | 61 | fields = object.children("select"); |
60 | 62 | |
61 | 63 | for(var j = 0; j < data.resources.length; j++){ |
... | ... | @@ -63,7 +65,6 @@ |
63 | 65 | |
64 | 66 | } |
65 | 67 | //Set initial tag options |
66 | - var form_topic = $("select#id_topic :selected").filter(":selected").val(); //get user selected topic option | |
67 | 68 | $.get("{% url 'subjects:reports:get_tags' %}?resource_class_name="+fields[0].value+"&subject_id={{subject.id}}"+"&topic_choice="+form_topic, function(data){ |
68 | 69 | fields[1].options.length = 0; |
69 | 70 | for(var j = 0; j < data.tags.length; j++){ |
... | ... | @@ -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 | 92 | </script> |
90 | 93 | {% endblock content %} |
91 | 94 | \ No newline at end of file | ... | ... |
reports/views.py
... | ... | @@ -58,7 +58,7 @@ class ReportView(LoginRequiredMixin, generic.FormView): |
58 | 58 | |
59 | 59 | #set formset |
60 | 60 | resourceTagFormSet = formset_factory(ResourceAndTagForm, formset=BaseResourceAndTagFormset) |
61 | - resourceTagFormSet = resourceTagFormSet(initial=[{'class_name': classes, 'tag':tags}]) | |
61 | + resourceTagFormSet = resourceTagFormSet() | |
62 | 62 | context['resource_tag_formset'] = resourceTagFormSet |
63 | 63 | return context |
64 | 64 | |
... | ... | @@ -131,6 +131,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
131 | 131 | context['end_date'] = params_data['end_date'] |
132 | 132 | context['subject'] = subject |
133 | 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 | 135 | context['data'], context['header'] = self.get_mural_data(subject, params_data['init_date'], params_data['end_date'], |
135 | 136 | params_data.getlist('resource'), params_data.getlist('tag')) |
136 | 137 | return context |
... | ... | @@ -148,6 +149,7 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
148 | 149 | |
149 | 150 | header = ['User'] |
150 | 151 | |
152 | + #For each student in the subject | |
151 | 153 | for student in students: |
152 | 154 | data[student] = [] |
153 | 155 | |
... | ... | @@ -202,7 +204,6 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
202 | 204 | |
203 | 205 | |
204 | 206 | #VAR08 through VAR_019 of documenttation: |
205 | - print(resources_id) | |
206 | 207 | resources_data = self.get_resources_and_tags_data(resources_id, tags_id, student, subject) |
207 | 208 | |
208 | 209 | interactions = {**interactions, **resources_data} |
... | ... | @@ -246,29 +247,47 @@ class ViewReportView(LoginRequiredMixin, generic.TemplateView): |
246 | 247 | data = {} |
247 | 248 | |
248 | 249 | for i in range(len(resources)): |
249 | - print(data) | |
250 | - print(resources) | |
251 | - print(resources[i]) | |
252 | - print(tags[i]) | |
253 | 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 | 251 | user_id = student.id, context__contains = {'subject_id': subject.id}).count() |
255 | 252 | |
256 | 253 | return data |
257 | 254 | |
258 | 255 | |
259 | - | |
256 | +""" | |
257 | +Get all possible resource subclasses available for that topic selected | |
258 | +""" | |
260 | 259 | def get_resources(request): |
261 | 260 | |
262 | 261 | #get all possible resources |
263 | 262 | classes = Resource.__subclasses__() |
264 | 263 | |
265 | 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 | 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 | 291 | def get_tags(request): |
273 | 292 | resource_type = request.GET['resource_class_name'] |
274 | 293 | subject = Subject.objects.get(id=request.GET['subject_id']) | ... | ... |