def _get_project_categories(self, project): """ Create list of categories. License, Language and Development status are shown separately and are therefore taken out from the category listing. """ # Get api cs = CQDECategoryStore() # Get categories and specialcase contexts categories = cs.get_all_project_categories(project.id) contexts = cs.get_contexts() combined_categories = [] separated_categories_per_context = {} categories_by_any_context_id = {} context_by_id = {} # Setup the contexts dicts for context in contexts: context_by_id[context.context_id] = context if context.summary_name: # If context has summary name, it is shown as separated in the summary page new_list = [] categories_by_any_context_id[context.context_id] = new_list separated_categories_per_context[context.context_id] = new_list else: categories_by_any_context_id[context.context_id] = combined_categories sort_opts = {'key':lambda c:c.name, 'cmp':lambda x,y: cmp(x.lower(), y.lower())} # Now, categories_by_any_context_id has key for each context id for category in categories: categories_by_any_context_id[category.context].append(category) for context_id in separated_categories_per_context: separated_categories_per_context[context_id].sort(**sort_opts) combined_categories.sort(**sort_opts) # Sort alphabetically, case-insensitively context_order = [c.context_id for c in sorted(map(lambda id:context_by_id[id], separated_categories_per_context.keys()), key=lambda c:c.summary_name)] languages = [] for context_id in separated_categories_per_context: context = context_by_id[context_id] if (context.summary_name and context.summary_name.lower() in ('language','natural language')): # Here, we expect that the description contains the language tag. # http://www.w3schools.com/tags/att_meta_http_equiv.asp # http://www.w3.org/TR/2011/WD-html-markup-20110113/meta.http-equiv.content-language.html languages = [c.description for c in separated_categories_per_context[context_id]] return (combined_categories, separated_categories_per_context, context_by_id, context_order, languages)
def get_project_categories(self, projects): """ Returns a map of project categories project_id => category string """ cs = CQDECategoryStore() project_categories = {} for project in projects: cats = cs.get_all_project_categories(project.id, ordered=True) cats_joined = ', '.join([cat.name.split("#")[0] for cat in cats]) project_categories[project.id] = cats_joined return project_categories
def get_project_categories(self, projects): """ Returns a map of project categories project_id => category string """ cs = CQDECategoryStore() project_categories = {} for project in projects: cats = cs.get_all_project_categories(project.id, ordered=True) cats_joined = ', '.join([cat.name.split("#")[0] for cat in cats]) project_categories[project.id] = cats_joined return project_categories
def _get_project_categories(self, project): """ Create list of categories. License, Language and Development status are shown separately and are therefore taken out from the category listing. """ # Get api cs = CQDECategoryStore() # Get categories and specialcase contexts categories = cs.get_all_project_categories(project.id) contexts = cs.get_contexts() combined_categories = [] separated_categories_per_context = {} categories_by_any_context_id = {} context_by_id = {} # Setup the contexts dicts for context in contexts: context_by_id[context.context_id] = context if context.summary_name: # If context has summary name, it is shown as separated in the summary page new_list = [] categories_by_any_context_id[context.context_id] = new_list separated_categories_per_context[context.context_id] = new_list else: categories_by_any_context_id[ context.context_id] = combined_categories sort_opts = { 'key': lambda c: c.name, 'cmp': lambda x, y: cmp(x.lower(), y.lower()) } # Now, categories_by_any_context_id has key for each context id for category in categories: categories_by_any_context_id[category.context].append(category) for context_id in separated_categories_per_context: separated_categories_per_context[context_id].sort(**sort_opts) combined_categories.sort(**sort_opts) # Sort alphabetically, case-insensitively context_order = [ c.context_id for c in sorted(map(lambda id: context_by_id[id], separated_categories_per_context.keys()), key=lambda c: c.summary_name) ] languages = [] for context_id in separated_categories_per_context: context = context_by_id[context_id] if (context.summary_name and context.summary_name.lower() in ('language', 'natural language')): # Here, we expect that the description contains the language tag. # http://www.w3schools.com/tags/att_meta_http_equiv.asp # http://www.w3.org/TR/2011/WD-html-markup-20110113/meta.http-equiv.content-language.html languages = [ c.description for c in separated_categories_per_context[context_id] ] return (combined_categories, separated_categories_per_context, context_by_id, context_order, languages)