Giter VIP home page Giter VIP logo

Comments (8)

sloria avatar sloria commented on May 22, 2024

Thanks @dwieeb!

Another way to get the same functionality as use is through a custom field.

class Use(fields.Field):

    def __init__(self, func, child=None, **kwargs):
        super().__init__(**kwargs)
        self.func = func
        self.child = child

    def _deserialize(self, value, attr, data):
        if self.child:
            value = self.child.deserialize(value, attr, data)
        return self.func(value)

@use_args({
    'foo': Use(lambda v: v.upper(), fields.Str())
})
def myview(args):
    #...

from webargs.

imhoffd avatar imhoffd commented on May 22, 2024

Interesting. Perhaps this could exist in the webargs codebase as fields.Lambda or fields.Alter or something?

from webargs.

sloria avatar sloria commented on May 22, 2024

Perhaps in the future. In the interest of keeping the core small, I'm going to hold off on adding this to the code base for now.

from webargs.

imhoffd avatar imhoffd commented on May 22, 2024

👍 I agree.

Besides, I think I would actually prefer the marshmallow solution, as it allows access to other fields and does not require custom fields.

Thanks for webargs. With the marshmallow integration it's the best solution out there even without being "stable"... And I've used pretty much everything out there for flask, including rolling my own.

from webargs.

sloria avatar sloria commented on May 22, 2024

Thanks for the encouraging words!

from webargs.

sloria avatar sloria commented on May 22, 2024

I've moved this to the Wiki here: https://github.com/sloria/webargs/wiki/Recipes . Thanks again @dwieeb !

from webargs.

imhoffd avatar imhoffd commented on May 22, 2024

You didn't need to do that; I'm not sure if a migration guide of a lesser used feature from an alpha version is helpful to people, especially as the 1.0 code base matures.

What's more important is that the documentation somehow shows the pre-processing and post-processing of schemas. Currently, there's just a link to the marshmallow api in the "marshmallow integration" section. People coming into webargs with no prior marshmallow experience may be looking in the docs for how to process values before they enter their route functions. Right now, it looks as if webargs doesn't have this.

I could get around to writing up something for the docs if I find time.

from webargs.

sloria avatar sloria commented on May 22, 2024

I agree; I think it would be useful to have some documentation for pre- and post-processing behavior. I would certainly welcome a PR.

from webargs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.