Commit 1b42d0823a9424843dfc105ca902e7180c390682
1 parent
0011bed0
Exists in
master
and in
4 other branches
New category_label method
Showing
2 changed files
with
39 additions
and
0 deletions
Show diff stats
app/db_mgr.py
@@ -8,6 +8,39 @@ from app.models import db, Period, Project, Category | @@ -8,6 +8,39 @@ from app.models import db, Period, Project, Category | ||
8 | charge_unit = 100 | 8 | charge_unit = 100 |
9 | 9 | ||
10 | 10 | ||
11 | +def category_labels(): | ||
12 | + """ | ||
13 | + Build a list of dicts of the categorized labels for form display: | ||
14 | + | ||
15 | + [{'name': 'Domaine', | ||
16 | + 'labels': [{'id': 1, 'name': 'R&T'}, | ||
17 | + {'id': 3, 'name': 'Autres 2'}, | ||
18 | + . | ||
19 | + . | ||
20 | + . | ||
21 | + {'id': 11, 'name': 'Instrumentation Sol'}], | ||
22 | + }, | ||
23 | + {'name': 'Pôle', | ||
24 | + 'labels': [{'id': 12, 'name': 'Astronomie'}, | ||
25 | + {'id': 14, 'name': 'Solaire'}, | ||
26 | + . | ||
27 | + . | ||
28 | + . | ||
29 | + {'id': 21, 'name': 'Administration'}] | ||
30 | + }] | ||
31 | + | ||
32 | + | ||
33 | + :return: | ||
34 | + """ | ||
35 | + _categories = [] | ||
36 | + for _c in Category.query.all(): | ||
37 | + _category = {'name': _c.name, 'labels': []} | ||
38 | + for _l in _c.labels: | ||
39 | + _category['labels'].append({'id': _l.label.id, 'name': _l.label.name}) | ||
40 | + _categories.append(_category) | ||
41 | + return _categories | ||
42 | + | ||
43 | + | ||
11 | def projects(): | 44 | def projects(): |
12 | """ | 45 | """ |
13 | Build the list of all projects, with their charges for the current period | 46 | Build the list of all projects, with their charges for the current period |
tests/backend_tests.py
@@ -74,3 +74,9 @@ class DbMgrTestCase(BaseTestCase): | @@ -74,3 +74,9 @@ class DbMgrTestCase(BaseTestCase): | ||
74 | stacked_charges = db_mgr.charges_by_project_stacked(60) | 74 | stacked_charges = db_mgr.charges_by_project_stacked(60) |
75 | # Waiting for 17 periods + headers line | 75 | # Waiting for 17 periods + headers line |
76 | self.assertEqual(18, len(stacked_charges)) | 76 | self.assertEqual(18, len(stacked_charges)) |
77 | + | ||
78 | + def test_category_labels(self): | ||
79 | + category_labels = db_mgr.category_labels() | ||
80 | + categories = [_cl['name'] for _cl in category_labels] | ||
81 | + self.assertEqual(['Domaine', 'Pôle'], categories) | ||
82 | + |