def render(self, context): """ Gets the tagged projects and return a list of them. """ try: # Allow lists as tags as well current_tags = [] for t in self.tags: tag = t.resolve(context) if not tag: continue elif type(tag) == list: for subtag in tag: current_tags.append(subtag) else: current_tags.append(tag) # Filter objects that have *all* the tags assigned projects = Project.objects.filter( tags__name__in=current_tags).annotate( repeat_count=Count("id")).filter( repeat_count=len(current_tags)) # Sort projects if requested. Default to true if # variable not given or not found. if self.sort == None: sort = True else: sort = self.sort.resolve(context) sort = bool(sort) if sort: projects = natural_sort(projects, "title") context[self.var_name] = projects except template.VariableDoesNotExist: pass return u""
def render( self, context ): """ Gets the tagged projects and return a list of them. """ try: # Allow lists as tags as well current_tags = [] for t in self.tags: tag = t.resolve( context ) if not tag: continue elif type(tag) == list: for subtag in tag: current_tags.append( subtag ) else: current_tags.append( tag ) # Filter objects that have *all* the tags assigned projects = Project.objects.filter( tags__name__in=current_tags ).annotate( repeat_count=Count("id") ).filter( repeat_count=len(current_tags) ) # Sort projects if requested. Default to true if # variable not given or not found. if self.sort == None: sort = True else: sort = self.sort.resolve( context ) sort = bool( sort ) if sort: projects = natural_sort( projects, "title" ) context[ self.var_name ] = projects except template.VariableDoesNotExist: pass return u""
def pids_to_projects(pids, project_index, sort=False): """ Returns a list of project objects that correspond to the PID list passed as parameter. If sort is specified, the returning list is sorted by title. """ projects = [project_index[pid] for pid in pids] if sort: return natural_sort(projects, "title") else: return projects
def main(): node = load_root_node() while True: options = [] will_download = True for n in node.get_children(): options.append((n.title, n)) if not n.can_download: will_download = False options = natural_sort(options, key=lambda x: x[0]) result = choose(options, allow_multi=will_download) if result is None: if node.parent is not None: node = node.parent else: break elif will_download: for n in result: if not n.download(): raw_input("Press return to continue...\n") else: node = result