I am trying to loop through a list of known elements so I can check if they were submitted properly, then do something with them. Problem is, my elements are strings, but the corresponding element object is needed to assign a value to a user object.
Should something else be where eval(element) is?
elements = ('first_name', 'last_name', 'email')
u = request.user
for element in elements:
if not element in form.errors:
dajax.alert('alert: %s' % form.cleaned_data[element])
u.eval(element) = form.cleaned_data[element]
dajax.add_css_class('div #%s' % element , 'form-group has-success')
setattr,getattr... and you shall find the answer.if not element in form.errors:. As shown here, it should be:if element not in form.errors:(I know the link talks aboutis, but the same rule applies toin).dictattribute with keys'first_name','last_name', and'email'instead of three separate attributes, you wouldn't need a fancysetattr(thingy, element, value)fancy, justthingy.elements[element] = value. See this blog post and this one for more details.