Skip to content
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

allow callback for field properties, improve MetaMixin for WebPage doc #7

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

yoshson
Copy link
Contributor

@yoshson yoshson commented Nov 16, 2023

No description provided.

@yoshson yoshson requested a review from matthiask November 16, 2023 10:01
super().__init__(property, *args, **kwargs)

def contribute_to_class(self, cls, name):
self.field.contribute_to_class(cls, name)
self.value = lambda obj: (
self.value = lambda obj: self.callback(
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, das ist eher eine Art coerce Funktion, oder? https://github.com/matthiask/speckenv/blob/49dd513950b7cce09767805411baeccb0a3ab0b5/speckenv.py#L54

Wärs alternativ etwas flexibler, wenn der Callback das ganze Objekt erhält, und nicht nur den Wert des Attributs? Dann würde value=lambda obj: obj.image.opengraph if obj.image else "" funktionieren.

Und dann könnte auch der Fallback so gelöst werden, zB value=lambda obj: obj.name or obj.fallback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gute Idee, ich versuchs mal.

coerce

@yoshson yoshson merged commit 823e033 into main Nov 28, 2023
3 checks passed
@yoshson yoshson deleted the ys/structured-data branch November 28, 2023 08:24
@matthiask
Copy link
Member

Merci!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants