示例#1
0
def modIssue(request, issue_id):
    """
    Can be accessed through post or get, will redirect immediately afterwards
    """
    issue = get_object_or_404(Issue, pk=issue_id)
    postResp = {}

    data = request.POST.copy()

    action = data.get('action')
    if action == "dropcc":
        user = get_object_or_404(User, pk=int(data['user']))
        issue.cc.remove(user)
        utils.updateHistory(request.user, issue, "Removed %s from the CC list" % (user))
        postResp['status'] = 1
    elif action == "addcc":
        user = get_object_or_404(User, username=data['user'])
        issue.cc.add(user)
        utils.updateHistory(request.user, issue, "Added %s to the CC list" % (user))
        postResp['username'] = user.username
        postResp['userid'] = user.id
        postResp['status'] = 1

    # FIXME: Needs to deal with error handling here, what happens when user 
    # could not have been removed?

    if request.is_ajax():
        # means an ajax call and so will do a json response
        return HttpResponse(simplejson.dumps(postResp))
    else:
        # direct call, will need to redirect
        return HttpResponseRedirect(reverse('IssueTracker-view', 
                                            args=[issue.issue_id]))
示例#2
0
def viewIssue(request, issue_id):
    """
    This is called when the issue requests a specific issue.
    Basically displays the requested issue and any related comments. Offers the
    user the ability to add comments to the issue.
    If a post is given, will also post a comment
    """

    # get the issue
    issue = get_object_or_404(Issue, pk=issue_id)

    args = {
            'issue': issue,
            'history': IssueHistory.objects.filter(issue=issue).order_by('-time'),
            'comments': IssueComment.objects.filter(issue=issue).order_by('time')
        }
    extraForm = None
    if request.method == 'POST':
        issueProcessor = IssueUpdater(request, issue)
        #CHANGE 
        # if everything passed, redirect to self
        if issueProcessor.is_valid():
            for action in issueProcessor.getUpdateActionString():
                utils.updateHistory(request.user, issue, action)
            issueProcessor.save() 
            if not request.POST.get('cc', None):
                issue.cc.clear()

            return HttpResponseRedirect(reverse('IssueTracker-view', args=[issue.issue_id]))
        form = issueProcessor.updateForm
        commentForm = issueProcessor.commentForm or AddCommentForm()
        extraForm = issueProcessor.extraForm
    else:
        form = UpdateIssueForm(instance=issue)
        commentForm = AddCommentForm()
        if issue.it:
            hook = utils.issueHooks.getHook("updateForm", issue.it.name)
            if hook:
                extraForm = hook(issue)
    #CHANGE
    args['add_comment_form'] = commentForm
    args['update_issue_form'] = form
    args['problem_types'] = form.fields['problem_type'].queryset
    args['extra_form'] = extraForm
    #CHANGE
    args['valid_form']= commentForm.is_valid()
    return render_to_response('view.html', args,
            context_instance=RequestContext(request))