예제 #1
0
파일: commands.py 프로젝트: allieus/askbot3
def add_tag_category(request):
    """adds a category at the tip of a given path expects
    the following keys in the ``request.POST``
    * path - array starting with zero giving path to
      the category page where to add the category
    * new_category_name - string that must satisfy the
      same requiremets as a tag

    return json with the category tree data
    TODO: switch to json stored in the live settings
    now we have indented input
    """
    if request.user.is_anonymous() or \
            not request.user.is_administrator_or_moderator():
        raise exceptions.PermissionDenied()

    post_data = json.loads(request.raw_post_data)
    category_name = forms.clean_tag(post_data['new_category_name'])
    path = post_data['path']

    tree = category_tree.get_data()

    if not category_tree.path_is_valid(tree, path):
        raise ValueError('category insertion path is invalid')

    new_path = category_tree.add_category(tree, category_name, path)
    category_tree.save_data(tree)
    return {
        'tree_data': tree,
        'new_path': new_path
    }
예제 #2
0
파일: commands.py 프로젝트: allieus/askbot3
def add_tag_category(request):
    """adds a category at the tip of a given path expects
    the following keys in the ``request.POST``
    * path - array starting with zero giving path to
      the category page where to add the category
    * new_category_name - string that must satisfy the
      same requiremets as a tag

    return json with the category tree data
    TODO: switch to json stored in the live settings
    now we have indented input
    """
    if request.user.is_anonymous() or \
            not request.user.is_administrator_or_moderator():
        raise exceptions.PermissionDenied()

    post_data = json.loads(request.raw_post_data)
    category_name = forms.clean_tag(post_data['new_category_name'])
    path = post_data['path']

    tree = category_tree.get_data()

    if not category_tree.path_is_valid(tree, path):
        raise ValueError('category insertion path is invalid')

    new_path = category_tree.add_category(tree, category_name, path)
    category_tree.save_data(tree)
    return {'tree_data': tree, 'new_path': new_path}
예제 #3
0
 def test_add_category(self):
     ct.add_category(self.tree, 'appreciate', [0, 2])
     appreciate = ct.get_subtree(self.tree, [0, 2, 0])
     self.assertEqual(appreciate[0] , 'appreciate')
예제 #4
0
 def test_add_category(self):
     ct.add_category(self.tree, 'appreciate', [0, 2])
     appreciate = ct.get_subtree(self.tree, [0, 2, 0])
     self.assertEqual(appreciate[0], 'appreciate')