Exemple #1
0
def diff(request,
         review_request_id,
         revision=None,
         interdiff_revision=None,
         local_site_name=None,
         template_name='diffviewer/view_diff.html'):
    """
    A wrapper around diffviewer.views.view_diff that handles querying for
    diffs owned by a review request,taking into account interdiffs and
    providing the user's current review of the diff if it exists.
    """
    review_request, response = \
        _find_review_request(request, review_request_id, local_site_name)

    if not review_request:
        return response

    diffset = _query_for_diff(review_request, request.user, revision)

    interdiffset = None
    interdiffset_id = None
    review = None
    draft = None

    if interdiff_revision and interdiff_revision != revision:
        # An interdiff revision was specified. Try to find a matching
        # diffset.
        interdiffset = _query_for_diff(review_request, request.user,
                                       interdiff_revision)
        interdiffset_id = interdiffset.id

    # Try to find an existing pending review of this diff from the
    # current user.
    review = review_request.get_pending_review(request.user)
    draft = review_request.get_draft(request.user)

    has_draft_diff = draft and draft.diffset
    is_draft_diff = has_draft_diff and draft.diffset == diffset
    is_draft_interdiff = has_draft_diff and interdiffset and \
                         draft.diffset == interdiffset

    num_diffs = review_request.diffset_history.diffsets.count()
    if draft and draft.diffset:
        num_diffs += 1

    last_activity_time, updated_object = review_request.get_last_activity()

    return view_diff(
         request, diffset.id, interdiffset_id, template_name=template_name,
         extra_context=_make_review_request_context(review_request, {
            'review': review,
            'review_request_details': draft or review_request,
            'draft': draft,
            'is_draft_diff': is_draft_diff,
            'is_draft_interdiff': is_draft_interdiff,
            'num_diffs': num_diffs,
            'last_activity_time': last_activity_time,
            'specific_diff_requested': revision is not None or
                                       interdiff_revision is not None,
        }))
Exemple #2
0
def diff(request,
         review_request_id,
         revision=None,
         interdiff_revision=None,
         local_site_name=None,
         template_name='diffviewer/view_diff.html'):
    """
    A wrapper around diffviewer.views.view_diff that handles querying for
    diffs owned by a review request,taking into account interdiffs and
    providing the user's current review of the diff if it exists.
    """
    review_request, response = \
        _find_review_request(request, review_request_id, local_site_name)

    if not review_request:
        return response

    diffset = _query_for_diff(review_request, request.user, revision)

    interdiffset = None
    review = None
    draft = None

    if interdiff_revision and interdiff_revision != revision:
        # An interdiff revision was specified. Try to find a matching
        # diffset.
        interdiffset = _query_for_diff(review_request, request.user,
                                       interdiff_revision)

    # Try to find an existing pending review of this diff from the
    # current user.
    review = review_request.get_pending_review(request.user)
    draft = review_request.get_draft(request.user)

    has_draft_diff = draft and draft.diffset
    is_draft_diff = has_draft_diff and draft.diffset == diffset
    is_draft_interdiff = has_draft_diff and interdiffset and \
                         draft.diffset == interdiffset

    num_diffs = review_request.diffset_history.diffsets.count()
    if draft and draft.diffset:
        num_diffs += 1

    last_activity_time, updated_object = review_request.get_last_activity()

    return view_diff(
         request, diffset, interdiffset, template_name=template_name,
         extra_context=_make_review_request_context(review_request, {
            'review': review,
            'review_request_details': draft or review_request,
            'draft': draft,
            'is_draft_diff': is_draft_diff,
            'is_draft_interdiff': is_draft_interdiff,
            'num_diffs': num_diffs,
            'last_activity_time': last_activity_time,
            'specific_diff_requested': revision is not None or
                                       interdiff_revision is not None,
            'base_url': review_request.get_absolute_url(),
        }))
