Пример #1
0
def view(id, slug=None):
    entity = Entity.by_id(id)
    if entity is None:
        raise NotFound()
    if entity.same_as is not None:
        canonical = Entity.by_id(entity.same_as)
        return redirect(entity_link(canonical))
    inbound_sections = []
    slug = url_slug(entity['name'].value)
    for schema in entity.inbound_schemata:
        pager_name = schema.name + '_in'
        pager = Pager(entity.inbound_by_schema(schema), pager_name, id=id, slug=slug, limit=15)
        inbound_sections.append((schema, pager))
    outbound_sections = []
    for schema in entity.outbound_schemata:
        pager_name = schema.name + '_out'
        pager = Pager(entity.outbound_by_schema(schema), pager_name, id=id, slug=slug, limit=15)
        outbound_sections.append((schema, pager))

    canonical_url = entity_link(entity, **dict(request.args.items()))
    entity_hairball = app.config.get('ENTITY_HAIRBALL', True)
    return render_template('entity.html', entity=entity,
        canonical_url=canonical_url,
        entity_hairball=entity_hairball,
        inbound_sections=inbound_sections,
        outbound_sections=outbound_sections,
        render_relation=render_relation)
Пример #2
0
def sitemap_xml():
    rp = db.session.execute("""
        SELECT e.id AS id, p.value_string AS name, e.updated_at AS updated
            FROM grano_entity e, grano_property p, grano_relation r
            WHERE e.id = p.entity_id AND p.name = 'name'
                AND p.value_string IS NOT NULL
                AND p.active = true
                AND (r.target_id = e.id OR r.source_id = e.id)
            GROUP BY e.id, p.value_string, e.updated_at
            ORDER BY COUNT(r.id) DESC
            LIMIT 49500
    """)
    entities = []
    while True:
        row = rp.fetchone()
        if row is None:
            break
        url = url_for('entities.view', id=row['id'], slug=url_slug(row['name']))
        entities.append((url, row['updated']))
    text = render_template('sitemap_simple.xml', entities=entities)
    res = make_response(text)
    res.headers['Content-Type'] = 'text/xml'
    return res