Commit fed90dbd6d32b3ebc074d08d4d2301000776008c

Authored by hitier
1 parent 9b43874a

Rewrite list intersection

Showing 1 changed file with 10 additions and 4 deletions   Show diff stats
@@ -43,13 +43,19 @@ def projects(): @@ -43,13 +43,19 @@ def projects():
43 # Build the table row by row 43 # Build the table row by row
44 for _pc in projects_charges: 44 for _pc in projects_charges:
45 p_id = _pc[0] 45 p_id = _pc[0]
46 - p = Project.query.get(int(p_id)) 46 + project = Project.query.get(int(p_id))
47 # adding 2 first columns: id, name 47 # adding 2 first columns: id, name
48 - project_row = [p.id, p.name] 48 + project_row = [project.id, project.name]
49 # then labels, many for each category 49 # then labels, many for each category
50 for category in categories: 50 for category in categories:
51 - # we build the labels.name list of the intersection of that category labels with projects labels  
52 - labels = [_cl.label.name for _cl in category.labels if _cl.label in [_pl.label for _pl in p.labels]] 51 + # we build the labels.name list of the intersection of current category's labels with project's labels
  52 + # Comprehensive shortcut is:
  53 + # labels = [_cl.label.name for _cl in category.labels if _cl.label in [_pl.label for _pl in project.labels]]
  54 + #
  55 + category_labels = [_cl.label for _cl in category.labels]
  56 + project_labels = [_pl.label for _pl in project.labels]
  57 + intersection_labels = list(set.intersection(set(project_labels), set(category_labels)))
  58 + labels = [label.name for label in intersection_labels]
53 project_row.append(labels) 59 project_row.append(labels)
54 # then add total charge 60 # then add total charge
55 project_row.append(_pc[1]) 61 project_row.append(_pc[1])