Skip to content

Commit

Permalink
More student module goal fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
murhum1 committed Oct 8, 2024
1 parent a49cf4d commit 2f99612
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 138 deletions.
37 changes: 8 additions & 29 deletions course/migrations/0060_studentmodulegoal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-09-24 12:42
# Generated by Django 4.2.13 on 2024-10-08 08:17

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -7,39 +7,18 @@
class Migration(migrations.Migration):

dependencies = [
("userprofile", "0008_delete_studentmodulegoal"),
("course", "0059_submissiontag"),
('userprofile', '0006_auto_20210812_1536'),
('course', '0059_submissiontag'),
]

operations = [
migrations.CreateModel(
name="StudentModuleGoal",
name='StudentModuleGoal',
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("goal_percentage", models.FloatField(default=100.0)),
("goal_points", models.IntegerField(default=0)),
(
"module",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="course.coursemodule",
),
),
(
"student",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="userprofile.userprofile",
),
),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('goal_points', models.IntegerField(default=0)),
('module', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='course.coursemodule')),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='userprofile.userprofile')),
],
),
]
17 changes: 0 additions & 17 deletions course/migrations/0061_remove_studentmodulegoal_goal_percentage.py

This file was deleted.

5 changes: 3 additions & 2 deletions e2e_tests/test_points_goal_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ def test_points_goal_reached(page: Page) -> None:
page.get_by_role("button", name="Save").click()
expect(page.locator("#success-alert")).to_contain_text("Succesfully set personalized points goal")
page.get_by_role("button", name="Close", exact=True).click()
progress_bar_locator = page.locator("#progress-questionnaires > .progress > .progress-bar")
expect(progress_bar_locator).to_have_class("progress-bar progress-bar-striped progress-bar-primary")
progress_bar_locator = page.locator("#progress-questionnaires > .progress > .aplus-progress-bar")
expect(progress_bar_locator).\
to_have_class("aplus-progress-bar aplus-progress-bar-striped aplus-progress-bar-primary")
6 changes: 3 additions & 3 deletions exercise/cache/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ class ModulePoints(DifficultyStats, ModuleEntryBase[LearningObjectPoints]):
_children_unconfirmed: bool
is_model_answer_revealed: bool
confirmable_children: bool
personalized_points_module_goal_points: Optional[int]
module_goal_points: Optional[int]

children_unconfirmed = RevealableAttribute[bool]()

