Example #1
0
    def test_french(self):
        # Create English parent document
        en_d = DocumentFactory()
        ApprovedRevisionFactory(document=en_d)

        # Create the French document
        fr_d = DocumentFactory(parent=en_d, title='A doc', locale='fr')
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)

        # Also works when English exists
        DocumentFactory(title='A doc')
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)
Example #2
0
    def test_french(self):
        # Create English parent document
        en_d = DocumentFactory()
        ApprovedRevisionFactory(document=en_d)

        # Create the French document
        fr_d = DocumentFactory(parent=en_d, title="A doc", locale="fr")
        obj = get_object_fallback(Document, "A doc", "fr", "!")
        eq_(fr_d, obj)

        # Also works when English exists
        DocumentFactory(title="A doc")
        obj = get_object_fallback(Document, "A doc", "fr", "!")
        eq_(fr_d, obj)
Example #3
0
 def test_english(self):
     # Create the English document
     d = document(title='A doc')
     d.save()
     # Now it exists
     obj = get_object_fallback(Document, 'A doc', 'en-US', '!')
     eq_(d, obj)
Example #4
0
    def _hook_template(self, parser, space, title):
        """Handles Template:Template name, formatting the content using given
        args"""
        params = title.split('|')
        short_title = params.pop(0)
        template_title = 'Template:' + short_title

        message = _('The template "%s" does not exist or has no approved '
                    'revision.') % short_title
        template = get_object_fallback(Document, template_title,
                                       locale=self.locale, is_template=True)

        if not template or not template.current_revision:
            return message

        if template.id in parser.inclusions:
            return RECURSION_MESSAGE % template_title
        else:
            parser.inclusions.append(template.id)
        c = template.current_revision.content.rstrip()
        # Note: this completely ignores the allowed attributes passed to the
        # WikiParser.parse() method and defaults to ALLOWED_ATTRIBUTES.
        parsed = parser.parse(c, show_toc=False, attributes=ALLOWED_ATTRIBUTES,
                              locale=self.locale)
        parser.inclusions.pop()

        # Special case for inline templates
        if '\n' not in c:
            parsed = parsed.replace('<p>', '')
            parsed = parsed.replace('</p>', '')
        # Do some string formatting to replace parameters
        return _format_template_content(parsed, _build_template_params(params))
Example #5
0
 def test_from_french(self):
     # Create the English document
     d = DocumentFactory(title="A doc")
     d.save()
     # Returns English document for French
     obj = get_object_fallback(Document, "A doc", "fr", "!")
     eq_(d, obj)
Example #6
0
    def test_translated(self):
        """If a localization of the English fallback exists, use it."""

        en_d = DocumentFactory(title='A doc')
        ApprovedRevisionFactory(document=en_d)

        fr_d = DocumentFactory(parent=en_d, title='Une doc', locale='fr')

        # Without an approved revision, the en-US doc should be returned.
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(en_d, obj)

        # Approve a revision, then fr doc should be returned.
        ApprovedRevisionFactory(document=fr_d)
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(fr_d, obj)
Example #7
0
 def test_from_french(self):
     # Create the English document
     d = document(title='A doc')
     d.save()
     # Returns English document for French
     obj = get_object_fallback(Document, 'A doc', 'fr', '!')
     eq_(d, obj)
Example #8
0
    def test_translated(self):
        """If a localization of the English fallback exists, use it."""

        en_d = DocumentFactory(title="A doc")
        ApprovedRevisionFactory(document=en_d)

        fr_d = DocumentFactory(parent=en_d, title="Une doc", locale="fr")

        # Without an approved revision, the en-US doc should be returned.
        obj = get_object_fallback(Document, "A doc", "fr")
        eq_(en_d, obj)

        # Approve a revision, then fr doc should be returned.
        ApprovedRevisionFactory(document=fr_d)
        obj = get_object_fallback(Document, "A doc", "fr")
        eq_(fr_d, obj)
Example #9
0
 def test_from_french(self):
     # Create the English document
     d = document(title='A doc')
     d.save()
     # Returns English document for French
     obj = get_object_fallback(Document, 'A doc', 'fr', '!')
     eq_(d, obj)
