def consulta_municipios_na_regiao(request):
    """ Return the render from page with query by municipalities in region.
    @param request context request from view
    @return HTML page with query by municipalities in region.
    """

    try:
        # Id from UF requested
        uf_id = request.GET["uf_id"]
    except MultiValueDictKeyError:
        # logger.error(str(e))
        erro = "Preencha corretamente o formulário!"
        return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request))

    try:
        valida_caracteres(uf_id)
    except ParametroInseguroClienteError:
        # logger.error(str(e))
        erro = "Preencha corretamente o formulário!"
        return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request))

    try:
        # object DAO from municipalities
        municipalities_dao = MunicipioDAO()
        # list of municipalities
        municipalities_list = municipalities_dao.lista_municipios(uf_id)
    except (MySQLdb.Error, ResultadoConsultaNuloError):
        # logger.error(str(e))
        erro = "Ocorreu um erro no sistema, tente novamente mais tarde!"
        return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request))

    return render_to_response(
        "municipio.html", {"municipio_list": municipalities_list}, context_instance=RequestContext(request)
    )
 def test_valida_caracteres(self):
     with self.assertRaises(ParametroInseguroClienteError):
         self.assertIsNone(validacao_util.valida_caracteres(None))
     with self.assertRaises(ParametroInseguroClienteError):
         self.assertFalse(validacao_util.valida_caracteres("./$%^&"))