Reduce User monkeypatching#4197
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is 🚀 New features to boost your workflow:
|
mathjazz
reviewed
Jun 9, 2026
mathjazz
left a comment
Collaborator
There was a problem hiding this comment.
Looks good.
Could we document which helpers intentionally remain monkeypatched on User, and why? The split is reasonable, but without a short comment, it’s hard to tell later whether a remaining add_to_class() method is intentional or just not migrated yet.
mathjazz
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Built on top of #4196, actual diff here is here -- so will probably need a rebase before merging.Edit: Done.Over time, we've ended up monkeypatching a plethora of functionality onto the base User object, via its
add_to_class()method. While this does make the methods and properties available everywhere, they're also hard to discover and get no editor support.This PR moves most of these utility functions into
pontoon.base.badge_utils,pontoon/base/notification_utils,pontoon.base.user_utils. A few are left in to keep them available in templates, which would otherwise need to have their contexts include the utility-provied values. For the methods and properties left on User, a type-hinting-only subclass is provided for better editor support -- this also provides a place to define the model's foreign-key relationships.