Пример #1
0
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
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_path_is_nvalid_too_deep(self):
     self.assertEqual(
         ct.path_is_valid(self.tree, [0,2,0,0,0]), False
     )
Пример #4
0
 def test_path_is_valid_deep(self):
     self.assertEqual(
         ct.path_is_valid(self.tree, [0,2,0,0]), True
     )
Пример #5
0
 def test_path_is_valid_dummy(self):
     self.assertEqual(
         ct.path_is_valid(self.tree, [0]), True
     )
Пример #6
0
 def test_path_is_nvalid_too_deep(self):
     self.assertEqual(ct.path_is_valid(self.tree, [0, 2, 0, 0, 0]), False)
Пример #7
0
 def test_path_is_valid_deep(self):
     self.assertEqual(ct.path_is_valid(self.tree, [0, 2, 0, 0]), True)
Пример #8
0
 def test_path_is_valid_dummy(self):
     self.assertEqual(ct.path_is_valid(self.tree, [0]), True)