Re: Whitespace handling in newforms modelforms
You can use Form inheritance to redefine default behaviour, so you will be just writing down just a strip and after making all your forms inherit from your BaseForm they all will strip fields 2008/2/18, James Bennett <[EMAIL PROTECTED]>: > > > On Feb 18, 2008 2:37 PM, web-junkie <[EMAIL PROTECTED]> wrote: > > why isn't whitespace automatically stripped from fields when using > > modelforms? This would be convenient. > > Up until the moment you need to store some source code written in the > language Django uses. > > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of > correct." > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Whitespace handling in newforms modelforms
On Feb 18, 2008 2:37 PM, web-junkie <[EMAIL PROTECTED]> wrote: > why isn't whitespace automatically stripped from fields when using > modelforms? This would be convenient. Up until the moment you need to store some source code written in the language Django uses. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Whitespace handling in newforms modelforms
On Mon, 2008-02-18 at 12:37 -0800, web-junkie wrote: > Hi, > > why isn't whitespace automatically stripped from fields when using > modelforms? This would be convenient. Convenient in your case. Absolutely tragic for situations where whitespace is important. So that's why it doesn't happen automatically. I've sometimes thought we could one day add a "strip space" option to CharField and TextField. Not sure how that would translate up to ModelForms, though. You might have to manually tweak the attribute in those cases. Anyway, that's for the future. As to how to do it now: add a clean_FOO() method for each field FOO that you want to strip spaces from (see the newforms docs). Then read the value out of self.cleaned_data, strip it and return it. It won't be too repetitive, since you can write a factory function to do most of the work. Regards, Malcolm -- The hardness of butter is directly proportional to the softness of the bread. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Whitespace handling in newforms modelforms
Hi, > why isn't whitespace automatically stripped from fields when using > modelforms? This would be convenient. It may be convenient for many cases but for many others that approach would *lose* information irrecoverably. What if you wanted to have some fields stored with their whitespace preserved? Say a Textarea field where a sentence typed in with a line break at the end needs to be interpreted differently than one without. For example, if you needed to use Markdown on such a field, then 2 spaces followed by a line break causes a to be generated by Markdown. Stripping such a field would cause a problem there. > Is there a reason for not doing so, where is one supposed to do that? - Add clean_ methods to the modelform class and strip() fields there (or in the general clean() method.) - You can also override save() on your models and strip() out relevant fields before the data gets saved. -Rajesh Dhawan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Whitespace handling in newforms modelforms
Hi, why isn't whitespace automatically stripped from fields when using modelforms? This would be convenient. Is there a reason for not doing so, where is one supposed to do that? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---