Ejemplo n.º 1
0
def related(macro, environ, predicate, obj):
    """Gets links to related items."""
    import wiki
    links = []
    predicate = to_slug(predicate)
    obj = to_slug(obj)
    for slug in wiki.ask("*", predicate, obj):
        node = wiki.get(slug)
        if node:
            links.append( HTML(render_template(["plate/%s.html" % node.get('type', 'default'), "plate/default.html"], node=node)) )
        else:
            links.append( tag.a(slug, href=slug) )
    return tag.div(links, class_="related")
Ejemplo n.º 2
0
def wiki_links_class_func(src):
    if (".com" in src or
        ".net" in src or
        ".org" in src):
        return "external"
    if not redis.exists("n:" + to_slug(src)):
        return "missing"
Ejemplo n.º 3
0
def put(slug, value, update=True):
    slug = to_slug(slug)
    if ':' in slug:
        left, _, right = slug.partition(':')
        if left == 'type':
            return put_type(right, value)
    elif slug == 'type':
        raise RuntimeError("Unnable to alter 'type'.  That's hard coded.")
    
    type = get_type(value['type']) or get_default_type()
    try:
        value = fields.process(type['fields'], value)
    except TypeError:
        raise FormError(type['fields'])
    
    value['type'] = type['slug'].split(':', 1)[1]
    value['slug'] = slug
    if update:
        value['updated'] = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
    relations = set()
    for k, content in value.items():
        if isinstance(content, basestring):
            relations.update(get_relations_from_text(content))
    set_relations(slug, relations)
    redis.set('n:' + slug, json.dumps(value))
    search.index_node(value)
    return value
Ejemplo n.º 4
0
def get(slug):
    slug = to_slug(slug)
    if ':' in slug:
        left, _, right = slug.partition(':')
        if left == 'type':
            return get_type(right)
    if slug == 'type':
        return get_type(slug)
    src = redis.get("n:" + slug)
    if src is None:
        return None
    node = json.loads(src)
    if not 'type' in node:
        node['type'] = 'document'
    return node
Ejemplo n.º 5
0
def wiki_links_path_func(src):
    if (".com" in src or
        ".net" in src or
        ".org" in src):
        return "http://%s" % src
    return to_slug(src)
Ejemplo n.º 6
0
def slug_filter(field, value):
    return util.to_slug(value)
Ejemplo n.º 7
0
def get_relations_from_text(content):
    for rel, obj in re_related.findall(content):
        rel = to_slug(rel)
        obj = to_slug(obj)
        yield rel, obj