|
4 | 4 | def get_home_links(tree, product, category_sector_resource):
|
5 | 5 | links = []
|
6 | 6 |
|
7 |
| - for simulation_round, simulation_round_tree in tree.tree_dict.items(): |
8 |
| - category_sector_resource_tree = simulation_round_tree.get('items', {}).get(product, {}).get('items', {}) |
9 |
| - if isinstance(category_sector_resource, str): |
10 |
| - # this is a category or a sector |
11 |
| - if category_sector_resource_tree.get(category_sector_resource): |
12 |
| - links.append( |
13 |
| - ( |
14 |
| - simulation_round, |
15 |
| - reverse('search', args=[ |
16 |
| - f'tree/{simulation_round}/{product}/{category_sector_resource}' |
17 |
| - ]) |
| 7 | + if tree: |
| 8 | + for simulation_round, simulation_round_tree in tree.tree_dict.items(): |
| 9 | + category_sector_resource_tree = simulation_round_tree.get('items', {}).get(product, {}).get('items', {}) |
| 10 | + if isinstance(category_sector_resource, str): |
| 11 | + # this is a category or a sector |
| 12 | + if category_sector_resource_tree.get(category_sector_resource): |
| 13 | + links.append( |
| 14 | + ( |
| 15 | + simulation_round, |
| 16 | + reverse('search', args=[ |
| 17 | + f'tree/{simulation_round}/{product}/{category_sector_resource}' |
| 18 | + ]) |
| 19 | + ) |
18 | 20 | )
|
19 |
| - ) |
20 |
| - else: |
21 |
| - # this is a resource |
22 |
| - for resource_path in category_sector_resource.paths: |
23 |
| - resource_simulation_round, resource_product, resource_publication = resource_path.split('/') |
24 |
| - if resource_simulation_round == simulation_round and resource_product == product: |
25 |
| - tree_publication = category_sector_resource_tree.get(resource_publication) or \ |
26 |
| - category_sector_resource_tree.get(resource_publication.lower()) |
27 |
| - if tree_publication: |
28 |
| - publication = tree_publication.get('specifier') |
29 |
| - links.append( |
30 |
| - ( |
31 |
| - simulation_round, |
32 |
| - reverse('search', args=[ |
33 |
| - f'tree/{simulation_round}/{product}/{publication}' |
34 |
| - ]) |
| 21 | + else: |
| 22 | + # this is a resource |
| 23 | + for resource_path in category_sector_resource.paths: |
| 24 | + resource_simulation_round, resource_product, resource_publication = resource_path.split('/') |
| 25 | + if resource_simulation_round == simulation_round and resource_product == product: |
| 26 | + tree_publication = category_sector_resource_tree.get(resource_publication) or \ |
| 27 | + category_sector_resource_tree.get(resource_publication.lower()) |
| 28 | + if tree_publication: |
| 29 | + publication = tree_publication.get('specifier') |
| 30 | + links.append( |
| 31 | + ( |
| 32 | + simulation_round, |
| 33 | + reverse('search', args=[ |
| 34 | + f'tree/{simulation_round}/{product}/{publication}' |
| 35 | + ]) |
| 36 | + ) |
35 | 37 | )
|
36 |
| - ) |
37 | 38 |
|
38 | 39 | return links
|
0 commit comments