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 }
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}
def delete_tag(request): """todo: actually delete tags now it is only deletion of category from the tree""" if request.user.is_anonymous() or not request.user.is_administrator_or_moderator(): raise exceptions.PermissionDenied() post_data = simplejson.loads(request.raw_post_data) tag_name = forms.clean_tag(post_data["tag_name"]) path = post_data["path"] tree = category_tree.get_data() category_tree.delete_category(tree, tag_name, path) category_tree.save_data(tree) return {"tree_data": tree}
def rename_tag(request): if request.user.is_anonymous() or not request.user.is_administrator_or_moderator(): raise exceptions.PermissionDenied() post_data = simplejson.loads(request.body) to_name = forms.clean_tag(post_data["to_name"]) from_name = forms.clean_tag(post_data["from_name"]) path = post_data["path"] # kwargs = {'from': old_name, 'to': new_name} # call_command('rename_tags', **kwargs) tree = category_tree.get_data() category_tree.rename_category(tree, from_name=from_name, to_name=to_name, path=path) category_tree.save_data(tree)
def rename_tag(request): if request.user.is_anonymous() \ or not request.user.is_administrator_or_moderator(): raise exceptions.PermissionDenied() post_data = json.loads(request.raw_post_data) to_name = forms.clean_tag(post_data['to_name']) from_name = forms.clean_tag(post_data['from_name']) path = post_data['path'] # kwargs = {'from': old_name, 'to': new_name} # call_command('rename_tags', **kwargs) tree = category_tree.get_data() category_tree.rename_category(tree, from_name=from_name, to_name=to_name, path=path) category_tree.save_data(tree)
def delete_tag(request): """todo: actually delete tags now it is only deletion of category from the tree""" if request.user.is_anonymous() or not request.user.is_administrator_or_moderator(): raise exceptions.PermissionDenied() try: post_data = simplejson.loads(request.body) tag_name = post_data["tag_name"] path = post_data["path"] tree = category_tree.get_data() category_tree.delete_category(tree, tag_name, path) category_tree.save_data(tree) except Exception: if "tag_name" in locals(): logging.critical("could not delete tag %s" % tag_name) else: logging.critical("failed to parse post data %s" % request.body) raise exceptions.PermissionDenied(_("Sorry, could not delete tag")) return {"tree_data": tree}
def delete_tag(request): """TODO: actually delete tags now it is only deletion of category from the tree""" if request.user.is_anonymous() \ or not request.user.is_administrator_or_moderator(): raise exceptions.PermissionDenied() try: post_data = json.loads(request.raw_post_data) tag_name = post_data['tag_name'] path = post_data['path'] tree = category_tree.get_data() category_tree.delete_category(tree, tag_name, path) category_tree.save_data(tree) except Exception: traceback.print_exc() if 'tag_name' in locals(): logging.critical('could not delete tag %s' % tag_name) else: logging.critical('failed to parse post data %s' % request.raw_post_data) raise exceptions.PermissionDenied(_('Sorry, could not delete tag')) return {'tree_data': tree}