Example #10
0
    def _hook_template(self, parser, space, title):
        """Handles Template:Template name, formatting the content using given
        args"""
        params = title.split('|')
        short_title = params.pop(0)
        template_title = 'Template:' + short_title

        message = _('The template "%s" does not exist or has no approved '
                    'revision.') % short_title
        template = get_object_fallback(Document, template_title,
                                       locale=self.locale, is_template=True)

        if not template or not template.current_revision:
            return message

        if template.id in parser.inclusions:
            return RECURSION_MESSAGE % template_title
        else:
            parser.inclusions.append(template.id)
        c = template.current_revision.content.rstrip()
        # Note: this completely ignores the allowed attributes passed to the
        # WikiParser.parse() method and defaults to ALLOWED_ATTRIBUTES.
        parsed = parser.parse(c, show_toc=False, attributes=ALLOWED_ATTRIBUTES,
                              locale=self.locale)
        parser.inclusions.pop()

        # Special case for inline templates
        if '\n' not in c:
            parsed = parsed.replace('<p>', '')
            parsed = parsed.replace('</p>', '')
        # Do some string formatting to replace parameters
        return _format_template_content(parsed, _build_template_params(params))
Example #11
0
 def test_english(self):
     # Create the English document
     d = document(title='A doc')
     d.save()
     # Now it exists
     obj = get_object_fallback(Document, 'A doc', 'en-US', '!')
     eq_(d, obj)
Example #12
0
    def _hook_include(self, parser, space, name):
        """Record an include link between documents, and then call super()."""
        include = get_object_fallback(Document, name, locale=self.locale)

        if include:
            self.current_doc.add_link_to(include, "include")

        return super(WhatLinksHereParser, self)._hook_include(parser, space, name)
Example #13
0
    def _hook_include(self, parser, space, name):
        """Record an include link between documents, and then call super()."""
        include = get_object_fallback(Document, name, locale=self.locale)

        if include:
            self.current_doc.add_link_to(include, "include")

        return super(WhatLinksHereParser, self)._hook_include(parser, space, name)
Example #14
0
    def test_french(self):
        # Create English parent document
        en_d = document()
        en_d.save()
        en_r = revision(document=en_d, is_approved=True)
        en_r.save()

        # Create the French document
        fr_d = document(parent=en_d, title='A doc', locale='fr')
        fr_d.save()
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)

        # Also works when English exists
        d = document(title='A doc')
        d.save()
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)
Example #15
0
    def test_redirect(self):
        """Assert get_object_fallback follows wiki redirects."""
        target_rev = ApprovedRevisionFactory(document__title='target')
        translated_target_rev = ApprovedRevisionFactory(
            document__parent=target_rev.document,
            document__locale='de')
        ApprovedRevisionFactory(document__title='redirect', content='REDIRECT [[target]]')

        eq_(translated_target_rev.document, get_object_fallback(Document, 'redirect', 'de'))
Example #16
0
    def _hook_image_tag(self, parser, space, name):
        """Record an image is included in a document, then call super()."""
        title = name.split("|")[0]
        image = get_object_fallback(Image, title, self.locale)

        if image:
            self.current_doc.add_image(image)

        return super(WhatLinksHereParser, self)._hook_image_tag(parser, space, name)
Example #17
0
    def test_french(self):
        # Create English parent document
        en_d = document()
        en_d.save()
        en_r = revision(document=en_d, is_approved=True)
        en_r.save()

        # Create the French document
        fr_d = document(parent=en_d, title='A doc', locale='fr')
        fr_d.save()
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)

        # Also works when English exists
        d = document(title='A doc')
        d.save()
        obj = get_object_fallback(Document, 'A doc', 'fr', '!')
        eq_(fr_d, obj)
Example #18
0
    def _hook_image_tag(self, parser, space, name):
        """Record an image is included in a document, then call super()."""
        title = name.split('|')[0]
        image = get_object_fallback(Image, title, self.locale)

        if image:
            self.current_doc.add_image(image)

        return (super(WhatLinksHereParser, self)
                ._hook_image_tag(parser, space, name))
Example #19
0
    def _hook_template(self, parser, space, name):
        """Record a template link between documents, and then call super()."""

        params = name.split("|")
        template = get_object_fallback(Document, "Template:" + params.pop(0), locale=self.locale, is_template=True)

        if template:
            self.current_doc.add_link_to(template, "template")

        return super(WhatLinksHereParser, self)._hook_template(parser, space, name)
Example #20
0
    def _hook_internal_link(self, parser, space, name):
        """Records links between documents, and then calls super()."""

        title = name.split("|")[0]
        locale = self.current_doc.locale

        linked_doc = get_object_fallback(Document, title, locale)
        if linked_doc is not None:
            self.current_doc.add_link_to(linked_doc, "link")

        return super(WhatLinksHereParser, self)._hook_internal_link(parser, space, name)
