示例#1
0
def edition_item(node, rels):
    ''' edition of a grimoire item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'],
                                        ['published', 'edited', 'has'])
    publisher = extract_rel_list(rels, 'publisher', 'start')
    if publisher:
        data['details']['publisher'] = extract_details(publisher)

    editors = extract_rel_list(rels, 'editor', 'start')
    if editors:
        data['details']['editor'] = extract_details(editors)

    grimoire = extract_rel_list(rels, 'grimoire', 'start')
    if grimoire:
        data['details']['grimoire'] = extract_details(grimoire)

    book = extract_rel_list(rels, 'book', 'start')
    if book:
        data['details']['book'] = extract_details(book)

    return data
示例#2
0
def edition_item(node, rels):
    ''' edition of a grimoire item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'],
                                        ['published', 'edited', 'has'])
    publisher = extract_rel_list(rels, 'publisher', 'start')
    if publisher:
        data['details']['publisher'] = extract_details(publisher)

    editors = extract_rel_list(rels, 'editor', 'start')
    if editors:
        data['details']['editor'] = extract_details(editors)

    grimoire = extract_rel_list(rels, 'grimoire', 'start')
    if grimoire:
        data['details']['grimoire'] = extract_details(grimoire)

    book = extract_rel_list(rels, 'book', 'start')
    if book:
        data['details']['book'] = extract_details(book)

    return data
示例#3
0
def grimoire_item(node, rels):
    ''' grimoire item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)

    data['rels'] = helpers.exclude_rels(data['rels'], [
        'lists', 'has', 'includes', 'wrote', 'was_written_in'])

    data['details']['date'] = [{'text': helpers.grimoire_date(node['props'])}]

    authors = extract_rel_list_by_type(rels, 'wrote', 'start')
    authors = extract_details(authors)
    if authors:
        data['details']['author'] = authors

    languages = extract_rel_list_by_type(rels, 'was_written_in', 'end')
    if languages:
        data['details']['language'] = extract_details(languages)

    editions = extract_rel_list(rels, 'edition', 'end')
    if editions:
        data['sidebar'].append({
            'title': 'Editions',
            'data': editions
        })

    for entity in entities:
        items = extract_rel_list_by_type(rels, 'lists', 'end', label=entity)
        if len(items):
            item_json = {
                'title': helpers.pluralize(entity),
                'data': items,
                'many': True,
                'compare': get_comparison(node, entity)
            }
            data['main'].append(item_json)

    spells = extract_rel_list(rels, 'spell', 'end')
    if len(spells):
        data['main'].append({
            'title': 'Spells',
            'data': spells,
            'many': False,
            'compare': get_comparison(node, 'spell')
        })

    talisman = extract_rel_list(rels, 'talisman', 'end')
    if len(talisman):
        data['main'].append({
            'title': 'Talismans',
            'data': talisman,
            'many': False
        })
    return data
示例#4
0
def grimoire_item(node, rels):
    ''' grimoire item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)

    data['rels'] = helpers.exclude_rels(
        data['rels'], ['lists', 'has', 'includes', 'wrote', 'was_written_in'])

    data['details']['date'] = [{'text': helpers.grimoire_date(node['props'])}]

    authors = extract_rel_list_by_type(rels, 'wrote', 'start')
    authors = extract_details(authors)
    if authors:
        data['details']['author'] = authors

    languages = extract_rel_list_by_type(rels, 'was_written_in', 'end')
    if languages:
        data['details']['language'] = extract_details(languages)

    editions = extract_rel_list(rels, 'edition', 'end')
    if editions:
        data['sidebar'].append({'title': 'Editions', 'data': editions})

    for entity in entities:
        items = extract_rel_list_by_type(rels, 'lists', 'end', label=entity)
        if len(items):
            item_json = {
                'title': helpers.pluralize(entity),
                'data': items,
                'many': True,
                'compare': get_comparison(node, entity)
            }
            data['main'].append(item_json)

    spells = extract_rel_list(rels, 'spell', 'end')
    if len(spells):
        data['main'].append({
            'title': 'Spells',
            'data': spells,
            'many': False,
            'compare': get_comparison(node, 'spell')
        })

    talisman = extract_rel_list(rels, 'talisman', 'end')
    if len(talisman):
        data['main'].append({
            'title': 'Talismans',
            'data': talisman,
            'many': False
        })
    return data