Exemple #3
0
def diff(request, review_request_id, revision=None, interdiff_revision=None, template_name="diffviewer/view_diff.html"):
    """
    A wrapper around diffviewer.views.view_diff that handles querying for
    diffs owned by a review request,taking into account interdiffs and
    providing the user's current review of the diff if it exists.
    """
    review_request = get_object_or_404(ReviewRequest, pk=review_request_id)
    diffset = _query_for_diff(review_request, request.user, revision)

    interdiffset = None
    interdiffset_id = None
    review = None
    draft = None

    if interdiff_revision and interdiff_revision != revision:
        # An interdiff revision was specified. Try to find a matching
        # diffset.
        interdiffset = _query_for_diff(review_request, request.user, interdiff_revision)
        interdiffset_id = interdiffset.id

    # Try to find an existing pending review of this diff from the
    # current user.
    review = review_request.get_pending_review(request.user)
    draft = review_request.get_draft(request.user)

    repository = review_request.repository

    has_draft_diff = draft and draft.diffset
    is_draft_diff = has_draft_diff and draft.diffset == diffset
    is_draft_interdiff = has_draft_diff and interdiffset and draft.diffset == interdiffset

    num_diffs = review_request.diffset_history.diffsets.count()
    if draft and draft.diffset:
        num_diffs += 1

    last_activity_time, updated_object = review_request.get_last_activity()

    return view_diff(
        request,
        diffset.id,
        interdiffset_id,
        {
            "review": review,
            "review_request": review_request,
            "review_request_details": draft or review_request,
            "draft": draft,
            "is_draft_diff": is_draft_diff,
            "is_draft_interdiff": is_draft_interdiff,
            "num_diffs": num_diffs,
            "upload_diff_form": UploadDiffForm(review_request),
            "upload_screenshot_form": UploadScreenshotForm(),
            "scmtool": repository.get_scmtool(),
            "last_activity_time": last_activity_time,
            "specific_diff_requested": revision is not None or interdiff_revision is not None,
        },
        template_name,
    )
Exemple #4
0
def diff(request, review_request_id, revision=None, interdiff_revision=None,
         template_name='diffviewer/view_diff.html'):
    """
    A wrapper around diffviewer.views.view_diff that handles querying for
    diffs owned by a review request,taking into account interdiffs and
    providing the user's current review of the diff if it exists.
    """
    review_request = get_object_or_404(ReviewRequest, pk=review_request_id)
    diffset = _query_for_diff(review_request, request.user, revision)

    interdiffset = None
    interdiffset_id = None
    review = None
    draft = None

    if interdiff_revision and interdiff_revision != revision:
        # An interdiff revision was specified. Try to find a matching
        # diffset.
        interdiffset = _query_for_diff(review_request, request.user,
                                       interdiff_revision)
        interdiffset_id = interdiffset.id

    # Try to find an existing pending review of this diff from the
    # current user.
    review = review_request.get_pending_review(request.user)
    draft = review_request.get_draft(request.user)

    repository = review_request.repository

    has_draft_diff = draft and draft.diffset
    is_draft_diff = has_draft_diff and draft.diffset == diffset
    is_draft_interdiff = has_draft_diff and interdiffset and \
                         draft.diffset == interdiffset

    num_diffs = review_request.diffset_history.diffsets.count()
    if draft and draft.diffset:
        num_diffs += 1

    return view_diff(request, diffset.id, interdiffset_id, {
        'review': review,
        'review_request': review_request,
        'review_request_details': draft or review_request,
        'draft': draft,
        'is_draft_diff': is_draft_diff,
        'is_draft_interdiff': is_draft_interdiff,
        'num_diffs': num_diffs,
        'upload_diff_form': UploadDiffForm(repository),
        'upload_screenshot_form': UploadScreenshotForm(),
        'scmtool': repository.get_scmtool(),
    }, template_name)
