Ejemplo n.º 1
0
def new_review_request(request, template_name="reviews/new_review_request.html"):
    """
    Displays a New Review Request form and handles the creation of a
    review request based on either an existing changeset or the provided
    information.
    """
    if request.method == "POST":
        form = NewReviewRequestForm(request.POST, request.FILES)

        if form.is_valid():
            try:
                review_request = form.create(
                    user=request.user,
                    diff_file=request.FILES["diff_path"],
                    parent_diff_file=request.FILES.get("parent_diff_path"),
                )
                return HttpResponseRedirect(review_request.get_absolute_url())
            except (OwnershipError, ChangeSetError):
                pass
    else:
        form = NewReviewRequestForm()

    return render_to_response(
        template_name, RequestContext(request, {"form": form, "fields": simplejson.dumps(form.field_mapping)})
    )
Ejemplo n.º 2
0
def new_review_request(request,
                       template_name='reviews/new_review_request.html'):
    """
    Displays a New Review Request form and handles the creation of a
    review request based on either an existing changeset or the provided
    information.
    """
    if request.method == 'POST':
        form = NewReviewRequestForm(request.POST, request.FILES)

        if form.is_valid():
            try:
                review_request = form.create(
                    user=request.user,
                    diff_file=request.FILES['diff_path'],
                    parent_diff_file=request.FILES.get('parent_diff_path'))
                return HttpResponseRedirect(review_request.get_absolute_url())
            except:
                # XXX - OwnershipError or ChangeSetError?
                #
                # We're preventing an exception from being thrown here so that
                # we can display the errors that form.create() sets in
                # a much nicer way in the template. Otherwise, the user would
                # see a useless backtrace.
                pass
    else:
        form = NewReviewRequestForm()

    return render_to_response(template_name, RequestContext(request, {
        'form': form,
        'fields': simplejson.dumps(form.field_mapping),
    }))
Ejemplo n.º 3
0
def new_review_request(request,
                       template_name='reviews/new_review_request.html'):
    """
    Displays a New Review Request form and handles the creation of a
    review request based on either an existing changeset or the provided
    information.
    """
    if request.method == 'POST':
        form = NewReviewRequestForm(request.POST, request.FILES)

        if form.is_valid():
            try:
                review_request = form.create(
                    user=request.user,
                    diff_file=request.FILES.get('diff_path'),
                    parent_diff_file=request.FILES.get('parent_diff_path'))
                return HttpResponseRedirect(review_request.get_absolute_url())
            except (OwnershipError, SCMError, ValueError):
                pass
    else:
        form = NewReviewRequestForm()

    return render_to_response(template_name, RequestContext(request, {
        'form': form,
        'fields': simplejson.dumps(form.field_mapping),
    }))
Ejemplo n.º 4
0
def new_review_request(request, local_site_name=None, template_name="reviews/new_review_request.html"):
    """
    Displays a New Review Request form and handles the creation of a
    review request based on either an existing changeset or the provided
    information.
    """
    if local_site_name:
        local_site = get_object_or_404(LocalSite, name=local_site_name)
        if not local_site.is_accessible_by(request.user):
            return _render_permission_denied(request)
    else:
        local_site = None

    if request.method == "POST":
        form = NewReviewRequestForm(request.user, local_site, request.POST, request.FILES)

        if form.is_valid():
            try:
                review_request = form.create(
                    user=request.user,
                    diff_file=request.FILES.get("diff_path"),
                    parent_diff_file=request.FILES.get("parent_diff_path"),
                    local_site=local_site,
                )
                return HttpResponseRedirect(review_request.get_absolute_url())
            except (OwnershipError, SCMError, ValueError):
                pass
    else:
        form = NewReviewRequestForm(request.user, local_site)

    return render_to_response(
        template_name, RequestContext(request, {"form": form, "fields": simplejson.dumps(form.field_mapping)})
    )
Ejemplo n.º 5
0
def new_review_request(request, template_name="reviews/new_review_request.html"):
    """
    Displays a New Review Request form and handles the creation of a
    review request based on either an existing changeset or the provided
    information.
    """
    if request.method == "POST":
        form = NewReviewRequestForm(request.POST, request.FILES)

        if form.is_valid():
            try:
                review_request = form.create(
                    user=request.user,
                    diff_file=request.FILES["diff_path"],
                    parent_diff_file=request.FILES.get("parent_diff_path"),
                )
                return HttpResponseRedirect(review_request.get_absolute_url())
            except:
                # XXX - OwnershipError or ChangeSetError?
                #
                # We're preventing an exception from being thrown here so that
                # we can display the errors that form.create() sets in
                # a much nicer way in the template. Otherwise, the user would
                # see a useless backtrace.
                pass
    else:
        form = NewReviewRequestForm()

    # Repository ID : visible fields mapping.  This is so we can dynamically
    # show/hide the relevant fields with javascript.
    fields = {}
    for repo in Repository.objects.all():
        fields[repo.id] = repo.get_scmtool().get_fields()

    # Turn the selected index back into an int so we can compare it properly.
    if "repository" in form.data:
        form.data["repository"] = int(form.data["repository"])

    return render_to_response(
        template_name, RequestContext(request, {"form": form, "fields": simplejson.dumps(fields)})
    )
Ejemplo n.º 6
0
def new_review_request(request,
                       local_site_name=None,
                       template_name='reviews/new_review_request.html'):
    """
    Displays a New Review Request form and handles the creation of a
    review request based on either an existing changeset or the provided
    information.
    """
    if local_site_name:
        local_site = get_object_or_404(LocalSite, name=local_site_name)

        if (request.user.is_anonymous() or
            not local_site.users.filter(pk=request.user.pk).exists()):
            return _render_permission_denied(requset)
    else:
        local_site = None

    if request.method == 'POST':
        form = NewReviewRequestForm(request.user, local_site,
                                    request.POST, request.FILES)

        if form.is_valid():
            try:
                review_request = form.create(
                    user=request.user,
                    diff_file=request.FILES.get('diff_path'),
                    parent_diff_file=request.FILES.get('parent_diff_path'),
                    local_site=local_site)
                return HttpResponseRedirect(review_request.get_absolute_url())
            except (OwnershipError, SCMError, ValueError):
                pass
    else:
        form = NewReviewRequestForm(request.user, local_site)

    return render_to_response(template_name, RequestContext(request, {
        'form': form,
        'fields': simplejson.dumps(form.field_mapping),
    }))
Ejemplo n.º 7
0
def new_review_request(request,
                       local_site_name=None,
                       template_name='reviews/new_review_request.html'):
    """
    Displays a New Review Request form and handles the creation of a
    review request based on either an existing changeset or the provided
    information.
    """
    if local_site_name:
        local_site = get_object_or_404(LocalSite, name=local_site_name)
        if not local_site.is_accessible_by(request.user):
            return _render_permission_denied(request)
    else:
        local_site = None

    if request.method == 'POST':
        form = NewReviewRequestForm(request.user, local_site, request.POST,
                                    request.FILES)

        if form.is_valid():
            try:
                review_request = form.create(
                    user=request.user,
                    diff_file=request.FILES.get('diff_path'),
                    parent_diff_file=request.FILES.get('parent_diff_path'),
                    local_site=local_site)
                return HttpResponseRedirect(review_request.get_absolute_url())
            except (OwnershipError, SCMError, ValueError):
                pass
    else:
        form = NewReviewRequestForm(request.user, local_site)

    return render_to_response(
        template_name,
        RequestContext(request, {
            'form': form,
            'fields': simplejson.dumps(form.field_mapping),
        }))