﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23927	Decouple Form field_names to its representation in HTML	jorgecarleitao	nobody	"Consider a form

{{{
class SearchForm(forms.Form):
    search = forms.CharField(required=False)
}}}

and a view that uses the form in a GET:

{{{
def get_names(request):

    if request.method == 'GET':
        form = SearchForm(request.GET)
        if form.is_valid():
            query_result = ...
            context = {'results': query_result, 'form': form}
        else:
            # handle failure
    else:
        form = SearchForm()

    return render(request, 'name.html', {'form': form})
}}}
   
When the form is submitted trough GET, one gets an url like `www.example.com/persons?search=...`

However, we typically want to i18n the parameters of the URL. I don't find an easy way to do that. The way I'm doing now is
{{{
    def add_prefix(self, field_name):
        # HACK: ensures 'search' appears in translations
        if field_name == 'search':
            return _('search')
        return _(field_name)  # assumes other fields exist in the translations
}}}

The suggestion here is to add an interface on the `Form` for the user to overwrite how the form field names are mapped to html (currently they are mapped to `field_name`). The implementation could be something on the lines of:

1. maps `field_name` to its translation when the form is converted to HTML.
2. maps translation back to `field_name` when the form receives data.

The flow could be: `SearchForm()` expects `{'busca': ...}`, and `cleaned_data` returns `{'search': ...}`.

By default this mapping is the identity (1. field_name -> field_name; 2. field_name -> field_name), that recovers the existing situation and is thus backward compatible."	New feature	closed	Forms	1.7	Normal	wontfix			Unreviewed	0	0	0	0	0	0