Exemple #5
0
def diff(request,
         review_request_id,
         revision=None,
         interdiff_revision=None,
         local_site_name=None,
         template_name='diffviewer/view_diff.html'):
    """
    A wrapper around diffviewer.views.view_diff that handles querying for
    diffs owned by a review request,taking into account interdiffs and
    providing the user's current review of the diff if it exists.
    """
    review_request, response = \
        _find_review_request(request, review_request_id, local_site_name)

    if not review_request:
        return response

    diffset = _query_for_diff(review_request, request.user, revision)

    interdiffset = None
    review = None
    draft = None

    if interdiff_revision and interdiff_revision != revision:
        # An interdiff revision was specified. Try to find a matching
        # diffset.
        interdiffset = _query_for_diff(review_request, request.user,
                                       interdiff_revision)

    # Try to find an existing pending review of this diff from the
    # current user.
    review = review_request.get_pending_review(request.user)
    draft = review_request.get_draft(request.user)

    has_draft_diff = draft and draft.diffset
    is_draft_diff = has_draft_diff and draft.diffset == diffset
    is_draft_interdiff = has_draft_diff and interdiffset and \
                         draft.diffset == interdiffset

    num_diffs = review_request.diffset_history.diffsets.count()
    if draft and draft.diffset:
        num_diffs += 1

    last_activity_time, updated_object = review_request.get_last_activity()

    # Passes the timestamp for the latest diff through to bust the page cache.
    # Without this a very peculiar use case fails...
    # 1. publish a review with multiple files
    # 2. upload a revision to several files but don't publish
    # 3. view the diff between versions 1 and 2
    # 4. upload a second revision for those files, still without publishing
    # 5. view the diff between versions 1 and 2 again
    #
    # For any fragments loaded by ajax (ie, all the diffs but the first) you
    # will still see the same diff as step #3. This is because the diff uses
    # the lower diff id for the url (the one for version 1) which causes the
    # page cache to hold onto the old content.

    draft_diff_time = 0
    if has_draft_diff:
      try:
        draft_timestamp = draft.diffset.timestamp
        draft_diff_time = time.mktime(draft_timestamp.timetuple())
      except DiffSet.DoesNotExist: pass

    return view_diff(
         request, diffset, interdiffset, template_name=template_name,
         extra_context=_make_review_request_context(review_request, {
            'review': review,
            'review_request_details': draft or review_request,
            'draft': draft,
            'is_draft_diff': is_draft_diff,
            'is_draft_interdiff': is_draft_interdiff,
            'num_diffs': num_diffs,
            'last_activity_time': last_activity_time,
            'draft_diff_time': draft_diff_time,
            'specific_diff_requested': revision is not None or
                                       interdiff_revision is not None,
            'base_url': review_request.get_absolute_url(),
        }))
Exemple #6
0
def diff(
    request,
    review_request_id,
    revision=None,
    interdiff_revision=None,
    local_site_name=None,
    template_name="diffviewer/view_diff.html",
):
    """
    A wrapper around diffviewer.views.view_diff that handles querying for
    diffs owned by a review request,taking into account interdiffs and
    providing the user's current review of the diff if it exists.
    """
    review_request, response = _find_review_request(request, review_request_id, local_site_name)

    if not review_request:
        return response

    diffset = _query_for_diff(review_request, request.user, revision)

    interdiffset = None
    review = None
    draft = None

    if interdiff_revision and interdiff_revision != revision:
        # An interdiff revision was specified. Try to find a matching
        # diffset.
        interdiffset = _query_for_diff(review_request, request.user, interdiff_revision)

    # Try to find an existing pending review of this diff from the
    # current user.
    review = review_request.get_pending_review(request.user)
    draft = review_request.get_draft(request.user)

    has_draft_diff = draft and draft.diffset
    is_draft_diff = has_draft_diff and draft.diffset == diffset
    is_draft_interdiff = has_draft_diff and interdiffset and draft.diffset == interdiffset

    num_diffs = review_request.diffset_history.diffsets.count()
    if draft and draft.diffset:
        num_diffs += 1

    last_activity_time, updated_object = review_request.get_last_activity()

    return view_diff(
        request,
        diffset,
        interdiffset,
        template_name=template_name,
        extra_context=_make_review_request_context(
            review_request,
            {
                "review": review,
                "review_request_details": draft or review_request,
                "draft": draft,
                "is_draft_diff": is_draft_diff,
                "is_draft_interdiff": is_draft_interdiff,
                "num_diffs": num_diffs,
                "last_activity_time": last_activity_time,
                "specific_diff_requested": revision is not None or interdiff_revision is not None,
                "base_url": review_request.get_absolute_url(),
            },
        ),
    )