def category(label): ''' list of entries for a label :param label: the type of data to list out :return: rendered list page ''' label = helpers.sanitize(label) if not graph.validate_label(label): labels = graph.get_labels() return render_template(request.url, '404.html', labels=labels) filtered = None try: item1 = helpers.sanitize(request.values['i']) except KeyError: data = graph.get_all(label) else: try: item2 = helpers.sanitize(request.values['j']) operator = helpers.sanitize(request.values['op']) if operator not in ['and', 'not']: raise BadRequestKeyError except (KeyError, BadRequestKeyError): data = graph.get_filtered(label, item1) filtered = { 'item1': graph.get_node(item1)['nodes'][0], } else: data = graph.get_filtered(label, item1, item2, operator) filtered = { 'operator': operator, 'item1': graph.get_node(item1)['nodes'][0], 'item2': graph.get_node(item2)['nodes'][0] } items = data['nodes'] template = 'list.html' title = 'List of %s' % helpers.capitalize_filter(helpers.pluralize(label)) grimoires = [] if label in entities: template = 'entity-list.html' grimoires = graph.get_all('grimoire', with_connection_label=label)['nodes'] if len(grimoires) < 2: grimoires = None return render_template(request.url, template, items=items, title=title, label=label, grimoires=grimoires, filtered=filtered)
def category(label): ''' list of entries for a label :param label: the type of data to list out :return: rendered list page ''' label = helpers.sanitize(label) if not graph.validate_label(label): labels = graph.get_labels() return render_template(request.url, 'label-404.html', labels=labels) filtered = None try: item1 = helpers.sanitize(request.values['i']) except KeyError: data = graph.get_all(label) else: try: item2 = helpers.sanitize(request.values['j']) operator = helpers.sanitize(request.values['op']) if operator not in ['and', 'not']: raise BadRequestKeyError except (KeyError, BadRequestKeyError): data = graph.get_filtered(label, item1) filtered = { 'item1': graph.get_node(item1)['nodes'][0], } else: data = graph.get_filtered(label, item1, item2, operator) filtered = { 'operator': operator, 'item1': graph.get_node(item1)['nodes'][0], 'item2': graph.get_node(item2)['nodes'][0] } items = data['nodes'] template = 'list.html' title = 'List of %s' % helpers.capitalize_filter(helpers.pluralize(label)) grimoires = [] if label in entities: template = 'entity-list.html' grimoires = graph.get_all('grimoire', with_connection_label=label)['nodes'] if len(grimoires) < 2: grimoires = None return render_template(request.url, template, items=items, title=title, label=label, grimoires=grimoires, filtered=filtered)
def item(label, uid): ''' generic page for an item :param label: the desired neo4j label :param uid: the human-readable uid of the node :return: customized data for this label rendered item page template ''' # load and validate url data label = helpers.sanitize(label) if not graph.validate_label(label): logging.error('Invalid label %s', label) return render_template(request.url, 'label-404.html', labels=graph.get_labels()) try: data = helpers.get_node(uid) except NameError: items = graph.get_all(label) return render_template(request.url, 'item-404.html', items=items['nodes'], search=graph.search(uid)['nodes'], label=label) node = data['node'] rels = data['rels'] # ----- page header/metadata title = node['props']['identifier'] # ----- formatted data switch = { 'parent:book': grimoire_item, 'parent:entity': entity_item, 'art': art_item, 'language': language_item, 'edition': edition_item, 'publisher': publisher_item, 'editor': editor_item, 'default': generic_item, 'spell': spell_item, 'talisman': spell_item, 'parent:ingredient': ingredient_item, 'outcome': outcome_item } key = node['parent_label'] if node['parent_label'] in switch else \ (label if label in switch else 'default') item_data = switch[key](node, rels) item_data['rels'] = helpers.combine_rels(item_data['rels']) # ----- sidebar sidebar = [] related = graph.related(uid, label) if related['nodes']: sidebar = [{'title': 'Similar %s' % \ helpers.capitalize_filter(helpers.pluralize(label)), 'data': related['nodes']}] sidebar += get_others(data['rels'], node) if not item_data['content'] and not item_data['excerpts']: item_data['content'] = 'The %s "%s."' % \ (helpers.format_filter(label), helpers.unthe(title)) max_main_length = max([len(i['data']) for i in item_data['main']] + [0]) default_collapse = len(item_data['main']) > 2 or max_main_length > 30 return render_template(request.url, 'item.html', data=item_data, title=title, label=label, sidebar=sidebar, default_collapse=default_collapse)
def item(label, uid): ''' generic page for an item :param label: the desired neo4j label :param uid: the human-readable uid of the node :return: customized data for this label rendered item page template ''' # load and validate url data label = helpers.sanitize(label) if not graph.validate_label(label): logging.error('Invalid label %s', label) return render_template(request.url, '404.html', labels=graph.get_labels()) try: data = helpers.get_node(uid) except NameError: items = graph.get_all(label) return render_template(request.url, '404.html', items=items['nodes'], search=graph.search(uid)['nodes'], label=label) node = data['node'] rels = data['rels'] # ----- page header/metadata title = node['props']['identifier'] # ----- formatted data switch = { 'parent:book': grimoire_item, 'parent:entity': entity_item, 'art': art_item, 'language': language_item, 'edition': edition_item, 'publisher': publisher_item, 'editor': editor_item, 'default': generic_item, 'spell': spell_item, 'talisman': spell_item, 'parent:ingredient': ingredient_item, 'outcome': outcome_item } key = node['parent_label'] if node['parent_label'] in switch else \ (label if label in switch else 'default') item_data = switch[key](node, rels) item_data['rels'] = helpers.combine_rels(item_data['rels']) # ----- sidebar sidebar = [] related = graph.related(uid, label) if related['nodes']: sidebar = [{'title': 'Similar %s' % \ helpers.capitalize_filter(helpers.pluralize(label)), 'data': related['nodes']}] sidebar += get_others(data['rels'], node) if not item_data['content'] and not item_data['excerpts']: item_data['content'] = 'The %s "%s."' % \ (helpers.format_filter(label), helpers.unthe(title)) max_main_length = max([len(i['data']) for i in item_data['main']] + [0]) default_collapse = len(item_data['main']) > 2 or max_main_length > 30 return render_template(request.url, 'item.html', data=item_data, title=title, label=label, sidebar=sidebar, default_collapse=default_collapse)