def browse_page(): page_size = 45 params = get_artwork_params() if not params: return browse_index() flat = '_'.join(f'{pid}={qid}' for pid, qid in params) item_labels = get_labels_db(qid for pid, qid in params) g.title = ' / '.join(find_more_props[pid] + ': ' + (item_labels.get(qid) or qid) for pid, qid in params) q_items = get_db_items(params) facets = get_db_facets(params) all_items = q_items.all() page = utils.get_int_arg('page') or 1 total = q_items.count() pager = Pagination(page, page_size, total) items = [item for item in pager.slice(all_items) if item.image_filename()] cache_name = f'{flat}_{page}_{page_size}' detail = get_image_detail_with_cache(items, cache_name) cache_refreshed = False linked_qids = {qid for pid, qid in params} for item in items: artist_qid = item.artist if artist_qid: linked_qids.add(artist_qid) for prop in 'P31', 'P180': linked_qids.update(item.linked_qids(prop)) linked_labels = get_labels_db(linked_qids) for item in items: image_filename = item.image_filename() if not cache_refreshed and image_filename not in detail: detail = get_image_detail_with_cache(items, cache_name, refresh=True) cache_refreshed = True item.image = detail[image_filename] return render_template('find_more.html', page=page, label=g.title, pager=pager, prop_labels=find_more_props, labels=find_more_props, linked_labels=linked_labels, items=items, total=total, params=params, facets=facets) return jsonify(params=params, items=items.count(), facets=facets)
def list_edits(): q = Edit.query.order_by(Edit.timestamp.desc()) page = utils.get_int_arg('page') or 1 pager = Pagination(page, 100, q.count()) item_count = (database.session.query(func.count(distinct( Edit.artwork_id))).scalar()) user_count = (database.session.query(func.count(distinct( Edit.username))).scalar()) return render_template('list_edits.html', pager=pager, edit_list=pager.slice(q), item_count=item_count, user_count=user_count)
def property_query_page(property_id): pid = f'P{property_id}' g.title = find_more_props[pid] sort = request.args.get('sort') sort_by_name = sort and sort.lower().strip() == 'name' q = (database.session.query( Triple.object_id, func.count(func.distinct(Triple.subject_id)).label('c')).filter_by( predicate_id=property_id).join( Item, Item.item_id == Triple.subject_id).filter_by( is_artwork=True).group_by(Triple.object_id).order_by( desc('c'))) page = utils.get_int_arg('page') or 1 total = q.count() page_size = 100 pager = Pagination(page, page_size, total) page_hits = pager.slice(q) labels = get_labels_db({f'Q{object_id}' for object_id, c in page_hits}) hits = [] for object_id, count in page_hits: qid = f'Q{object_id}' hits.append({ 'qid': qid, 'label': labels.get(qid) or '[item missing]', 'count': count }) return render_template('property.html', label=g.title, order=('name' if sort_by_name else 'count'), pid=pid, page=page, pager=pager, hits=hits)
def browse_page(): params = get_artwork_params() if not params: return browse_index() flat = '_'.join(f'{pid}={qid}' for pid, qid in params) item_labels = get_labels(qid for pid, qid in params) g.title = ' / '.join(find_more_props[pid] + ': ' + item_labels[qid] for pid, qid in params) bindings = filter_artwork(params) try: facets = get_facets(params) except wdqs.QueryError: facets = {} page_size = 45 item_map = wdqs.build_browse_item_map(bindings) all_items = [] for item in item_map.values(): if len(item['image_filename']) != 1: continue item['image_filename'] = item['image_filename'][0] all_items.append(item) page = utils.get_int_arg('page') or 1 pager = Pagination(page, page_size, len(all_items)) items = pager.slice(all_items) cache_name = f'{flat}_{page}_{page_size}' detail = get_image_detail_with_cache(items, cache_name) cache_refreshed = False for item in items: item['url'] = url_for('item_page', item_id=item['item_id']) image_filename = item['image_filename'] if not cache_refreshed and image_filename not in detail: detail = get_image_detail_with_cache(items, cache_name, refresh=True) cache_refreshed = True item['image'] = detail[image_filename] catalog_url = url_for('catalog_page', **dict(params)) return render_template('find_more.html', facets=facets, prop_labels=find_more_props, label=g.title, pager=pager, params=params, item_map=item_map, catalog_url=catalog_url, page=page, labels=find_more_props, bindings=bindings, total=len(item_map), items=items)