def state_label_css(subm):
    green_label = "badge label label-success"
    red_label = "badge label label-important"
    grey_label = "badge label label-info"
    # We expect a submission as input
    if subm.is_closed() and subm.grading:
        if subm.grading.means_passed:
            return green_label
        else:
            return red_label
    if subm.state in [subm.SUBMITTED_TESTED,
                      subm.SUBMITTED,
                      subm.TEST_FULL_PENDING,
                      subm.GRADED,
                      subm.TEST_FULL_FAILED]:
        return green_label
    if subm.state == subm.TEST_VALIDITY_FAILED:
        return red_label
    return grey_label