Example #1
0
def store_refinement(request, path):
    assert_authentication(request)
    assert_permissions(
        request,
        [
            "node_storage.add_node",
            "node_storage.add_argument",
            "node_storage.add_vote",
            "node_storage.add_nodeorder",
            "node_storage.add_derivation",
            "node_storage.add_text",
            "node_storage.change_vote",
        ],
    )
    user = request.user
    p = json.loads(request.body)

    origin = get_node_for_path(path)
    slot_path = path.rsplit(".", 1)[0]
    slot = get_node_for_path(slot_path)

    derivate = generate_refinement(origin, p["proposal"], p["argument"], slot, user)

    new_path = get_good_path_for_structure_node(derivate, slot, slot_path)

    # microblog alert
    post_new_derivate_for_node_message(user, path, new_path)

    return json_response({"storeRefinementResponse": {"path": new_path}})
Example #2
0
def store_text(request, path):
    assert_authentication(request)
    assert_permissions(request,
                       ['node_storage.add_node', 'node_storage.add_argument',
                        'node_storage.add_vote', 'node_storage.add_nodeorder',
                        'node_storage.add_derivation', 'node_storage.add_text',
                        'node_storage.change_vote'])
    user = request.user
    p = request.POST
    if 'wikiText' in p and not \
            ('argumentType' in p or 'wikiTextAlternative' in p):

        if len(p['wikiText'].strip()) > 0:
            # fork for additional slot
            new_path = fork_node_and_add_slot(path, user, p['wikiText'])
            # microblog alert
            post_new_derivate_for_node_message(user, path, new_path)
        else:
            raise EmptyText

    elif 'wikiText' in p and 'argumentType' in p and not \
            'wikiTextAlternative' in p:

        if len(p['wikiText'].strip()) > 0:
            # store argument
            new_path = store_argument(path, p['wikiText'], p['argumentType'], user)
            # microblog alert
            post_new_argument_for_node_message(user, path, p['argumentType'], new_path)
        else:
            raise EmptyText

    elif 'wikiTextAlternative' in p and not \
            ('wikiText' in p or 'argumentType' in p):

        if len(p['wikiTextAlternative'].strip()) > 0:
            # store alternative
            _, new_path = store_structure_node(path, p['wikiTextAlternative'], user)
        else:
            raise EmptyText

    elif 'wikiTextAlternative' in p and 'wikiText' in p and 'argumentType' in p:

        if len(p['wikiText'].strip()) > 0 and len(p['wikiTextAlternative'].strip()) > 0:
            # store Argument and Derivate of structure Node as alternative
            arg_text = p['wikiText']
            arg_type = p['argumentType']
            derivate_wiki_text = p['wikiTextAlternative']
            new_path = store_derivate(path, arg_text, arg_type, derivate_wiki_text, user)
            # microblog alert
            post_new_derivate_for_node_message(user, path, new_path)
        else:
            raise EmptyText

    else:
        # wrong usage of API
        raise MissingPOSTParameter('fooo')

    return json_response({'storeTextResponse': {'path': new_path}})
Example #3
0
def store_refinement(request, path):
    assert_authentication(request)
    assert_permissions(request, [
        'node_storage.add_node', 'node_storage.add_argument',
        'node_storage.add_vote', 'node_storage.add_nodeorder',
        'node_storage.add_derivation', 'node_storage.add_text',
        'node_storage.change_vote'
    ])
    user = request.user
    p = json.loads(request.body)

    origin = get_node_for_path(path)
    slot_path = path.rsplit('.', 1)[0]
    slot = get_node_for_path(slot_path)

    derivate = generate_refinement(origin, p['proposal'], p['argument'], slot,
                                   user)

    new_path = get_good_path_for_structure_node(derivate, slot, slot_path)

    # microblog alert
    post_new_derivate_for_node_message(user, path, new_path)

    return json_response({'storeRefinementResponse': {'path': new_path}})
Example #4
0
 def test_post_new_derivate_for_node_message(self):
     hugo = create_user('Hugo')
     node_a = create_nodes_for_path('/bla.1/blubb.1', [hugo])
     node_b = create_nodes_for_path('/bla.2/pling.1', [hugo])
     post = post_new_derivate_for_node_message(hugo, '/bla.1/blubb.1',
                                               '/bla.2/pling.1')
     self.assertEqual(post.author, get_system_user())
     self.assertEqual(post.location, node_a)
     self.assertEqual(post.post_type, Post.NODE_REFINED)
     self.assertIn(hugo, post.mentions.all())
     self.assertIn(node_a, post.node_references.all())
     self.assertIn(node_b, post.node_references.all())
     self.assertEqual(post.node_references.count(), 2)
     self.assertEqual(
         post.text_cache, u'<span style="color: gray;">Hinweis:</span> ' +
         u'<a href="/user/Hugo">@Hugo</a> hat <a href="/bla.1/blubb.1">'
         u'blubb_long<span class="nodeIndex">1</span></a> zu ' +
         u'<a href="/bla.2/pling.1">pling_long'
         u'<span class="nodeIndex">1</span></a> weiterentwickelt.')
 def test_post_new_derivate_for_node_message(self):
     hugo = create_user('Hugo')
     node_a = create_nodes_for_path('/bla.1/blubb.1', [hugo])
     node_b = create_nodes_for_path('/bla.2/pling.1', [hugo])
     post = post_new_derivate_for_node_message(hugo, '/bla.1/blubb.1',
                                               '/bla.2/pling.1')
     self.assertEqual(post.author, get_system_user())
     self.assertEqual(post.location, node_a)
     self.assertEqual(post.post_type, Post.NODE_REFINED)
     self.assertIn(hugo, post.mentions.all())
     self.assertIn(node_a, post.node_references.all())
     self.assertIn(node_b, post.node_references.all())
     self.assertEqual(post.node_references.count(), 2)
     self.assertEqual(
         post.text_cache,
         u'<span style="color: gray;">Hinweis:</span> ' +
         u'<a href="/user/Hugo">@Hugo</a> hat <a href="/bla.1/blubb.1">'
         u'blubb_long<span class="nodeIndex">1</span></a> zu ' +
         u'<a href="/bla.2/pling.1">pling_long'
         u'<span class="nodeIndex">1</span></a> weiterentwickelt.')