def index(self, format='html'): for item in self.extensions: item.index(c, request, response, c.results) if format == 'json': return to_jsonp(map(lambda d: d.as_dict(), c.datasets)) elif format == 'csv': results = map(lambda d: d.as_dict(), c.datasets) return write_csv(results, response) else: c.query = request.params.items() c.add_filter = lambda f, v: '?' + urlencode(c.query + [(f, v)] if ( f, v) not in c.query else c.query) c.del_filter = lambda f, v: '?' + urlencode([(k, x) for k, x in c.query if (k, x) != (f, v)]) c.results = c.datasets for language in request.params.getall('languages'): l = db.aliased(DatasetLanguage) c.results = c.results.join(l, Dataset._languages) c.results = c.results.filter(l.code == language) for territory in request.params.getall('territories'): t = db.aliased(DatasetTerritory) c.results = c.results.join(t, Dataset._territories) c.results = c.results.filter(t.code == territory) c.results = list(c.results) c.territory_options = DatasetTerritory.dataset_counts(c.results) c.language_options = DatasetLanguage.dataset_counts(c.results) return render('dataset/index.html')
def index(self, format='html'): for item in self.extensions: item.index(c, request, response, c.results) if format == 'json': return to_jsonp(map(lambda d: d.as_dict(), c.datasets)) elif format == 'csv': results = map(lambda d: d.as_dict(), c.datasets) return write_csv(results, response) else: c.query = request.params.items() c.add_filter = lambda f, v: '?' + urlencode(c.query + [(f, v)] if (f, v) not in c.query else c.query) c.del_filter = lambda f, v: '?' + urlencode([(k,x) for k, x in c.query if (k,x) != (f,v)]) c.results = c.datasets for language in request.params.getall('languages'): l = db.aliased(DatasetLanguage) c.results = c.results.join(l, Dataset._languages) c.results = c.results.filter(l.code==language) for territory in request.params.getall('territories'): t = db.aliased(DatasetTerritory) c.results = c.results.join(t, Dataset._territories) c.results = c.results.filter(t.code==territory) c.results = list(c.results) c.territory_options = DatasetTerritory.dataset_counts(c.results) c.language_options = DatasetLanguage.dataset_counts(c.results) return render('dataset/index.html')
def language_index(datasets): """ Get a list of languages by count of datasets """ # Get a list of languages in the current list of datasets languages = DatasetLanguage.dataset_counts(datasets) # Return a list of languages as dicts with code, count, url and label return [{'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', languages=code), 'label': LANGUAGES.get(code, code)} for (code, count) in languages]
def language_index(datasets): """ Get a list of languages by count of datasets """ # Get a list of languages in the current list of datasets languages = DatasetLanguage.dataset_counts(datasets) # Return a list of languages as dicts with code, count, url and label return [{ 'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', languages=code), 'label': LANGUAGES.get(code, code) } for (code, count) in languages]
def index(self, format='html'): c.query = request.params.items() c.add_filter = lambda f, v: '?' + urlencode(c.query + [(f, v)] if (f, v) not in c.query else c.query) c.del_filter = lambda f, v: '?' + urlencode([(k, x) for k, x in c.query if (k, x) != (f, v)]) c.results = c.datasets for language in request.params.getall('languages'): l = db.aliased(DatasetLanguage) c.results = c.results.join(l, Dataset._languages) c.results = c.results.filter(l.code == language) for territory in request.params.getall('territories'): t = db.aliased(DatasetTerritory) c.results = c.results.join(t, Dataset._territories) c.results = c.results.filter(t.code == territory) c.results = list(c.results) c.territory_options = [{'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', territories=code), 'label': COUNTRIES.get(code, code)} \ for (code, count) in DatasetTerritory.dataset_counts(c.results)] c.language_options = [{'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', languages=code), 'label': LANGUAGES.get(code, code)} \ for (code, count) in DatasetLanguage.dataset_counts(c.results)] if format == 'json': results = map(lambda d: d.as_dict(), c.results) results = [dataset_apply_links(r) for r in results] return to_jsonp({ 'datasets': results, 'territories': c.territory_options, 'languages': c.language_options }) elif format == 'csv': results = map(lambda d: d.as_dict(), c.results) return write_csv(results, response) return render('dataset/index.html')
def index(self, format='html'): c.query = request.params.items() c.add_filter = lambda f, v: '?' + urlencode(c.query + [(f, v)] if ( f, v) not in c.query else c.query) c.del_filter = lambda f, v: '?' + urlencode([(k, x) for k, x in c.query if (k, x) != (f, v)]) c.results = c.datasets for language in request.params.getall('languages'): l = db.aliased(DatasetLanguage) c.results = c.results.join(l, Dataset._languages) c.results = c.results.filter(l.code == language) for territory in request.params.getall('territories'): t = db.aliased(DatasetTerritory) c.results = c.results.join(t, Dataset._territories) c.results = c.results.filter(t.code == territory) category = request.params.get('category') if category: c.results = c.results.filter(Dataset.category == category) c.results = list(c.results) c.territory_options = [{'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', territories=code), 'label': COUNTRIES.get(code, code)} \ for (code, count) in DatasetTerritory.dataset_counts(c.results)] c.language_options = [{'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', languages=code), 'label': LANGUAGES.get(code, code)} \ for (code, count) in DatasetLanguage.dataset_counts(c.results)] # TODO: figure out where to put this: ds_ids = [d.id for d in c.results] if len(ds_ids): q = db.select( [Dataset.category, db.func.count(Dataset.id)], Dataset.id.in_(ds_ids), group_by=Dataset.category, order_by=db.func.count(Dataset.id).desc()) c.category_options = [{'category': category, 'count': count, 'url': h.url_for(controller='dataset', action='index', category=category), 'label': CATEGORIES.get(category, category)} \ for (category, count) in db.session.bind.execute(q).fetchall() \ if category is not None] else: c.category_options = [] c._must_revalidate = True if len(c.results): dt = max([r.updated_at for r in c.results]) etag_cache_keygen(dt) if format == 'json': results = map(lambda d: d.as_dict(), c.results) results = [dataset_apply_links(r) for r in results] return to_jsonp({ 'datasets': results, 'categories': c.category_options, 'territories': c.territory_options, 'languages': c.language_options }) elif format == 'csv': results = map(lambda d: d.as_dict(), c.results) return write_csv(results, response) c.show_rss = True return templating.render('dataset/index.html')
def index(self, format='html'): c.query = request.params.items() c.add_filter = lambda f, v: '?' + urlencode(c.query + [(f, v)] if (f, v) not in c.query else c.query) c.del_filter = lambda f, v: '?' + urlencode([(k, x) for k, x in c.query if (k, x) != (f, v)]) c.results = c.datasets for language in request.params.getall('languages'): l = db.aliased(DatasetLanguage) c.results = c.results.join(l, Dataset._languages) c.results = c.results.filter(l.code == language) for territory in request.params.getall('territories'): t = db.aliased(DatasetTerritory) c.results = c.results.join(t, Dataset._territories) c.results = c.results.filter(t.code == territory) category = request.params.get('category') if category: c.results = c.results.filter(Dataset.category == category) c.results = list(c.results) c.territory_options = [{'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', territories=code), 'label': COUNTRIES.get(code, code)} \ for (code, count) in DatasetTerritory.dataset_counts(c.results)] c.language_options = [{'code': code, 'count': count, 'url': h.url_for(controller='dataset', action='index', languages=code), 'label': LANGUAGES.get(code, code)} \ for (code, count) in DatasetLanguage.dataset_counts(c.results)] # TODO: figure out where to put this: ds_ids = [d.id for d in c.results] if len(ds_ids): q = db.select([Dataset.category, db.func.count(Dataset.id)], Dataset.id.in_(ds_ids), group_by=Dataset.category, order_by=db.func.count(Dataset.id).desc()) c.category_options = [{'category': category, 'count': count, 'url': h.url_for(controller='dataset', action='index', category=category), 'label': CATEGORIES.get(category, category)} \ for (category, count) in db.session.bind.execute(q).fetchall() \ if category is not None] else: c.category_options = [] c._must_revalidate = True if len(c.results): dt = max([r.updated_at for r in c.results]) etag_cache_keygen(dt) if format == 'json': results = map(lambda d: d.as_dict(), c.results) results = [dataset_apply_links(r) for r in results] return to_jsonp({ 'datasets': results, 'categories': c.category_options, 'territories': c.territory_options, 'languages': c.language_options }) elif format == 'csv': results = map(lambda d: d.as_dict(), c.results) return write_csv(results, response) c.show_rss = True return templating.render('dataset/index.html')
def index(self, format="html"): c.query = request.params.items() c.add_filter = lambda f, v: "?" + urlencode(c.query + [(f, v)] if (f, v) not in c.query else c.query) c.del_filter = lambda f, v: "?" + urlencode([(k, x) for k, x in c.query if (k, x) != (f, v)]) c.results = c.datasets for language in request.params.getall("languages"): l = db.aliased(DatasetLanguage) c.results = c.results.join(l, Dataset._languages) c.results = c.results.filter(l.code == language) for territory in request.params.getall("territories"): t = db.aliased(DatasetTerritory) c.results = c.results.join(t, Dataset._territories) c.results = c.results.filter(t.code == territory) category = request.params.get("category") if category: c.results = c.results.filter(Dataset.category == category) c.results = list(c.results) c.territory_options = [ { "code": code, "count": count, "url": h.url_for(controller="dataset", action="index", territories=code), "label": COUNTRIES.get(code, code), } for (code, count) in DatasetTerritory.dataset_counts(c.results) ] c.language_options = [ { "code": code, "count": count, "url": h.url_for(controller="dataset", action="index", languages=code), "label": LANGUAGES.get(code, code), } for (code, count) in DatasetLanguage.dataset_counts(c.results) ] # TODO: figure out where to put this: ds_ids = [d.id for d in c.results] if len(ds_ids): q = db.select( [Dataset.category, db.func.count(Dataset.id)], Dataset.id.in_(ds_ids), group_by=Dataset.category, order_by=db.func.count(Dataset.id).desc(), ) c.category_options = [ { "category": category, "count": count, "url": h.url_for(controller="dataset", action="index", category=category), "label": CATEGORIES.get(category, category), } for (category, count) in db.session.bind.execute(q).fetchall() if category is not None ] else: c.category_options = [] c._must_revalidate = True if len(c.results): dt = max([r.updated_at for r in c.results]) etag_cache_keygen(dt) if format == "json": results = map(lambda d: d.as_dict(), c.results) results = [dataset_apply_links(r) for r in results] return to_jsonp( { "datasets": results, "categories": c.category_options, "territories": c.territory_options, "languages": c.language_options, } ) elif format == "csv": results = map(lambda d: d.as_dict(), c.results) return write_csv(results, response) return render("dataset/index.html")