question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to access the alternative of a Field Type

See original GitHub issue

I 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:closed
  • Created 10 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dairikicommented, Nov 8, 2022

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 your value_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 the Record is actually constructed. So at the time value_from_raw is called, there is no record

0reactions
dairikicommented, Nov 8, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found