示例#1
0
def store_argument(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_text",
            "node_storage.change_vote",
        ],
    )
    user = request.user
    p = json.loads(request.body)

    node = get_node_for_path(path)
    title = p["argument"]["title"]
    text = p["argument"]["text"]
    arg_type = p["argument"]["type"]
    arg = create_argument(node, arg_type=arg_type, title=title, text=text, authors=[user])
    create_vote(user, [arg])  # auto-follow
    new_path = "{path}.{arg_type}.{index}".format(path=path, arg_type=arg_type, index=arg.index)

    # microblog alert
    post_new_argument_for_node_message(user, path, p["argument"]["type"], new_path)
    return json_response({"storeArgumentResponse": {"path": new_path}})
示例#2
0
def store_argument(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_text', 'node_storage.change_vote'
    ])
    user = request.user
    p = json.loads(request.body)

    node = get_node_for_path(path)
    title = p['argument']['title']
    text = p['argument']['text']
    arg_type = p['argument']['type']
    arg = create_argument(node,
                          arg_type=arg_type,
                          title=title,
                          text=text,
                          authors=[user])
    create_vote(user, [arg])  # auto-follow
    new_path = "{path}.{arg_type}.{index}".format(path=path,
                                                  arg_type=arg_type,
                                                  index=arg.index)

    # microblog alert
    post_new_argument_for_node_message(user, path, p['argument']['type'],
                                       new_path)
    return json_response({'storeArgumentResponse': {'path': new_path}})
示例#3
0
文件: views.py 项目: justelex/Findeco
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}})
示例#4
0
 def test_post_new_generic_argument_for_node_message(self):
     hugo = create_user('Hugo')
     node = create_nodes_for_path('/bla.1/blubb.1', [hugo])
     argument = create_argument(node, Argument.PRO, 'Argumentutinio',
                                'Arrgumente!', [hugo])
     post = post_new_argument_for_node_message(hugo, '/bla.1/blubb.1',
                                               Argument.PRO,
                                               '/bla.1/blubb.1.pro.1')
     self.assertEqual(post.author, get_system_user())
     self.assertEqual(post.location, node)
     self.assertEqual(post.post_type, Post.ARGUMENT_CREATED)
     self.assertIn(hugo, post.mentions.all())
     self.assertIn(node, post.node_references.all())
     self.assertIn(argument.pk, [a.pk for a in 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 dem Vorschlag '
         u'<a href="/bla.1/blubb.1">blubb_long'
         u'<span class="nodeIndex">1</span></a> das Argument ' +
         u'<a href="/bla.1/blubb.1.pro.1">Argumentutinio'
         u'<span class="nodeIndex">1</span></a> hinzugefügt.')
 def test_post_new_generic_argument_for_node_message(self):
     hugo = create_user('Hugo')
     node = create_nodes_for_path('/bla.1/blubb.1', [hugo])
     argument = create_argument(node, Argument.PRO, 'Argumentutinio',
                                'Arrgumente!', [hugo])
     post = post_new_argument_for_node_message(hugo, '/bla.1/blubb.1',
                                               Argument.PRO,
                                               '/bla.1/blubb.1.pro.1')
     self.assertEqual(post.author, get_system_user())
     self.assertEqual(post.location, node)
     self.assertEqual(post.post_type, Post.ARGUMENT_CREATED)
     self.assertIn(hugo, post.mentions.all())
     self.assertIn(node, post.node_references.all())
     self.assertIn(argument.pk, [a.pk for a in 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 dem Vorschlag '
         u'<a href="/bla.1/blubb.1">blubb_long'
         u'<span class="nodeIndex">1</span></a> das Argument ' +
         u'<a href="/bla.1/blubb.1.pro.1">Argumentutinio'
         u'<span class="nodeIndex">1</span></a> hinzugefügt.')