def add_unit(unit,**kwargs):
    """
        Add the unit defined into the object "unit" to the DB
        If unit["project_id"] is None it means that the unit is global, otherwise is property of a project
        If the unit exists emits an exception


        A minimal example:

        .. code-block:: python

            new_unit = dict(

                name      = 'Teaspoons per second',
                abbreviation = 'tsp s^-1',
                cf        = 0,               # Constant conversion factor
                lf        = 1.47867648e-05,  # Linear conversion factor
                dimension_id = 2,
                description  = 'A flow of one teaspoon per second.',
            )
            add_unit(new_unit)


    """

    new_unit = Unit()
    new_unit.dimension_id   = unit["dimension_id"]
    new_unit.name           = unit['name']

    # Needed to uniform abbr to abbreviation
    new_unit.abbreviation = unit['abbreviation']

    # Needed to uniform into to description
    new_unit.description = unit['description']

    new_unit.lf             = unit['lf']
    new_unit.cf             = unit['cf']

    if ('project_id' in unit) and (unit['project_id'] is not None):
        # Adding dimension to the "user" dimensions list
        new_unit.project_id = unit['project_id']

    # Save on DB
    db.DBSession.add(new_unit)
    db.DBSession.flush()

    return JSONObject(new_unit)