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

Main language for evaluations #2367

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

hansegucker
Copy link
Collaborator

No description provided.

@richardebeling richardebeling linked an issue Jan 19, 2025 that may be closed by this pull request
Comment on lines +311 to +313
with self.assertRaises(ValueError):
form["main_language"] = "some_other_wrong_value"
form.submit(name="operation", value="save")
Copy link
Member

Choose a reason for hiding this comment

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

Like the "Invalid value doesn't work"-block in 303, I think this will already fail on setting the form field as django webtest throws when we try to set a value that is not in the choices list. I think testing that server-side validation works is a good idea here, not sure if it can be done with WebTest form framework though. I think in the past we always manually crafted POST requests to achieve this.

def _migrate(apps, schema_editor):
Evaluation = apps.get_model("evaluation", "Evaluation")
for evaluation in Evaluation.objects.filter(state__gte=40):
evaluation.main_language = "de"
Copy link
Member

Choose a reason for hiding this comment

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

Why? I would have expected "undecided" (which is the default value -> no explicit migration code needed?)

(If we keep this, can we use some named variable instead of the magic 40?)

def editor_approve(self):
pass

@transition(
field=state,
source=[State.NEW, State.PREPARED, State.EDITOR_APPROVED],
target=State.APPROVED,
conditions=[lambda self: self.general_contribution_has_questionnaires],
conditions=[lambda self: self.general_contribution_has_questionnaires and self.has_valid_main_language],
Copy link
Member

Choose a reason for hiding this comment

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

The issue says that staff users should be able to set "undecided". I think this change here would block that workflow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In preparation, yes. But at the point of approval (not editor approval!), a language has to be determined.

@@ -1920,6 +1920,38 @@ def test_evaluation_create(self):
form.submit()
self.assertEqual(Evaluation.objects.get().name_de, "lfo9e7bmxp1xi")

def _set_valid_form(self, form):
Copy link
Member

Choose a reason for hiding this comment

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

factoring out the helper is nice -- but we should also use it in test_evaluation_create then :D

self.assertNotEqual(Evaluation.objects.first().state, self.evaluation.State.APPROVED)

form["main_language"] = "en"
form.submit("operation", value="approve")
Copy link
Member

Choose a reason for hiding this comment

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

We probably have to add an assertion that the response now doesn't contain the above error anymore (our views return 200 even if there is a business logic error / form validation failed)

raise SuspiciousOperation("Invalid POST operation")

evaluation_form = EvaluationForm(
request.POST or None, instance=evaluation, semester=evaluation.course.semester, operation=operation
Copy link
Member

Choose a reason for hiding this comment

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

random consideration: A narrower, more precise interface would be passing require_main_language: bool instead of passing an operation string that implicitly allows to infer that bool

data-bs-placement="bottom"
title="{{ language_name }}"
role="button"
href="{% url 'student:vote' evaluation.pk %}?language={{ language_code }}"
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be a POST-form, not a GET-anchor. (Currently, this wouldn't need the CSRF token)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why should that need a CSRF token? As this won't set the language anywhere in the backend, it's only display logic determined by the GET parameter. @janno42 was OK with this.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I assumed that this would save the language so that if a user came back later to the same evaluation, they would still go back to the language they last selected.

If we keep the language stateless, the anchor is fine here, but then we don't need the csrf_token above.

model_name="evaluation",
name="main_language",
field=models.CharField(
choices=[("en", "English"), ("de", "Deutsch"), ("x", "undecided")],
Copy link
Collaborator

@Kakadus Kakadus Jan 27, 2025

Choose a reason for hiding this comment

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

I want to note that now a new migration is needed when the user changes the languages in the settings. Is it okay that this is still a setting then? I can imagine that this is unexpected from a django setting

If not, then this can probably become a models.TextChoices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Independent questionnaire language
3 participants