Example #21
0
    def test_translated(self):
        """If a localization of the English fallback exists, use it."""

        en_d = document(title='A doc')
        en_d.save()
        en_r = revision(document=en_d, is_approved=True)
        en_r.save()

        fr_d = document(parent=en_d, title='Une doc', locale='fr')
        fr_d.save()

        # Without an approved revision, the en-US doc should be returned.
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(en_d, obj)

        # Approve a revision, then fr doc should be returned.
        fr_r = revision(document=fr_d, is_approved=True)
        fr_r.save()
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(fr_d, obj)
Example #22
0
    def _hook_internal_link(self, parser, space, name):
        """Records links between documents, and then calls super()."""

        title = name.split("|")[0]
        locale = self.current_doc.locale

        linked_doc = get_object_fallback(Document, title, locale)
        if linked_doc is not None:
            self.current_doc.add_link_to(linked_doc, "link")

        return super(WhatLinksHereParser, self)._hook_internal_link(parser, space, name)
Example #23
0
    def test_translated(self):
        """If a localization of the English fallback exists, use it."""

        en_d = document(title='A doc')
        en_d.save()
        en_r = revision(document=en_d, is_approved=True)
        en_r.save()

        fr_d = document(parent=en_d, title='Une doc', locale='fr')
        fr_d.save()

        # Without an approved revision, the en-US doc should be returned.
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(en_d, obj)

        # Approve a revision, then fr doc should be returned.
        fr_r = revision(document=fr_d, is_approved=True)
        fr_r.save()
        obj = get_object_fallback(Document, 'A doc', 'fr')
        eq_(fr_d, obj)
Example #24
0
    def test_redirect(self):
        """Assert get_object_fallback follows wiki redirects."""
        target_rev = ApprovedRevisionFactory(document__title="target")
        translated_target_rev = ApprovedRevisionFactory(
            document__parent=target_rev.document, document__locale="de")
        ApprovedRevisionFactory(document__title="redirect",
                                content="REDIRECT [[target]]")

        eq_(
            translated_target_rev.document,
            get_object_fallback(Document, "redirect", "de"),
        )
Example #25
0
    def _hook_template(self, parser, space, name):
        """Record a template link between documents, and then call super()."""

        params = name.split('|')
        template = get_object_fallback(Document, 'Template:' + params[0],
                                       locale=self.locale, is_template=True)

        if template:
            self.current_doc.add_link_to(template, 'template')

        return (super(WhatLinksHereParser, self)
                ._hook_template(parser, space, name))
Example #26
0
def home(request):
    """The home page."""
    if request.MOBILE:
        return redirect_to(request, 'products', permanent=False)

    products = Product.objects.filter(visible=True)
    moz_news = get_object_fallback(
        Document, MOZILLA_NEWS_DOC, request.LANGUAGE_CODE)

    return render(request, 'landings/home.html', {
        'products': products,
        'moz_news': moz_news})
Example #27
0
def home(request):
    """Community hub landing page."""

    community_news = get_object_fallback(
        Document, COMMUNITY_NEWS_DOC, request.LANGUAGE_CODE)

    return render(request, 'community/index.html', {
        'community_news': community_news,
        'top_contributors_aoa': top_contributors_aoa(),
        'top_contributors_kb': top_contributors_kb(),
        'top_contributors_l10n': top_contributors_l10n(),
        'top_contributors_questions': top_contributors_questions(),
    })
Example #28
0
def home(request):
    """The home page."""
    if request.MOBILE:
        return redirect_to(request, 'products', permanent=False)

    products = Product.objects.filter(visible=True)
    moz_news = get_object_fallback(Document, MOZILLA_NEWS_DOC,
                                   request.LANGUAGE_CODE)

    return render(request, 'landings/home.html', {
        'products': products,
        'moz_news': moz_news
    })
