def available_labels(self): # possible labels, marking active ones labels = [[], []] for label in self.jar.list(): if label['by_user']: label['active'] = (label['label_id'] in self.storage and self.user_id() in self.storage[label['label_id']]) labels[0].append(label) else: label['active'] = (label.get('label_id') in self.storage) labels[1].append(label) labels[0].sort(key=lambda cls: make_sortable(cls['title'])) labels[1].sort(key=lambda cls: make_sortable(cls['title'])) return labels
def active_labels(self): labels = [] for label_id in self.storage: try: labels.append(self.jar.get(label_id)) except KeyError: pass return sorted(labels, key=lambda cls: make_sortable(cls['title']))
def active_labels(self): # selected labels labels = [] for label_id in self.storage: try: label = self.jar.get(label_id) if label['by_user']: if self.user_id() in self.storage[label_id]: labels.append(label) else: labels.append(label) except KeyError: pass return sorted(labels, key=lambda cls: make_sortable(cls['title']))
def list(self): labels = map(dict, self.storage.values()) return sorted(labels, key=lambda cls: make_sortable(cls['title']))