On Friday, January 26, 2018 at 3:12:19 PM UTC-5, Melvyn Sopacua wrote:
There are a bunch of issues with this code:
1) Spell Physical correctly:
> 2 - Phyiscal
> if form.data['handicapped'] is 'Physical' or 'Mental':
> handicapped = forms.ChoiceField(choices=[(x, x) for x in ('-------',
> 'Mental', 'Physcal')], required=False)
Comparison of non boolean or None values using "is" instead of "==":
> if form.data['handicapped'] is 'Physical' or 'Mental':
Use of or as if natural language in RHS of comparisons (should be a == x or a
== y, not a == x or y):
> if form.data['handicapped'] is 'Physical' or 'Mental':
> if form['handicapped'].data == 1 or 2:
So this reads as if someone with very little knowledge of Python is modifying
a 3rd party app, written by someone with a decent amount of Django experience.
Finally, when accessing form data from a valid form, we access
form.cleaned_data and generally use a local variable to reference the dict:
if form.is_valid():
data = form.cleaned_data
# do stuff with data
--
Melvyn Sopacua
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/394ce2de-fc0c-4ed2-9c89-7dab9a1c727a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment