예제 #1
0
 def test_find_related_documents(self):
     trans1 = translated_revision(is_approved=True)
     trans1.save()
     d1 = trans1.document
     trans2 = translated_revision(is_approved=True)
     trans2.save()
     d2 = trans2.document
     RelatedDocument.objects.create(document=d1.parent,
                                    related=d2.parent, in_common=2)
     # Assert the English versions still match
     assert list(find_related_documents(d1.parent)) == [d2.parent]
     # Assert that the translation matches
     assert list(find_related_documents(d1)) == [d2]
예제 #2
0
파일: test_models.py 프로젝트: ibai/kitsune
 def test_find_related_documents(self):
     trans1 = translated_revision(is_approved=True)
     trans1.save()
     d1 = trans1.document
     trans2 = translated_revision(is_approved=True)
     trans2.save()
     d2 = trans2.document
     RelatedDocument.objects.create(document=d1.parent,
                                    related=d2.parent,
                                    in_common=2)
     # Assert the English versions still match
     assert list(find_related_documents(d1.parent)) == [d2.parent]
     # Assert that the translation matches
     assert list(find_related_documents(d1)) == [d2]
예제 #3
0
def document(request, document_slug, template=None):
    """View a wiki document."""
    fallback_reason = None
    # If a slug isn't available in the requested locale, fall back to en-US:
    try:
        doc = Document.objects.get(locale=request.locale, slug=document_slug)
        if (not doc.current_revision and doc.parent
                and doc.parent.current_revision):
            # This is a translation but its current_revision is None
            # and OK to fall back to parent (parent is approved).
            fallback_reason = 'translation_not_approved'
        elif not doc.current_revision:
            # No current_revision, no parent with current revision, so
            # nothing to show.
            fallback_reason = 'no_content'
    except Document.DoesNotExist:
        # Look in default language:
        doc = get_object_or_404(Document,
                                locale=settings.WIKI_DEFAULT_LANGUAGE,
                                slug=document_slug)
        # If there's a translation to the requested locale, take it:
        translation = doc.translated_to(request.locale)
        if translation:
            url = translation.get_absolute_url()
            url = urlparams(url, query_dict=request.GET)
            return HttpResponseRedirect(url)
        elif doc.current_revision:
            # There is no translation
            # and OK to fall back to parent (parent is approved).
            fallback_reason = 'no_translation'

    # Obey explicit redirect pages:
    # Don't redirect on redirect=no (like Wikipedia), so we can link from a
    # redirected-to-page back to a "Redirected from..." link, so you can edit
    # the redirect.
    redirect_url = (None if request.GET.get('redirect') == 'no' else
                    doc.redirect_url(request.locale))
    if redirect_url:
        url = urlparams(redirect_url,
                        query_dict=request.GET,
                        redirectslug=doc.slug,
                        redirectlocale=doc.locale)
        return HttpResponseRedirect(url)

    # Get "redirected from" doc if we were redirected:
    redirect_slug = request.GET.get('redirectslug')
    redirect_locale = request.GET.get('redirectlocale')
    redirected_from = None
    if redirect_slug and redirect_locale:
        try:
            redirected_from = Document.objects.get(locale=redirect_locale,
                                                   slug=redirect_slug)
        except Document.DoesNotExist:
            pass

    related = find_related_documents(doc)

    contributors = doc.contributors.all()

    products = doc.get_products()
    if len(products) < 1:
        product = Product.objects.filter(visible=True)[0]
    else:
        product = products[0]

    topics = doc.get_topics()

    data = {
        'document': doc,
        'redirected_from': redirected_from,
        'related': related,
        'contributors': contributors,
        'fallback_reason': fallback_reason,
        'is_aoa_referral': request.GET.get('ref') == 'aoa',
        'topics': topics,
        'product': product
    }
    data.update(SHOWFOR_DATA)
    return jingo.render(request, template, data)
