def acidentes_uf(request):
    """ Return the render with the accidents by states. """

    try:
        date = datetime.now()
        uf_dao = UFAcidentesDAO()
        uf_accidents_general = uf_dao.acidentes_uf_geral()
        uf_accidents_year = uf_dao.acidentes_uf_ano()

    except (MySQLdb.Error, ResultadoConsultaNuloError):
        # logger.error(str(e))
        erro = "Ocorreu um erro no sistema, tente novamente mais tarde!"
        response = render_to_response(
            "index.html", {
                'erro': erro
            }, context_instance=RequestContext(request)
        )

        return response

    response = render_to_response(
        "uf_acidentes.html", {
            'ano': range(_FIRST_YEAR, date.year + 1),
            'uf_acidentes_ano': uf_accidents_year,
            'uf_acidentes_geral': uf_accidents_general[:10],
            'uf_acidentes_geral_mapa': uf_accidents_general
        }, context_instance=RequestContext(request)
    )

    return response
class Test_UF_Acidentes(DAO_Tests):

    """docstring for TestUFAcidentes
    Class that tests the methods from uf_acidentes_dao
    """

    def test_uf_acidentes(self):
        """
        Test that verifies if the statistics are correctly instantiated, not
        leaving NULL
        """

        self.estatistica = UFAcidentesDAO()
        self.assertIsNotNone(self.estatistica)

    def test_acidentes_uf_geral(self):
        """
        Test if the statistics in accidents in all UFs are correctly
        instantiated, not returnning NULL
        """

        self.estatistica = UFAcidentesDAO()
        self.assertIsNotNone(self.estatistica.acidentes_uf_geral())

    def test_acidentes_uf_ano(self):
        """
        Test the number of accidents per year.

        @brief Local variables
            uf_acidentes_ano_list -
                List of number of accidents per year.

            anos -
                List of years.

            ufs -
                A Selected UF to check the number of accidents.
        """

        self.estatistica = UFAcidentesDAO()
        uf_acidentes_ano_list = self.estatistica.acidentes_uf_ano()

        anos = uf_acidentes_ano_list[0].ano_list
        self.assertEquals([
            2007,
            2008,
            2009,
            2010,
            2011,
            2012,
            2013
        ], anos)

        ufs = [i.uf for i in uf_acidentes_ano_list]
        self.assertIn('Pernambuco', ufs)