Example #29
0
def home(request):
    """Community hub landing page."""

    community_news = get_object_fallback(
        Document, COMMUNITY_NEWS_DOC, request.LANGUAGE_CODE)
    locale = _validate_locale(request.GET.get('locale'))
    product = request.GET.get('product')
    if product:
        product = get_object_or_404(Product, slug=product)

    # Get the 5 most recent Community Discussion threads.
    recent_threads = Thread.objects.filter(forum__slug='contributors')[:5]

    data = {
        'community_news': community_news,
        'locale': locale,
        'product': product,
        'products': Product.objects.filter(visible=True),
        'threads': recent_threads,
    }

    if locale:
        data['top_contributors_aoa'], _ = top_contributors_aoa(locale=locale)

        # If the locale is en-US we should top KB contributors, else we show
        # top l10n contributors for that locale
        if locale == settings.WIKI_DEFAULT_LANGUAGE:
            data['top_contributors_kb'], _ = top_contributors_kb(
                product=product)
        else:
            data['top_contributors_l10n'], _ = top_contributors_l10n(
                locale=locale, product=product)

        # If the locale is enabled for the Support Forum, show the top
        # contributors for that locale
        if locale in QuestionLocale.objects.locales_list():
            data['top_contributors_questions'], _ = top_contributors_questions(
                locale=locale, product=product)
    else:
        # If no locale is specified, we show overall top contributors
        # across locales.
        data['top_contributors_aoa'], _ = top_contributors_aoa()
        data['top_contributors_kb'], _ = top_contributors_kb(product=product)
        data['top_contributors_l10n'], _ = top_contributors_l10n(
            product=product)
        data['top_contributors_questions'], _ = top_contributors_questions(
            product=product)

    return render(request, 'community/index.html', data)
Example #30
0
def home(request):
    """Community hub landing page."""

    community_news = get_object_fallback(Document, COMMUNITY_NEWS_DOC,
                                         request.LANGUAGE_CODE)
    locale = _validate_locale(request.GET.get("locale"))
    product = request.GET.get("product")
    if product:
        product = get_object_or_404(Product, slug=product)

    # Get the 5 most recent Community Discussion threads.
    recent_threads = Thread.objects.filter(forum__slug="contributors")[:5]

    data = {
        "community_news": community_news,
        "locale": locale,
        "product": product,
        "products": Product.objects.filter(visible=True),
        "threads": recent_threads,
    }

    if locale:
        data["top_contributors_aoa"], _ = top_contributors_aoa(locale=locale)

        # If the locale is en-US we should top KB contributors, else we show
        # top l10n contributors for that locale
        if locale == settings.WIKI_DEFAULT_LANGUAGE:
            data["top_contributors_kb"], _ = top_contributors_kb(
                product=product)
        else:
            data["top_contributors_l10n"], _ = top_contributors_l10n(
                locale=locale, product=product)

        # If the locale is enabled for the Support Forum, show the top
        # contributors for that locale
        if locale in QuestionLocale.objects.locales_list():
            data["top_contributors_questions"], _ = top_contributors_questions(
                locale=locale, product=product)
    else:
        # If no locale is specified, we show overall top contributors
        # across locales.
        data["top_contributors_aoa"], _ = top_contributors_aoa()
        data["top_contributors_kb"], _ = top_contributors_kb(product=product)
        data["top_contributors_l10n"], _ = top_contributors_l10n(
            product=product)
        data["top_contributors_questions"], _ = top_contributors_questions(
            product=product)

    return render(request, "community/index.html", data)
Example #31
0
    def _hook_include(self, parser, space, title):
        """Returns the document's parsed content."""
        message = _('The document "%s" does not exist.') % title
        include = get_object_fallback(Document, title, locale=self.locale)
        if not include or not include.current_revision:
            return message

        if include.id in parser.inclusions:
            return RECURSION_MESSAGE % title
        else:
            parser.inclusions.append(include.id)
        ret = parser.parse(include.current_revision.content, show_toc=False, locale=self.locale)
        parser.inclusions.pop()

        return ret
Example #32
0
    def test_redirect_translations_only(self):
        """Make sure get_object_fallback doesn't follow redirects when working
        purely in the default language.

        That would make it hard to navigate to redirects (to edit them, for
        example).

        """
        ApprovedRevisionFactory(document__title='target', content='O hai.')
        redirect_rev = ApprovedRevisionFactory(
            document__title='redirect',
            content='REDIRECT [[target]]')
        eq_(redirect_rev.document,
            get_object_fallback(Document, 'redirect',
                                redirect_rev.document.locale))
Example #33
0
    def test_redirect(self):
        """Assert get_object_fallback follows wiki redirects."""
        target_rev = revision(document=document(title='target', save=True),
                              is_approved=True,
                              save=True)
        translated_target_rev = revision(document=document(
            parent=target_rev.document, locale='de', save=True),
                                         is_approved=True,
                                         save=True)
        revision(document=document(title='redirect', save=True),
                 content='REDIRECT [[target]]',
                 is_approved=True).save()

        eq_(translated_target_rev.document,
            get_object_fallback(Document, 'redirect', 'de'))
Example #34
0
    def _hook_include(self, parser, space, title):
        """Returns the document's parsed content."""
        message = _('The document "%s" does not exist.') % title
        include = get_object_fallback(Document, title, locale=self.locale)
        if not include or not include.current_revision:
            return message

        if include.id in parser.inclusions:
            return RECURSION_MESSAGE % title
        else:
            parser.inclusions.append(include.id)
        ret = parser.parse(include.current_revision.content, show_toc=False, locale=self.locale)
        parser.inclusions.pop()

        return ret
