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

Task types #636

Merged
merged 2 commits into from
Mar 20, 2025
Merged

Task types #636

merged 2 commits into from
Mar 20, 2025

Conversation

Dym03
Copy link
Contributor

@Dym03 Dym03 commented Mar 16, 2025

Added Task types for possible sorting and grouping of the tasks. Enums are solved using a django_enums, could lead to easier comparison of enums.

Fixes: #578

@geordi
Copy link
Member

geordi commented Mar 17, 2025

Thanks for your contribution! Please, try to squash a few commits.

@Kobzol
Copy link
Collaborator

Kobzol commented Mar 17, 2025

For review it's easier to see the individual changes, so you can keep it like this for now. I'll try to take a look soon-ish. Thanks!

Copy link
Collaborator

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR! It looks really good, and would already provide value to us. I left some comments on things that I'd like to change.

api/views.py Outdated
@@ -509,6 +509,9 @@ def set_subject(task):
else:
task.plagiarism_key = plagiarism_key[:255]

if data.get("type"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the type will be invalid, this will end in 500 server error. Let's check if the type is valid based on the TextChoices values, and if not, return a proper 400 bad client request error.

@Dym03
Copy link
Contributor Author

Dym03 commented Mar 18, 2025

I have hopefully resolved all of the problems mentioned in the feedbacks. Only problem with the null values are in the admin page, where they are now required, and i wasn't able to add an option with null as an option, this could be solved with adding a blank=True in the definition, whereas this would provide null as a default option. This depends on you.
Small frontend changes were made, preview can be seen on the next picture.
image

@Kobzol
Copy link
Collaborator

Kobzol commented Mar 20, 2025

Sorry, that was a small misunderstanding, we didn't necessarily want to have all the types from Edison, just wanted to point out which ones exist :)

I would go for this set, to make it simpler than Edison:

HOMEWORK
PROJECT
EXAM
LABORATORY
OTHER

I played with this locally a bit and I have to say that I'm a bit worried about the usage of the enum. It's quite strict and if we ever rename one of the fields or somehow wrong stuff appears in the DB, the server will not have a good time. We could work around that using type = EnumField(TaskType, null=True, constrained=False, strict=False), but at that point we might just as well use a string. This kind of usage also has a big disadvantage in that it changes the field type - if there is an unknown value, it will be a string, while if there's a known value, it will be an enum instance, which is super confusing and error-prone.

I would just use a normal string, as we do for the existing enums (e.g. Day). With TextChoices, it's relatively easy to work with them even in the admin. It cannot be reset to NULL in admin, but we don't really ever want to reset the type to NULL after setting it for the first time anyway.

@Dym03
Copy link
Contributor Author

Dym03 commented Mar 20, 2025

Okey, it was not specified, so i added all, but got it, will update that. About the enum thing, i didn't test it that much, but it was only proposed solution. After all the Enum is to my understanding just a wrapper around the choices, so i will change it. Is it a wanted feature to be able to leave a new task without a task type or to leave it blank. Or every new task created in the admin should have a type ? @Kobzol

@Kobzol
Copy link
Collaborator

Kobzol commented Mar 20, 2025

The enum was a good idea, but I worry that with our state of the database in Kelvin it would be a bit too easy to get into some weird state, and then the website would essentially become bricked until someone updated the DB manually to fix the invalid enum values 😅

We don't really create tasks in the admin, so it's not super important how it behaves there. For creating tasks on Kelvin, on the EditTask page, I would like to uphold the following rules:

  • If a task is being created, the task type has to be set (the default should be prefilled e.g. to "homework")
  • If a task is being edited, and the the task type was NULL, it can remain NULL when the task is saved
  • If a task is being edited, and the task type was not NULL, it shouldn't be possible to set it back to NULL again

Does that make sense?

@Dym03
Copy link
Contributor Author

Dym03 commented Mar 20, 2025

Makes sense. Will try to implement this behavior :). Thanks for the clarification. I wasn't sure where the task where being created, now that is clear.

Dym03 added a commit to Dym03/kelvin that referenced this pull request Mar 20, 2025
Dym03 added a commit to Dym03/kelvin that referenced this pull request Mar 20, 2025
Dym03 added a commit to Dym03/kelvin that referenced this pull request Mar 20, 2025
Dym03 added a commit to Dym03/kelvin that referenced this pull request Mar 20, 2025
@Dym03 Dym03 force-pushed the task_types branch 2 times, most recently from fcc40d5 to 7f63da2 Compare March 20, 2025 12:41
@Dym03
Copy link
Contributor Author

Dym03 commented Mar 20, 2025

Should be ready for merge now, squashed down into two main commits for backend and frontend.

Copy link
Collaborator

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thank you! Left two minor comments, otherwise it looks pretty good :)

Copy link
Collaborator

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Awesome work. Thank you very much! ❤️

@Kobzol Kobzol added this pull request to the merge queue Mar 20, 2025
Merged via the queue into mrlvsb:master with commit 669ad1f Mar 20, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add types of tasks
3 participants