def person_checklist(people): """ Three-column checklist of people. Can handle any database model with a 'name' field or property. """ people = sort_by_lastname(people) col1, col2, col3 = split(people, 3) return {"col1": col1, "col2": col2, "col3": col3}
def person_checklist(people, phone_numbers=False): """ A checklist of people. Each person is a database model with a `name` field or property. If including phone numbers, each person must also have a `get_phone_number` method. """ people = sort_by_lastname(people) if phone_numbers: n_cols = 2 template_name = 'utils/checklists/people_and_phones.html' else: n_cols = 3 template_name = 'utils/checklists/people.html' return loader.get_template(template_name).render( {'columns': split(people, n_cols)})
def test_sort_by_lastname(self): inc1 = mommy.make(IncomingStudent, name='Rachel Zhao') inc2 = mommy.make(IncomingStudent, name='Lara P. Balick') inc3 = mommy.make(IncomingStudent, name='William A. P. Wolfe-McGuire') self.assertEqual([inc2, inc3, inc1], sort_by_lastname([inc1, inc2, inc3]))