Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
[Bug 1269104] Compare a new translation to the English document
Browse files Browse the repository at this point in the history
  • Loading branch information
safwanrahman committed Apr 7, 2017
1 parent 06a1b7e commit 6961f87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
29 changes: 13 additions & 16 deletions kuma/wiki/views/list.py
Expand Up @@ -8,9 +8,8 @@

from ..constants import DOCUMENTS_PER_PAGE
from ..decorators import process_document_path, prevent_indexing
from ..models import (Document, DocumentTag, Revision, ReviewTag,
from ..models import (Document, DocumentTag, ReviewTag,
LocalizationTag)
from ..queries import MultiQuerySet


@block_user_agents
Expand Down Expand Up @@ -190,30 +189,28 @@ def get_previous(revisions):

# Grab revisions, but defer summary and content because they can lead to
# attempts to cache more than memcached allows.
revisions = MultiQuerySet(
(Revision.objects.filter(pk=document.current_revision.pk)
.prefetch_related('creator', 'document')
.transform(get_previous)),
(Revision.objects.filter(document=document)
.order_by('-created', '-id')
.exclude(pk=document.current_revision.pk)
.prefetch_related('creator', 'document')
.transform(get_previous))
)

if not revisions.exists():
all_revisions = (document.revisions.defer('summary', 'content').order_by('created', 'id')
.reverse().transform(get_previous))

if not all_revisions.exists():
raise Http404

if per_page == 'all':
page = None
revisions = list(all_revisions)
else:
try:
per_page = int(per_page)
except ValueError:
per_page = DOCUMENTS_PER_PAGE

page = paginate(request, revisions, per_page)
revisions = page.object_list
page = paginate(request, all_revisions, per_page)
revisions = list(page.object_list)
# In order to compare the first revision of a translation, need to insert its parent revision to the list
# The parent revision should stay at last page in order to compare. So insert only if there are no next page or
# all revisions are showing
if (not page or not page.has_next()) and document.parent:
revisions.append(all_revisions.last().based_on)

context = {
'revisions': revisions,
Expand Down
7 changes: 6 additions & 1 deletion kuma/wiki/views/revision.py
Expand Up @@ -94,7 +94,12 @@ def compare(request, document_slug, document_locale):
to_id = smart_int(request.GET.get('to'))

revisions = Revision.objects.prefetch_related('document')
revision_from = get_object_or_404(revisions, id=from_id, document=doc)
# It should also be possible to compare from the parent document revision
try:
revision_from = revisions.get(id=from_id, document=doc)
except Revision.DoesNotExist:
revision_from = get_object_or_404(revisions, id=from_id, document=doc.parent)

revision_to = get_object_or_404(revisions, id=to_id, document=doc)

context = {
Expand Down

0 comments on commit 6961f87

Please sign in to comment.