-
-
Notifications
You must be signed in to change notification settings - Fork 783
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
Updates for metadata information #7343
Updates for metadata information #7343
Conversation
- Override 'label' values with 'verbose_name' values - Only if 'label' is *not* translated, but 'verbose_name' is - Allows the translated model fields name to be pushed through to the metadata framework
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
…venTree into metadata-improvements
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7343 +/- ##
=======================================
Coverage 83.78% 83.78%
=======================================
Files 1049 1049
Lines 46005 46031 +26
Branches 1386 1386
=======================================
+ Hits 38545 38569 +24
- Misses 7099 7101 +2
Partials 361 361
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; Should we add tests for this (translation)?
Yeah, I'll add some unit tests so that we don't get any regressions |
* Updates for metadata information - Override 'label' values with 'verbose_name' values - Only if 'label' is *not* translated, but 'verbose_name' is - Allows the translated model fields name to be pushed through to the metadata framework * Remove unused import * Add unit testing for metadata lookup * Update serializer: allow 'category' to be blank * Bump API version * Fix for unit test
This PR fixes a subtle bug which existed in our "metadata" implementation, which extracted database field information and provided it to the DRF API.
Any custom serializer fields which do not have an explicitly defined label would default to their attribute name, which was an untranslated string.
So, something like this:
Would result in a
label
value of "Category" (which is simply extracted from the name of the serializer field) even if it pointed to an underlying database model field. The "verbose_name" of the field (in this casePart Category
) was not obtained.Worse, the auto-generated labels were not exposed to the translation framework at any point. So, any custom DRF fields were never getting translated.
This patch adds some extra introspection steps, and will override a raw stirng value with a translated string value (if it exists). It also adds explicit mapping from
verbose_name
(on the model field) tolabel
(on the serializer field).Note: If a translated string exists on the serializer field it will not be overridden by the model field