app/soc/views/helper/forms.py
changeset 612 3cca81b1e5a1
parent 472 519c298a4f87
child 639 1f92bd41b914
equal deleted inserted replaced
611:2ec30182e5f1 612:3cca81b1e5a1
   310     insertion into a template
   310     insertion into a template
   311   """
   311   """
   312   field_name = field_name_fmt % {'arg_name': arg_name}
   312   field_name = field_name_fmt % {'arg_name': arg_name}
   313   return SelectQueryArgForm(request.path, arg_name, choices, field_name,
   313   return SelectQueryArgForm(request.path, arg_name, choices, field_name,
   314                             initial={field_name: initial_value})
   314                             initial={field_name: initial_value})
       
   315 
       
   316 
       
   317 def collectCleanedFields(form):
       
   318   """Collects all cleaned fields and returns them with the key_name.
       
   319 
       
   320   Args:
       
   321     form: The form from which the cleaned fields should be collected
       
   322 
       
   323   Returns: All the fields that are in the form's cleaned_data
       
   324   property are returned. If there is a key_name field, it is not
       
   325   included in the returend fields, instead, it is returned as the
       
   326   first element in the returned tuple. If no key_name field is
       
   327   present, None is returned as first value instead.
       
   328   """
       
   329 
       
   330   fields = {}
       
   331 
       
   332   key_name = None
       
   333   if 'key_name' in form.cleaned_data:
       
   334     key_name = form.cleaned_data.pop('key_name')
       
   335 
       
   336   for field, value in form.cleaned_data.iteritems():
       
   337     fields[field] = value
       
   338 
       
   339   return key_name, fields