mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
pedagogy: enhance StarList widget
This commit is contained in:
parent
851231869b
commit
e475273cd3
@ -77,6 +77,16 @@ class UVForm(forms.ModelForm):
|
||||
class StarList(forms.NumberInput):
|
||||
template_name = "pedagogy/starlist.jinja"
|
||||
|
||||
def __init__(self, nubmer_of_stars=0):
|
||||
super(StarList, self).__init__(None)
|
||||
self.number_of_stars = nubmer_of_stars
|
||||
|
||||
def get_context(self, name, value, attrs):
|
||||
context = super(StarList, self).get_context(name, value, attrs)
|
||||
context["number_of_stars"] = range(0, self.number_of_stars)
|
||||
context["translations"] = {"do_not_vote": _("Do not vote")}
|
||||
return context
|
||||
|
||||
|
||||
class UVCommentForm(forms.ModelForm):
|
||||
"""
|
||||
@ -99,11 +109,11 @@ class UVCommentForm(forms.ModelForm):
|
||||
"comment": MarkdownInput,
|
||||
"author": forms.HiddenInput,
|
||||
"uv": forms.HiddenInput,
|
||||
"grade_global": StarList,
|
||||
"grade_utility": StarList,
|
||||
"grade_interest": StarList,
|
||||
"grade_teaching": StarList,
|
||||
"grade_work_load": StarList,
|
||||
"grade_global": StarList(5),
|
||||
"grade_utility": StarList(5),
|
||||
"grade_interest": StarList(5),
|
||||
"grade_teaching": StarList(5),
|
||||
"grade_work_load": StarList(5),
|
||||
}
|
||||
|
||||
def __init__(self, author_id, uv_id, *args, **kwargs):
|
||||
|
@ -1,5 +1,4 @@
|
||||
<div>
|
||||
{# <input name="{{ widget.name }}" id="{{ widget.name }}" hidden type="number" {% include "django/forms/widgets/attrs.html" %}></input> #}
|
||||
<style>
|
||||
.checked {
|
||||
color : orange;
|
||||
@ -16,14 +15,24 @@
|
||||
|
||||
</style>
|
||||
|
||||
{% for i in i|rjust:5 %}
|
||||
<label class="star">
|
||||
<input type="radio" name="{{ widget.name }}" value="-1" onclick='
|
||||
var stars = document.getElementsByClassName("{{ widget.name }}");
|
||||
for (var i = 0; i < stars.length; i++){
|
||||
var attrs = stars[i].getAttribute("class");
|
||||
attrs = attrs.replace("unchecked", "");
|
||||
attrs = attrs.replace("checked", "");
|
||||
stars[i].setAttribute("class", attrs + " unchecked");
|
||||
}
|
||||
' checked>
|
||||
<span class="fa fa-times-circle"> {{ translations.do_not_vote }}</span>
|
||||
</label>
|
||||
{% for i in number_of_stars %}
|
||||
<label class="star">
|
||||
<input type="radio" name="{{ widget.name }}" value="{{ forloop.counter0 }}" onclick='
|
||||
var stars = document.getElementsByClassName("{{ widget.name }}");
|
||||
// console.log(Array.from(this.parentNode.parentNode.children).filter(el => el.className == "star"));
|
||||
|
||||
for (var i = 0; i < 5; i++){
|
||||
console.log(i);
|
||||
for (var i = 0; i < stars.length; i++){
|
||||
var attrs = stars[i].getAttribute("class");
|
||||
attrs = attrs.replace("unchecked", "");
|
||||
attrs = attrs.replace("checked", "");
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% import "pedagogy/macros.jinja" as macros%}
|
||||
{% from "pedagogy/macros.jinja" import display_star %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}UV Details{% endtrans %}
|
||||
@ -15,20 +15,20 @@
|
||||
<p>{{ object.key_concepts|markdown }}</p>
|
||||
<p>{% trans %}UV manager: {% endtrans %}{{ object.manager }}</p>
|
||||
|
||||
<p>{{ object.grade_global_average }}</p>
|
||||
<p>{{ object.grade_utility_average }}</p>
|
||||
<p>{{ object.grade_interest_average }}</p>
|
||||
<p>{{ object.grade_teaching_average }}</p>
|
||||
<p>{{ object.grade_work_load_average }}</p>
|
||||
<p>{{ display_star(object.grade_global_average) }}</p>
|
||||
<p>{{ display_star(object.grade_utility_average) }}</p>
|
||||
<p>{{ display_star(object.grade_interest_average) }}</p>
|
||||
<p>{{ display_star(object.grade_teaching_average) }}</p>
|
||||
<p>{{ display_star(object.grade_work_load_average) }}</p>
|
||||
|
||||
{% if object.comments.exists() %}
|
||||
<h2>{% trans %}Comments{% endtrans %}</h2>
|
||||
{% for comment in object.comments.all() %}
|
||||
<p>{{ macros.display_star(comment.grade_global) }}</p>
|
||||
<p>{{ macros.display_star(comment.grade_utility) }}</p>
|
||||
<p>{{ macros.display_star(comment.grade_interest) }}</p>
|
||||
<p>{{ macros.display_star(comment.grade_teaching) }}</p>
|
||||
<p>{{ macros.display_star(comment.grade_work_load) }}</p>
|
||||
<p>{{ display_star(comment.grade_global) }}</p>
|
||||
<p>{{ display_star(comment.grade_utility) }}</p>
|
||||
<p>{{ display_star(comment.grade_interest) }}</p>
|
||||
<p>{{ display_star(comment.grade_teaching) }}</p>
|
||||
<p>{{ display_star(comment.grade_work_load) }}</p>
|
||||
<p>{{ comment.comment|markdown }}</p>
|
||||
<p>{% trans %}Published: {% endtrans %}{{ comment.publish_date }}</p>
|
||||
<p>{% trans %}Author: {% endtrans %}{{ comment.author }}</p>
|
||||
|
Loading…
Reference in New Issue
Block a user