Expand Down Expand Up @@ -920,7 +920,7 @@ def _generate_data(
self._points_by_difficulty = {}
self._true_unconfirmed_points_by_difficulty = {}
self._unconfirmed_points_by_difficulty = {}
self.personalized_points_module_goal_points = None
self.module_goal_points = None
self.instance = precreated.get_or_create_proxy(
CachedPointsData, *self.instance._params, user_id, modifiers=self._modifiers
)
Expand All @@ -943,7 +943,7 @@ def _generate_data(

try:
student_module_goal = StudentModuleGoal.objects.get(module_id=module_id, student_id=user_id)
self.personalized_points_module_goal_points = student_module_goal.goal_points
self.module_goal_points = student_module_goal.goal_points
except StudentModuleGoal.DoesNotExist:
pass

Expand Down
4 changes: 2 additions & 2 deletions exercise/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ class Meta:
fields = ['submitters']

class StudentModuleGoalForm(forms.Form):
personalized_points_goal_input = forms.CharField(
module_goal_input = forms.CharField(
label=_('LABEL_POINTS_GOAL_INPUT'),
max_length=10,
widget=forms.TextInput(attrs={'style': 'width: 66px;', 'class': 'form-control'}),
)

class Meta():
fields = [
'personalized_points_goal_input',
'module_goal_input',
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$(document).ready(function() {
const $pointsGoalForm = $('#pointsGoalForm');
const $inputField = $('#id_personalized_points_goal_input');
const $inputField = $('#id_module_goal_input');
// If points-goal is a number then input it into the field
if (typeof $pointsGoalForm.data('points-goal') === 'number') {
$inputField.val($pointsGoalForm.data('points-goal'))};
Expand Down Expand Up @@ -71,12 +71,12 @@ $(document).ready(function() {

// Update progress-bar style
if (response.goal_points <= $pointsGoalForm.data('points')) {
$progressDiv.find('.progress-bar').removeClass('progress-bar-warning');
$progressDiv.find('.progress-bar').addClass('progress-bar-primary');
$progressDiv.find('.aplus-progress-bar').removeClass('aplus-progress-bar-warning');
$progressDiv.find('.aplus-progress-bar').addClass('aplus-progress-bar-primary');
}
else {
$progressDiv.find('.progress-bar').removeClass('progress-bar-primary');
$progressDiv.find('.progress-bar').addClass('progress-bar-warning');
$progressDiv.find('.aplus-progress-bar').removeClass('aplus-progress-bar-primary');
$progressDiv.find('.aplus-progress-bar').addClass('aplus-progress-bar-warning');
}
// Show the success alert
$('#success-alert').show();
Expand Down Expand Up @@ -129,7 +129,7 @@ $(document).ready(function() {
$progressDiv.attr('data-original-title', updatedTooltipTitle);

// Update progress-bar style
$progressDiv.find('.progress-bar').removeClass('progress-bar-primary');
$progressDiv.find('.aplus-progress-bar').removeClass('aplus-progress-bar-primary');

$('#deletePointsGoalForm').hide();

Expand Down
10 changes: 5 additions & 5 deletions exercise/templates/exercise/_points_progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
<br/>
{% translate 'POINTS_TO_PASS' %}: <span class='text-nowrap'>{{ required }}</span>
{% endif %}
{% if personalized_points_module_goal %}
{% if module_goal %}
<span class='personalized-points-full-text text-nowrap'>
<br/>
{% translate 'PERSONALIZED_POINTS_GOAL' %}:
<span class='personalized-points-text text-nowrap'>
{{ personalized_points_module_goal_points|floatformat:"0" }}
{{ module_goal_points|floatformat:"0" }}
</span>
</span>
{% endif %}"
>
<div class="aplus-progress-bar aplus-progress-bar-striped aplus-progress-bar-{% if full_score %}success{% elif passed %}warning{% else %}danger{% endif %}"
<div class="aplus-progress-bar aplus-progress-bar-striped aplus-progress-bar-{% if full_score %}success{% elif module_goal_achieved %}primary{% elif passed %}warning{% else %}danger{% endif %}"
rel="progressbar" aria-valuenow="{{ points }}" aria-valuemin="0" aria-valuemax="{{ max }}"
style="width:{{ percentage }}%;"></div>
<link rel="stylesheet" href="{% static 'exercise/css/goal_points.css' %}" />
{% if required_percentage %}
<div class="required-points" style="left:{{ required_percentage }}%"></div>
{% endif %}
{% if personalized_points_module_goal %}
<div id="goal-points" class="goal-points" style="left:{{ personalized_points_module_goal|floatformat:0 }}%"></div>
{% if module_goal_percentage %}
<div id="goal-points" class="goal-points" style="left:{{ module_goal_percentage|floatformat:0 }}%"></div>
{% endif %}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load static %}
{% load course %}
{% load exercise %}
<script src="{% static 'exercise/personalized_points_goal.js' %}"></script>
<script src="{% static 'exercise/module_goal.js' %}"></script>

{% get_max_module_points module.id user.id as max_points %}
{% get_module_points module.id user.id as points %}
Expand Down Expand Up @@ -41,9 +41,9 @@ <h4 class="title" id="pointsGoalModalLabel">{% translate "PERSONALIZED_POINTS_MO
>
{% csrf_token %}
<div class="form-group">
{{ form.personalized_points_goal_input.label_tag }}
{{ form.module_goal_input.label_tag }}
<div style="display: flex;">
{{ form.personalized_points_goal_input }} <span style="margin-top: 5px; margin-left: 5px;">/<span id="max-points"> {{ max_points }}</span></span>
{{ form.module_goal_input }} <span style="margin-top: 5px; margin-left: 5px;">/<span id="max-points"> {{ max_points }}</span></span>
</div>
{% if module.points_to_pass %}
<p style="margin-top: 5px;">{% translate "POINTS_TO_PASS" %}: <span id="required-points">{{ module.points_to_pass }}</span></p>
Expand Down
17 changes: 11 additions & 6 deletions exercise/templatetags/exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,15 @@ def _points_data(

max_points = getattr(obj, 'max_points', 0)
required = getattr(obj, 'points_to_pass', 0)
personalized_points_module_goal_points = getattr(obj, 'personalized_points_module_goal_points', None)
if personalized_points_module_goal_points is not None:
personalized_points_module_goal = (personalized_points_module_goal_points / max_points) * 100
module_goal_points = getattr(obj, 'module_goal_points', None)
if module_goal_points is not None:
module_goal_percentage = (module_goal_points / max_points) * 100
else:
personalized_points_module_goal = None
module_goal_percentage = None
module_goal_achieved = (
module_goal_points
and points >= module_goal_points
)

data = {
'points': points,
Expand All @@ -249,8 +253,9 @@ def _points_data(
'unofficial_submission_type': getattr(obj, 'unofficial_submission_type', None),
'confirmable_points': getattr(obj, 'confirmable_points', False),
'feedback_revealed': getattr(obj, 'feedback_revealed', True),
'personalized_points_module_goal_points': personalized_points_module_goal_points,
'personalized_points_module_goal': personalized_points_module_goal,
'module_goal_points': module_goal_points,
'module_goal_percentage': module_goal_percentage,
'module_goal_achieved': module_goal_achieved,
}
reveal_time = getattr(obj, 'feedback_reveal_time', None)

Expand Down
4 changes: 2 additions & 2 deletions exercise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
class StudentModuleGoalFormView(CourseModuleBaseView, BaseFormView):
access_mode = ACCESS.STUDENT
form_class = StudentModuleGoalForm
template_name = "exercise/personalized_points_goal_modal.html"
template_name = "exercise/module_goal_modal.html"
success_url = '/'

def delete(self, request: HttpRequest, *args: Any, **kwargs: Any) -> JsonResponse:
Expand All @@ -641,7 +641,7 @@ def delete(self, request: HttpRequest, *args: Any, **kwargs: Any) -> JsonRespons


def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> JsonResponse:
points_goal = request.POST.get('personalized_points_goal_input')
points_goal = request.POST.get('module_goal_input')

cached_points = CachedPoints(self.instance, request.user, True)
cached_module, _, _, _ = cached_points.find(self.module)
Expand Down
12 changes: 6 additions & 6 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1273,23 +1273,23 @@ msgstr "Points goal"
msgid "POINTS_GOAL_TOOLTIP"
msgstr "Set a personal points goal for this module. This goal is only visible to you. Once the goal has been reached, the points progress bar changes colour to blue."

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_TITLE"
msgstr "Set personalized points goal for module"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "LABEL_POINTS_GOAL_INPUT"
msgstr "Input personalized goal as a percentage or points (e.g., 50% or 150)"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_SUCCESS"
msgstr "Succesfully set personalized points goal"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_FAILURE"
msgstr "Failed to set personalized points goal"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_NOT_NUMBER"
msgstr "Input needs to be a percentage or a number (e.g., 50% or 150)"

Expand Down Expand Up @@ -4148,7 +4148,7 @@ msgid "POINTS"
msgstr "Points"

#: exercise/templates/exercise/_points_progress.html
#: exercise/templates/exercise/save_personalized_points_goal.html
#: exercise/templates/exercise/save_module_goal.html
msgid "POINTS_TO_PASS"
msgstr "Points to pass"

Expand Down
10 changes: 5 additions & 5 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -763,23 +763,23 @@ msgstr "Pistetavoite"
msgid "POINTS_GOAL_TOOLTIP"
msgstr "Aseta henkilökohtainen pistetavoite tälle moduulille. Tavoite näkyy vain sinulle. Kun tavoite on saavutettu, pistepalkki vaihtaa värin siniseksi."

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_TITLE"
msgstr "Aseta pistetavoite moduulille"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "LABEL_POINTS_GOAL_INPUT"
msgstr "Anna pistetavoite prosentteina tai pisteinä (esim. 50% tai 150)"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_SUCCESS"
msgstr "Pistetavoite asetettu onnistuneesti"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_FAILURE"
msgstr "Pistetavoitteen asettaminen epäonnistui"

#: exercise/templates/exercise/personalized_points_goal_modal.html
#: exercise/templates/exercise/module_goal_modal.html
msgid "PERSONALIZED_POINTS_MODAL_NOT_NUMBER"
msgstr "Pistetavoite tulee antaa joko prosentteina tai pisteinä (esim. 50% or 150)"

Expand Down
36 changes: 0 additions & 36 deletions userprofile/migrations/0007_studentmodulegoal.py

This file was deleted.

16 changes: 0 additions & 16 deletions userprofile/migrations/0008_delete_studentmodulegoal.py

This file was deleted.

0 comments on commit 2f99612

Please sign in to comment.