How to access the alternative of a Field Type
See original GitHub issueI have a custom field type to parse an ingredient line of a recipe. For example: “2 cups chocolate” or “1 banana” or “1 can Marzano tomatoes, chopped”. As you can see, the format is quite variable so I cannot simply split the string by some delimiter. Instead I have a list of pre-defined measurement units (‘cups’, ‘can’) that I check to split the components.
But now comes the tricky part, my site is multi-lingual and I have a different list of measurements for each alternative.
However, when lektor initializes my custom field (value_from_raw
) I have no way to get the alternative of the calling record.
Is there a way to get the alternative of a Field Type?
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Introduction to data types and field properties - Microsoft Support
On the Modify Fields tab, in the Fields & Columns group, click Add Fields, Access displays a list of data types that you...
Read more >Alternative access control to fields of graphql types
I'd like to propose alternative approach to limiting user access to certain fields of graphql types. One example usage of presented ...
Read more >Alternate ACCESS for ELLs - WIDA
Scoring. Alternate ACCESS tests students' language in the four domains: Listening, Reading, Speaking, Writing. Test scores can be used to inform instruction ...
Read more >An alternative to having fields that might not be used in a class
You would have a Card parent class, with derived classes with specific fields for specific games. This lets you use collections of Card...
Read more >Field Types and Uses in Access 2019 Databases - dummies
Calculated: Use this field type when you want to fill the field in question with the result of a formula that uses one...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah. If you want access to the record (so that you can access
record.alt
), you’ll need to resort to returning a “descriptor” from yourvalue_from_raw
(and defer further processing of the value until that descriptor’s__get__
is called.)See Lektor’s MarkdownType for an example of how that’s done.
The issue (IIRC) is that
value_from_raw
gets called early in the process of reading the.lr
file data, before theRecord
is actually constructed. So at the timevalue_from_raw
is called, there is norecord
…I don’t think it’s used anywhere.
The API is evidently copied from Python’s attribute descriptor API. Maybe, originally, the idea was to use the
property
decorator to define field descriptors? I don’t know.