Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http verbs #1837

Merged
merged 7 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions evap/rewards/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,30 @@ def setUpTestData(cls):
course=course,
)

cls.url = f"/rewards/reward_semester_activation/{cls.semester.pk}/"
cls.url = f"/rewards/reward_semester_activation/{cls.semester.pk}/edit"
richardebeling marked this conversation as resolved.
Show resolved Hide resolved

def test_activate(self):
baker.make(SemesterActivation, semester=self.semester, is_active=False)
self.app.post(self.url + "on", user=self.manager)
response = self.app.post(self.url, user=self.manager)
form = response.forms["form_activation_status"]
form.set("activation_status", "on")
form.submit()
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
self.assertTrue(is_semester_activated(self.semester))

def test_deactivate(self):
baker.make(SemesterActivation, semester=self.semester, is_active=True)
self.app.post(self.url + "off", user=self.manager)
response = self.app.post(self.url, user=self.manager)
form = response.forms["form_activation_status"]
form.set("activation_status", "off")
form.submit()
self.assertFalse(is_semester_activated(self.semester))

def test_activate_after_voting(self):
baker.make(SemesterActivation, semester=self.semester, is_active=False)
self.assertEqual(0, reward_points_of_user(self.student))
response = self.app.post(self.url + "on", user=self.manager)
response = self.app.post(self.url, user=self.manager)
form = response.forms["form_activation_status"]
form.set("activation_status", "on")
response = form.submit()
self.assertContains(response, "3 reward points were granted")
self.assertEqual(3, reward_points_of_user(self.student))
2 changes: 1 addition & 1 deletion evap/rewards/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
path("reward_point_redemption_event/<int:event_id>/export", views.reward_point_redemption_event_export, name="reward_point_redemption_event_export"),
path("reward_point_redemption_event/delete", views.reward_point_redemption_event_delete, name="reward_point_redemption_event_delete"),

path("reward_semester_activation/<int:semester_id>/<str:active>", views.semester_activation, name="semester_activation"),
path("reward_semester_activation/<int:semester_id>/edit", views.semester_activation_edit, name="semester_activation_edit"),
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
]
6 changes: 4 additions & 2 deletions evap/rewards/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ def reward_point_redemption_event_export(request, event_id):
return response


@require_POST
@manager_required
def semester_activation(request, semester_id, active):
def semester_activation_edit(request, semester_id):
semester = get_object_or_404(Semester, id=semester_id)
active = active == "on"
status = request.POST.get("activation_status")
active = status == "on"
richardebeling marked this conversation as resolved.
Show resolved Hide resolved

SemesterActivation.objects.update_or_create(semester=semester, defaults={"is_active": active})
if active:
Expand Down
28 changes: 12 additions & 16 deletions evap/staff/templates/staff_semester_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
{% load evaluation_filters %}

{% block content %}
{{ block.super }}

{{ block.super }}
niklasmohrin marked this conversation as resolved.
Show resolved Hide resolved
<form id="form_activation_status" method="post" action="{% url 'rewards:semester_activation_edit' semester.id%}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<form id="form_activation_status" method="post" action="{% url 'rewards:semester_activation_edit' semester.id%}">
<form id="form_activation_status" method="post" action="{% url 'rewards:semester_activation_edit' semester.id %}">

<input type="hidden" id="activation_status" name="activation_status">
{% csrf_token %}
</form>
<h3>
{{ semester.name }}
{% if request.user.is_manager %}
Expand Down Expand Up @@ -549,23 +553,15 @@ <h3>
{% trans 'Activate reward points' as action_text %}
{% include 'confirmation_modal.html' with modal_id='activateRewardPointsModal' title=title question=question action_text=action_text btn_type='primary' %}
<script type="text/javascript">
function activateRewardPointsModalAction(dataId) {
$.ajax({
type: "POST",
url: "{% url 'rewards:semester_activation' semester.id 'on' %}",
data: {},
success: function(){ location.reload(); },
error: function(){ window.alert("{% trans 'The server is not responding.' %}"); }
});
function setRewardPointActivationStatus(status) {
document.getElementById("activation_status").value = status;
document.getElementById("form_activation_status").submit();
richardebeling marked this conversation as resolved.
Show resolved Hide resolved
}
function activateRewardPointsModalAction() {
setRewardPointActivationStatus("on");
};
function deactivateRewardPoints() {
$.ajax({
type: "POST",
url: "{% url 'rewards:semester_activation' semester.id 'off' %}",
data: {},
success: function(){ location.reload(); },
error: function(){ window.alert("{% trans 'The server is not responding.' %}"); }
});
setRewardPointActivationStatus("off");
}
</script>
{% endblock %}
Expand Down