示例#1
0
文件: repos.py 项目: Tvaske/sponge
def delete(request, repo_id=None):
    repo = repo_utils.get_repo(repo_id)
    form = DeleteOkayForm(request.POST or None, dict(id=repo_id))
    if request.method == 'POST':
        if form.is_valid():
            repoapi = RepositoryAPI()
            try:
                repoapi.delete(repo_id)
                messages.success(request,
                                 "Deleted repository %s (%s)" %
                                 (repo['name'], repo['id']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.repos.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to delete repository %s (%s): %s"
                               (repo['name'], repo['id'], err[1]))
示例#2
0
文件: filters.py 项目: Tvaske/sponge
def delete(request, filter_id=None):
    filterapi = FilterAPI()
    fltr = filterapi.filter(filter_id)
    if request.method == 'POST':
        form = DeleteOkayForm(request.POST)
        if form.is_valid():
            try:
                filterapi.delete(filter_id)
                messages.success(request,
                                 "Deleted filter %s (%s)" %
                                 (fltr['description'], fltr['id']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.filters.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to delete filter %s (%s): %s" %
                               (fltr['description'], fltr['id'], err[1]))
示例#3
0
文件: users.py 项目: Tvaske/sponge
def delete(request, login=None):
    userapi = UserAPI()
    user = userapi.user(login)
    if request.method == 'POST':
        form = DeleteOkayForm(request.POST)
        if form.is_valid():
            try:
                userapi.delete(login=login)
                messages.success(request,
                                 "Deleted user %s (%s)" %
                                 (user['name'], user['login']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.users.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to delete user %s (%s): %s"
                               (user['name'], user['login'], err[1]))
示例#4
0
文件: tasks.py 项目: Tvaske/sponge
def delete(request, task_id=None):
    # figure out if this is a pulp task or a sponge task
    taskapi = TaskAPI()
    task = taskapi.info(task_id)
    if task is not None:
        command = task['method_name'].lstrip("_")
        if task['scheduler'] == 'interval':
            command = "Scheduled %s" % command
        
        if request.method == 'POST':
            form = DeleteOkayForm(request.POST)
            if form.is_valid():
                taskapi.cancel(task_id)
                messages.success(request,
                                 "Deleted task %s (%s)" % (task_id, command))
            return HttpResponseRedirect(reverse('sponge.views.tasks.list'))
        return dict(task_id=task_id,
                    command=command,
                    form=DeleteOkayForm(dict(id=task_id)))
    else:
        # must be a sponge task
        task = CeleryTaskTracker.objects.get(taskid=task_id)
        if request.method == 'POST':
            form = DeleteOkayForm(request.POST)
            if form.is_valid():
                tclass = getattr(tasks, task.taskclass)
                status = tclass.AsyncResult(task.taskid)
                task.delete()
                status.forget()
                messages.success(request,
                                 "Deleted task %s (%s)" % (task.taskid,
                                                           task.taskclass))
            return HttpResponseRedirect(reverse('sponge.views.tasks.list'))
        return dict(task_id=task.taskid,
                    command=task.taskclass,
                    form=DeleteOkayForm(dict(id=task_id)))