Beispiel #1
0
def create_entry(text, user):
    split_text = user_ref_pattern.split(text)
    mentions = []
    for i in range(1, len(split_text), 2):
        username = split_text[i]
        try:
            u = User.objects.get(username=username)
            split_text[i] = '<a href="/.users/{0}">@{0}</a>'.format(username)
            mentions.append(u)
        except User.DoesNotExist:
            split_text[i] = '@'+username
    text = "".join(split_text)

    split_text = tag_pattern.split(text)
    for i in range(1, len(split_text), 2):
        tagname = split_text[i]
        split_text[i] = '<a href="/.search?search_string=%23{0}">#{0}</a>'.format(tagname)
    text = "".join(split_text)

    split_text = internal_link_pattern.split(text)
    nodes = []
    for i in range(1, len(split_text), 2):
        path = split_text[i]
        try:
            n = getNodeForPath(path)
            node = n.as_leaf_class()
            if isinstance(node, Slot):
                n = node.get_favorite()

            split_text[i] = '<a href="{0}">{1}</a>'.format(path, n.getShortTitle())
            nodes.append(n)
        except ObjectDoesNotExist:
            pass
    text = "".join(split_text)

    split_text = url_pattern.split(text)
    for i in range(1, len(split_text), 2):
        link = split_text[i]
        split_text[i] = '<a href="{0}">{0}</a>'.format(link)
    text = "".join(split_text)

    entry = Entry()
    entry.content = text
    entry.user = user
    entry.save()
    entry.mentions.add(*mentions)
    entry.node_references.add(*nodes)
    entry.save()
    return entry
Beispiel #2
0
def path(request, path):
    node = getNodeForPath(path).as_leaf_class()
    if isinstance(node, Slot):
        node = node.node_set.order_by('-rating')[0].as_leaf_class()

    ## structure : Graph  : get top rated siblings and select node
    ###            Path   : path to parent select node
    ###            Content: slots
    ## text      : Graph  : get top rated siblings and select node
    ###            Path   : path to parent select node
    ###            Content: slots

    anchor_nodes = getDataForAlternativesGraph(request, node.parent_id, include_node=node.id)
    return render_to_response("node/show.html",
        {"pagename": node.getShortTitle(),
         "this_url": node.getTextPath(),
         "authForm": AuthenticationForm(),
         "navigation": getNavigationData(request, node.id, node.getType()),
         "anchor_nodes": anchor_nodes,
         "selected_id": node.id
        },
        context_instance=RequestContext(request))