Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

A different approach for filters #128

Closed
pbu88 opened this issue Sep 18, 2014 · 0 comments · Fixed by #592
Closed

A different approach for filters #128

pbu88 opened this issue Sep 18, 2014 · 0 comments · Fixed by #592
Labels
enhancement New feature, or existing feature improvement
Milestone

Comments

@pbu88
Copy link

pbu88 commented Sep 18, 2014

Hi, first of all, thanks for the useful library.

I want to perform some cleaning in some fields, for example, remove several \n in a row or strip some whitespaces. The cleanest way I found so far was to use filters in the field definition. This is not bad, but for instance, the method clean_field() that will be used as a filter can not be in the field container class (the form class) and only receive one argument (the field data). So I need to add the function globally or static in another class. Something like this:

def clean_my_field(data):
    # remove unnecessary blank lines

class MyForm(Form):
    my_field = TextAreaField(..., filters=[clean_my_field])

Is there a better way to do this? I was expecting something like, I can define inside the form class a method:

class MyForm(Form)
    ...
    def filter_my_field(self, data):
        # remove the unnecessary blank lines

and that every method called filter_<field_name> will be called automatically by either Form.process() method or a similar.

Does this make any sense? I will be willing to implement this and provide tests but I'm not sure if this is wanted.

Thanks for your hard work with WTF :)

@crast crast added the enhancement New feature, or existing feature improvement label Oct 17, 2014
This was referenced Jan 7, 2015
@crast crast added this to the 3.0 milestone Dec 15, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature, or existing feature improvement
Development

Successfully merging a pull request may close this issue.

2 participants