예제 #4
0
파일: views.py 프로젝트: muratmeran/kitsune
def document(request, document_slug, template=None):
    """View a wiki document."""
    fallback_reason = None
    # If a slug isn't available in the requested locale, fall back to en-US:
    try:
        doc = Document.objects.get(locale=request.locale, slug=document_slug)
        if not doc.current_revision and doc.parent and doc.parent.current_revision:
            # This is a translation but its current_revision is None
            # and OK to fall back to parent (parent is approved).
            fallback_reason = "translation_not_approved"
        elif not doc.current_revision:
            # No current_revision, no parent with current revision, so
            # nothing to show.
            fallback_reason = "no_content"
    except Document.DoesNotExist:
        # Look in default language:
        doc = get_object_or_404(Document, locale=settings.WIKI_DEFAULT_LANGUAGE, slug=document_slug)
        # If there's a translation to the requested locale, take it:
        translation = doc.translated_to(request.locale)
        if translation:
            url = translation.get_absolute_url()
            url = urlparams(url, query_dict=request.GET)
            return HttpResponseRedirect(url)
        elif doc.current_revision:
            # There is no translation
            # and OK to fall back to parent (parent is approved).
            fallback_reason = "no_translation"

    # Obey explicit redirect pages:
    # Don't redirect on redirect=no (like Wikipedia), so we can link from a
    # redirected-to-page back to a "Redirected from..." link, so you can edit
    # the redirect.
    redirect_url = None if request.GET.get("redirect") == "no" else doc.redirect_url()
    if redirect_url:
        url = urlparams(redirect_url, query_dict=request.GET, redirectslug=doc.slug, redirectlocale=doc.locale)
        return HttpResponseRedirect(url)

    # Get "redirected from" doc if we were redirected:
    redirect_slug = request.GET.get("redirectslug")
    redirect_locale = request.GET.get("redirectlocale")
    redirected_from = None
    if redirect_slug and redirect_locale:
        try:
            redirected_from = Document.objects.get(locale=redirect_locale, slug=redirect_slug)
        except Document.DoesNotExist:
            pass

    related = find_related_documents(doc)

    contributors = doc.contributors.all()

    data = {
        "document": doc,
        "redirected_from": redirected_from,
        "related": related,
        "contributors": contributors,
        "fallback_reason": fallback_reason,
        "is_aoa_referral": request.GET.get("ref") == "aoa",
    }
    data.update(SHOWFOR_DATA)
    return jingo.render(request, template, data)
예제 #5
0
파일: views.py 프로젝트: bebef1987/kitsune
def document(request, document_slug, template=None):
    """View a wiki document."""
    fallback_reason = None
    # If a slug isn't available in the requested locale, fall back to en-US:
    try:
        doc = Document.objects.get(locale=request.locale, slug=document_slug)
        if (not doc.current_revision and doc.parent and
            doc.parent.current_revision):
            # This is a translation but its current_revision is None
            # and OK to fall back to parent (parent is approved).
            fallback_reason = 'translation_not_approved'
        elif not doc.current_revision:
            # No current_revision, no parent with current revision, so
            # nothing to show.
            fallback_reason = 'no_content'
    except Document.DoesNotExist:
        # Look in default language:
        doc = get_object_or_404(Document,
                                locale=settings.WIKI_DEFAULT_LANGUAGE,
                                slug=document_slug)
        # If there's a translation to the requested locale, take it:
        translation = doc.translated_to(request.locale)
        if translation:
            url = translation.get_absolute_url()
            url = urlparams(url, query_dict=request.GET)
            return HttpResponseRedirect(url)
        elif doc.current_revision:
            # There is no translation
            # and OK to fall back to parent (parent is approved).
            fallback_reason = 'no_translation'

    # Obey explicit redirect pages:
    # Don't redirect on redirect=no (like Wikipedia), so we can link from a
    # redirected-to-page back to a "Redirected from..." link, so you can edit
    # the redirect.
    redirect_url = (None if request.GET.get('redirect') == 'no'
                    else doc.redirect_url(request.locale))
    if redirect_url:
        url = urlparams(redirect_url, query_dict=request.GET,
                        redirectslug=doc.slug, redirectlocale=doc.locale)
        return HttpResponseRedirect(url)

    # Get "redirected from" doc if we were redirected:
    redirect_slug = request.GET.get('redirectslug')
    redirect_locale = request.GET.get('redirectlocale')
    redirected_from = None
    if redirect_slug and redirect_locale:
        try:
            redirected_from = Document.objects.get(locale=redirect_locale,
                                                   slug=redirect_slug)
        except Document.DoesNotExist:
            pass

    related = find_related_documents(doc)

    contributors = doc.contributors.all()

    products = doc.get_products()
    if len(products) < 1:
        product = Product.objects.filter(visible=True)[0]
    else:
        product = products[0]

    topics = doc.get_topics()

    data = {'document': doc, 'redirected_from': redirected_from,
            'related': related, 'contributors': contributors,
            'fallback_reason': fallback_reason,
            'is_aoa_referral': request.GET.get('ref') == 'aoa',
            'topics': topics, 'product': product}
    data.update(SHOWFOR_DATA)
    return jingo.render(request, template, data)