Skip to content

Bugfix 24 hours validation does not work on report creation#236

Merged
kbeker merged 4 commits intomasterfrom
bugfix-24-hours-validation-does-not-work-on-report-creation
May 27, 2019
Merged

Bugfix 24 hours validation does not work on report creation#236
kbeker merged 4 commits intomasterfrom
bugfix-24-hours-validation-does-not-work-on-report-creation

Conversation

@maciejSamerdak
Copy link
Collaborator

@maciejSamerdak maciejSamerdak commented May 24, 2019

Resolves #221

@maciejSamerdak maciejSamerdak added the bug Something isn't working label May 24, 2019
@maciejSamerdak maciejSamerdak added this to the v0.3.0 milestone May 24, 2019
@maciejSamerdak maciejSamerdak self-assigned this May 24, 2019
@kbeker
Copy link
Contributor

kbeker commented May 24, 2019

@maciejSamerdak mea culpa for deleting branch which was based of this PR :P

@maciejSamerdak
Copy link
Collaborator Author

Ok, now it's back to it's last state

@maciejSamerdak
Copy link
Collaborator Author

@kbeker I shalt not judge thy sins, save it for thy Creator!

Copy link
Contributor

@dybi dybi left a comment

Choose a reason for hiding this comment

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

Please fix one minor issue and it's good to go from my PoV 👍


def validate(self, data: OrderedDict) -> OrderedDict:
data = super().validate(data)
if "date" in data:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, since it seems that the serializer is never created with partial flag (https://www.django-rest-framework.org/api-guide/serializers/#partial-updates), it's safe to assume, that "date" is always present in data. So, please remove the if.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Based on that, I additionally changed data.get("work_hours", 0) to just data["work_hours"]

Copy link
Contributor

@rwrzesien rwrzesien left a comment

Choose a reason for hiding this comment

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

Looks good, but I still think effort put to this could be put into refactoring this view to Django generic, which would auto resolve this issue, as forms always do full_clean() before save().

@kbeker kbeker force-pushed the bugfix-24-hours-validation-does-not-work-on-report-creation branch from 4676b69 to de04803 Compare May 27, 2019 07:43
@kbeker kbeker merged commit de04803 into master May 27, 2019
@kbeker kbeker deleted the bugfix-24-hours-validation-does-not-work-on-report-creation branch May 29, 2019 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation for sum of hours per day being less than 24 does not work on report creation.

4 participants