示例#5
0
def entity_item(node, rels):
    ''' entity item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)

    # removes duplication of two-way sister rels
    rels = [r for r in rels if r['type'] != 'is_a_sister_of' \
            or r['end']['id'] != node['id']]

    data['rels'] = helpers.exclude_rels(data['rels'], [
        'lists', 'teaches', 'skilled_in', 'serves', 'facilitates',
        'appears_like', 'can', 'for'
    ])
    grimoires = extract_rel_list(rels, 'grimoire', 'start') + \
                extract_rel_list(rels, 'book', 'start')
    if grimoires:
        data['sidebar'].append({'title': 'Grimoires', 'data': grimoires})

    outcomes = extract_rel_list_by_type(rels, 'for', 'end')
    if outcomes:
        data['main'].append({'title': 'Powers', 'data': outcomes})

    appearance = extract_rel_list(rels, 'creature', 'end')
    if appearance:
        data['main'].append({
            'title': 'Appearance',
            'data': appearance,
            'many': True
        })

    serves = extract_rel_list_by_type(rels, 'serves', 'end')
    serves = [
        s for s in serves if not s['props']['uid'] == node['props']['uid']
    ]
    if serves:
        data['main'].append({'title': 'Serves', 'data': serves})

    servants = extract_rel_list_by_type(rels, 'serves', 'start')
    servants = [
        s for s in servants if not s['props']['uid'] == node['props']['uid']
    ]
    if servants:
        data['main'].append({'title': 'Servants', 'data': servants})

    if not data['content']:
        content = 'The %s %s appears in %s' % \
                  (helpers.format_filter(node['label']),
                   node['props']['identifier'],
                   format_list(grimoires))
        data['content'] = markdown(content)
    return data
示例#6
0
def entity_item(node, rels):
    ''' entity item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)

    # removes duplication of two-way sister rels
    rels = [r for r in rels if r['type'] != 'is_a_sister_of' \
            or r['end']['id'] != node['id']]

    data['rels'] = helpers.exclude_rels(data['rels'], [
        'lists', 'teaches', 'skilled_in', 'serves', 'facilitates',
        'appears_like', 'can', 'for'])
    grimoires = extract_rel_list(rels, 'grimoire', 'start') + \
                extract_rel_list(rels, 'book', 'start')
    if grimoires:
        data['sidebar'].append({'title': 'Grimoires', 'data': grimoires})

    outcomes = extract_rel_list_by_type(rels, 'for', 'end')
    if outcomes:
        data['main'].append({'title': 'Powers', 'data': outcomes})

    appearance = extract_rel_list(rels, 'creature', 'end')
    if appearance:
        data['main'].append({
            'title': 'Appearance',
            'data': appearance, 'many': True})

    serves = extract_rel_list_by_type(rels, 'serves', 'end')
    serves = [s for s in serves if
              not s['props']['uid'] == node['props']['uid']]
    if serves:
        data['main'].append({'title': 'Serves', 'data': serves})

    servants = extract_rel_list_by_type(rels, 'serves', 'start')
    servants = [s for s in servants if
                not s['props']['uid'] == node['props']['uid']]
    if servants:
        data['main'].append({'title': 'Servants', 'data': servants})

    if not data['content']:
        content = 'The %s %s appears in %s' % \
                  (helpers.format_filter(node['label']),
                   node['props']['identifier'],
                   format_list(grimoires))
        data['content'] = markdown(content)
    return data
示例#7
0
def spell_item(node, rels):
    ''' spell item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['for', 'uses'])
    try:
        del data['details']['grimoire']
    except KeyError:
        pass

    grimoires = extract_rel_list(rels, 'grimoire', 'start') + \
                extract_rel_list(rels, 'book', 'start')
    if grimoires:
        data['sidebar'].append({'title': 'Grimoires', 'data': grimoires})
        if len(grimoires) == 1:
            data['parent_label'] = grimoires[0]

    ingredients = extract_rel_list(rels, 'parent:ingredient', 'end')
    if ingredients:
        data['main'].append({'title': 'Ingredients', 'data': ingredients})

    outcomes = extract_rel_list_by_type(rels, 'for', 'end')
    if outcomes:
        data['details']['Outcome'] = extract_details(outcomes)

    if not data['content'] and not data['excerpts']:
        content = 'This %s appears in %s, ' \
                  'and you can find the full text there. ' % \
                  (node['label'], format_list(grimoires))
        if outcomes:
            content += 'It is used for %s' % \
                       format_list(outcomes, italics=False).lower()
            if ingredients:
                content += ' and calls for %s' % \
                           format_list(ingredients, italics=False,
                                       show_label=False).lower()
            content += '. '

        data['content'] = markdown(content)
    return data
示例#8
0
def spell_item(node, rels):
    ''' spell item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['for', 'uses'])
    try:
        del data['details']['grimoire']
    except KeyError:
        pass

    grimoires = extract_rel_list(rels, 'grimoire', 'start') + \
                extract_rel_list(rels, 'book', 'start')
    if grimoires:
        data['sidebar'].append({'title': 'Grimoires', 'data': grimoires})
        if len(grimoires) == 1:
            data['parent_label'] = grimoires[0]

    ingredients = extract_rel_list(rels, 'parent:ingredient', 'end')
    if ingredients:
        data['main'].append({'title': 'Ingredients', 'data': ingredients})

    outcomes = extract_rel_list_by_type(rels, 'for', 'end')
    if outcomes:
        data['details']['Outcome'] = extract_details(outcomes)

    if not data['content'] and not data['excerpts']:
        content = 'This %s appears in %s, ' \
                  'and you can find the full text there. ' % \
                  (node['label'], format_list(grimoires))
        if outcomes:
            content += 'It is used for %s' % \
                       format_list(outcomes, italics=False).lower()
            if ingredients:
                content += ' and calls for %s' % \
                           format_list(ingredients, italics=False,
                                       show_label=False).lower()
            content += '. '

        data['content'] = markdown(content)
    return data
