diff --git a/app/db_mgr.py b/app/db_mgr.py index bd1fa95..a8c7473 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -8,6 +8,39 @@ from app.models import db, Period, Project, Category charge_unit = 100 +def category_labels(): + """ + Build a list of dicts of the categorized labels for form display: + + [{'name': 'Domaine', + 'labels': [{'id': 1, 'name': 'R&T'}, + {'id': 3, 'name': 'Autres 2'}, + . + . + . + {'id': 11, 'name': 'Instrumentation Sol'}], + }, + {'name': 'Pôle', + 'labels': [{'id': 12, 'name': 'Astronomie'}, + {'id': 14, 'name': 'Solaire'}, + . + . + . + {'id': 21, 'name': 'Administration'}] + }] + + + :return: + """ + _categories = [] + for _c in Category.query.all(): + _category = {'name': _c.name, 'labels': []} + for _l in _c.labels: + _category['labels'].append({'id': _l.label.id, 'name': _l.label.name}) + _categories.append(_category) + return _categories + + def projects(): """ Build the list of all projects, with their charges for the current period diff --git a/tests/backend_tests.py b/tests/backend_tests.py index e4dacb6..e8b8b95 100644 --- a/tests/backend_tests.py +++ b/tests/backend_tests.py @@ -74,3 +74,9 @@ class DbMgrTestCase(BaseTestCase): stacked_charges = db_mgr.charges_by_project_stacked(60) # Waiting for 17 periods + headers line self.assertEqual(18, len(stacked_charges)) + + def test_category_labels(self): + category_labels = db_mgr.category_labels() + categories = [_cl['name'] for _cl in category_labels] + self.assertEqual(['Domaine', 'Pôle'], categories) + -- libgit2 0.21.2