Example #35
0
def home(request):
    """Community hub landing page."""

    community_news = get_object_fallback(Document, COMMUNITY_NEWS_DOC,
                                         request.LANGUAGE_CODE)
    locale = _validate_locale(request.GET.get('locale'))
    product = request.GET.get('product')
    if product:
        product = get_object_or_404(Product, slug=product)

    # Get the 5 most recent Community Discussion threads.
    recent_threads = Thread.objects.filter(forum__slug='contributors')[:5]

    data = {
        'community_news': community_news,
        'locale': locale,
        'product': product,
        'products': Product.objects.filter(visible=True),
        'threads': recent_threads,
    }

    if locale:
        data['top_contributors_aoa'] = top_contributors_aoa(locale=locale)

        # If the locale is en-US we should top KB contributors, else we show
        # top l10n contributors for that locale
        if locale == settings.WIKI_DEFAULT_LANGUAGE:
            data['top_contributors_kb'] = top_contributors_kb(product=product)
        else:
            data['top_contributors_l10n'] = top_contributors_l10n(
                locale=locale, product=product)

        # If the locale is enabled for the Support Forum, show the top
        # contributors for that locale
        if locale in settings.AAQ_LANGUAGES:
            data['top_contributors_questions'] = top_contributors_questions(
                locale=locale, product=product)
    else:
        # If no locale is specified, we show overall top contributors
        # across locales.
        data['top_contributors_aoa'] = top_contributors_aoa()
        data['top_contributors_kb'] = top_contributors_kb(product=product)
        data['top_contributors_l10n'] = top_contributors_l10n(product=product)
        data['top_contributors_questions'] = top_contributors_questions(
            product=product)

    return render(request, 'community/index.html', data)
Example #36
0
    def test_redirect_translations_only(self):
        """Make sure get_object_fallback doesn't follow redirects when working
        purely in the default language.

        That would make it hard to navigate to redirects (to edit them, for
        example).

        """
        revision(document=document(title='target', save=True),
                              content='O hai.',
                              is_approved=True).save()
        redirect_rev = revision(document=document(title='redirect', save=True),
                                content='REDIRECT [[target]]',
                                is_approved=True,
                                save=True)
        eq_(redirect_rev.document,
            get_object_fallback(Document, 'redirect',
                                redirect_rev.document.locale))
Example #37
0
    def test_redirect(self):
        """Assert get_object_fallback follows wiki redirects."""
        target_rev = revision(
            document=document(title='target', save=True),
            is_approved=True,
            save=True)
        translated_target_rev = revision(
            document=document(parent=target_rev.document, locale='de',
                              save=True),
            is_approved=True,
            save=True)
        revision(
            document=document(title='redirect', save=True),
            content='REDIRECT [[target]]',
            is_approved=True).save()

        eq_(translated_target_rev.document,
            get_object_fallback(Document, 'redirect', 'de'))
Example #38
0
    def test_redirect_translations_only(self):
        """Make sure get_object_fallback doesn't follow redirects when working
        purely in the default language.

        That would make it hard to navigate to redirects (to edit them, for
        example).

        """
        revision(document=document(title='target', save=True),
                 content='O hai.',
                 is_approved=True).save()
        redirect_rev = revision(document=document(title='redirect', save=True),
                                content='REDIRECT [[target]]',
                                is_approved=True,
                                save=True)
        eq_(
            redirect_rev.document,
            get_object_fallback(Document, 'redirect',
                                redirect_rev.document.locale))
Example #39
0
 def test_empty(self):
     """get_object_fallback returns message when no objects."""
     # English does not exist
     obj = get_object_fallback(Document, 'A doc', 'en-US', '!')
     eq_('!', obj)
Example #40
0
 def test_empty(self):
     """get_object_fallback returns message when no objects."""
     # English does not exist
     obj = get_object_fallback(Document, 'A doc', 'en-US', '!')
     eq_('!', obj)
Example #41
0
 def test_empty(self):
     """get_object_fallback returns message when no objects."""
     # English does not exist
     obj = get_object_fallback(Document, "A doc", "en-US", "!")
     eq_("!", obj)
Example #42
0
 def test_english(self):
     # Create the English document
     d = DocumentFactory(title="A doc")
     # Now it exists
     obj = get_object_fallback(Document, "A doc", "en-US", "!")
     eq_(d, obj)