示例#9
0
def editor_item(node, rels):
    ''' editor of a grimoire item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['edited'])
    editions = extract_rel_list(rels, 'edition', 'end')
    if editions:
        data['main'].append({'title': 'Editions', 'data': editions})
    return data
示例#10
0
def publisher_item(node, rels):
    ''' publisher item page
    :param node: the publisher item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['published'])
    books = extract_rel_list(rels, 'edition', 'end')
    if books:
        data['main'].append({'title': 'Books', 'data': books})
    return data
示例#11
0
def editor_item(node, rels):
    ''' editor of a grimoire item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['edited'])
    editions = extract_rel_list(rels, 'edition', 'end')
    if editions:
        data['main'].append({'title': 'Editions', 'data': editions})
    return data
示例#12
0
def outcome_item(node, rels):
    ''' spell item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)

    spells = extract_rel_list(rels, 'spell', 'start')
    if spells:
        data['main'].append({'title': 'Spells', 'data': spells})

    for entity in entities:
        items = extract_rel_list(rels, entity, 'start')
        if items:
            data['main'].append({'title': helpers.pluralize(entity),
                                 'data': items})

    data['rels'] = helpers.exclude_rels(data['rels'], ['for'])

    return data
示例#13
0
def publisher_item(node, rels):
    ''' publisher item page
    :param node: the publisher item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['published'])
    books = extract_rel_list(rels, 'edition', 'end')
    if books:
        data['main'].append({'title': 'Books', 'data': books})
    return data
示例#14
0
def outcome_item(node, rels):
    ''' spell item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)

    spells = extract_rel_list(rels, 'spell', 'start')
    if spells:
        data['main'].append({'title': 'Spells', 'data': spells})

    for entity in entities:
        items = extract_rel_list(rels, entity, 'start')
        if items:
            data['main'].append({
                'title': helpers.pluralize(entity),
                'data': items
            })

    data['rels'] = helpers.exclude_rels(data['rels'], ['for'])

    return data
示例#15
0
def language_item(node, rels):
    ''' language item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['was_written_in'])
    grimoires = extract_rel_list(rels, 'grimoire', 'start')
    data['main'].append({
        'title': 'Grimoires Written in this Langage',
        'data': grimoires
    })
    return data
示例#16
0
def language_item(node, rels):
    ''' language item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['rels'] = helpers.exclude_rels(data['rels'], ['was_written_in'])
    grimoires = extract_rel_list(rels, 'grimoire', 'start')
    data['main'].append({
        'title': 'Grimoires Written in this Langage',
        'data': grimoires
    })
    return data
示例#17
0
def art_item(node, rels):
    ''' art/topic item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['entities'] = {}
    for entity in entities:
        items = extract_rel_list(rels, entity, 'start')
        if len(items):
            data['main'].append({
                'title': helpers.pluralize(entity),
                'data': items,
                'many': True
            })
    data['rels'] = helpers.exclude_rels(data['rels'], ['teaches', 'skilled_in'])
    return data
示例#18
0
def art_item(node, rels):
    ''' art/topic item page
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    data = generic_item(node, rels)
    data['entities'] = {}
    for entity in entities:
        items = extract_rel_list(rels, entity, 'start')
        if len(items):
            data['main'].append({
                'title': helpers.pluralize(entity),
                'data': items,
                'many': True
            })
    data['rels'] = helpers.exclude_rels(data['rels'],
                                        ['teaches', 'skilled_in'])
    return data
示例#19
0
def generic_item(node, rels):
    ''' standard item processing
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    def format_field(field):
        ''' deal with array data '''
        if isinstance(field, list):
            return [{'text': i} for i in field]
        return [{'text': field}]

    data = {'id': node['id']}

    try:
        data['content'] = markdown(node['props']['content'])
    except AttributeError:
        data['content'] = ''

    # -- build timeline
    events = extract_rel_list(rels, 'event', 'end')
    for event in events:
        event['props']['relevant'] = True
    related = graph.get_related_events(node['props']['uid'])
    related = zip(related['nodes'], related['rels'])
    for rel_item in related:
        event = rel_item[0]
        this = 'this %s' % helpers.format_filter(node['label'])
        rel_type = helpers.format_filter(rel_item[1]['type'])
        if rel_item[1]['start']['props']['uid'] == node['props']['uid']:
            note = '(%s %s %s)' % \
                   (this, rel_type,
                    helpers.unthe(rel_item[1]['end']['props']['identifier']))
        else:
            note = '(%s %s)' % (rel_type, this)
        event['note'] = note
        events.append(event)
    data['timeline'], data['start_date'], \
            data['end_date'] = build_timeline(events)

    excerpts = extract_rel_list_by_type(rels, 'excerpt', 'end')
    for excerpt in excerpts:
        try:
            excerpt['props']['content'] = markdown(excerpt['props']['content'])
        except AttributeError:
            pass
    data['excerpts'] = excerpts

    data['images'] = extract_rel_list_by_type(rels, 'image',
                                              'end', label='image')

    # remove special node types from relationship lists
    remove = ['excerpt', 'event', 'image', 'contains_item']
    data['rels'] = helpers.exclude_rels(rels, remove)

    data['details'] = {k: format_field(node['props'][k]) for k in
                       node['props'] if k not in
                       ['content', 'uid', 'identifier', 'owned',
                        'buy', 'date_precision', 'isbn']}

    data['buy'] = node['props']['buy'] if 'buy' in node['props'] else None

    data['props'] = node['props']
    data['sidebar'] = []
    data['main'] = []
    data['has_details'] = len([d for d in data['details'] if \
                              data['details'][d]]) > 0
    data['link'] = node['link']

    return data
示例#20
0
def generic_item(node, rels):
    ''' standard item processing
    :param node: the item node
    :param rels: default relationship list
    :return: customized data for this label
    '''
    def format_field(field):
        ''' deal with array data '''
        if isinstance(field, list):
            return [{'text': i} for i in field]
        return [{'text': field}]

    data = {'id': node['id']}

    try:
        content = node['props']['content'].encode('ascii', 'xmlcharrefreplace')
        data['content'] = markdown(content)
    except AttributeError:
        data['content'] = ''

    # -- build timeline
    events = extract_rel_list(rels, 'event', 'end')
    for event in events:
        event['props']['relevant'] = True
    related = graph.get_related_events(node['props']['uid'])
    related = zip(related['nodes'], related['rels'])
    for rel_item in related:
        event = rel_item[0]
        this = 'this %s' % helpers.format_filter(node['label'])
        rel_type = helpers.format_filter(rel_item[1]['type'])
        if rel_item[1]['start']['props']['uid'] == node['props']['uid']:
            note = '(%s %s %s)' % \
                   (this, rel_type,
                    helpers.unthe(rel_item[1]['end']['props']['identifier']))
        else:
            note = '(%s %s)' % (rel_type, this)
        event['note'] = note
        events.append(event)
    data['timeline'], data['start_date'], \
            data['end_date'] = build_timeline(events)

    excerpts = extract_rel_list_by_type(rels, 'excerpt', 'end')
    for excerpt in excerpts:
        try:
            excerpt['props']['content'] = markdown(excerpt['props']['content'])
        except AttributeError:
            pass
    data['excerpts'] = excerpts

    data['images'] = extract_rel_list_by_type(rels,
                                              'image',
                                              'end',
                                              label='image')

    # remove special node types from relationship lists
    remove = ['excerpt', 'event', 'image', 'contains_item']
    data['rels'] = helpers.exclude_rels(rels, remove)

    data['details'] = {
        k: format_field(node['props'][k])
        for k in node['props'] if k not in [
            'content', 'uid', 'identifier', 'owned', 'buy', 'date_precision',
            'isbn', 'full_version'
        ]
    }

    if 'full_version' in node['props']:
        data['full_version'] = node['props']['full_version']

    data['buy'] = node['props']['buy'] if 'buy' in node['props'] else None

    data['props'] = node['props']
    data['sidebar'] = []
    data['main'] = []
    data['has_details'] = len([d for d in data['details'] if \
                              data['details'][d]]) > 0
    data['link'] = node['link']

    return data