Beispiel #1
0
 def product(self):
     """Return the product this question is about or an empty mapping if
     unknown."""
     md = self.metadata
     if 'product' in md:
         return products.get(md['product'], {})
     return {}
Beispiel #2
0
 def product(self):
     """Return the product this question is about or an empty mapping if
     unknown."""
     md = self.metadata
     if 'product' in md:
         return products.get(md['product'], {})
     return {}
Beispiel #3
0
def aaq(request, product_key=None, category_key=None, showform=False,
        template=None, step=0):
    """Ask a new question."""

    if product_key is None:
        product_key = request.GET.get('product')
        if request.MOBILE and product_key is None:
            product_key = 'desktop'
    product = products.get(product_key)
    if product_key and not product:
        raise Http404

    if category_key is None:
        category_key = request.GET.get('category')

    if product and category_key:
        category = product['categories'].get(category_key)
        if not category:
            # If we get an invalid category, redirect to previous step.
            return HttpResponseRedirect(
                reverse('questions.aaq_step2', args=[product_key]))
        deadend = category.get('deadend', False)
        topic = category.get('topic')
        if topic:
            html = None
            articles, fallback = documents_for(
                locale=settings.WIKI_DEFAULT_LANGUAGE,  # en-US only for now.
                products=Product.objects.filter(
                    slug__in=product.get('products')),
                topics=[Topic.objects.get(slug=topic)])
        else:
            html = category.get('html')
            articles = category.get('articles')
    else:
        category = None
        deadend = product.get('deadend', False) if product else False
        html = product.get('html') if product else None
        articles = None
        if product:
            # User is on the select category step
            statsd.incr('questions.aaq.select-category')
        else:
            # User is on the select product step
            statsd.incr('questions.aaq.select-product')

    login_t = ('questions/mobile/new_question_login.html' if request.MOBILE
               else 'questions/new_question_login.html')
    if request.method == 'GET':
        search = request.GET.get('search', '')
        if search:
            results = _search_suggestions(
                request,
                search,
                locale_or_default(request.locale),
                product.get('tags'),
                product.get('products'))
            tried_search = True
        else:
            results = []
            tried_search = False
            if category:
                # User is on the "Ask This" step
                statsd.incr('questions.aaq.search-form')

        if showform or request.GET.get('showform'):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                # User is on the login or register Step
                statsd.incr('questions.aaq.login-or-register')
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(request, login_t,
                                    {'product': product, 'category': category,
                                     'title': search,
                                     'register_form': register_form,
                                     'login_form': login_form})
            form = NewQuestionForm(product=product,
                                   category=category,
                                   initial={'title': search})
            # User is on the question details step
            statsd.incr('questions.aaq.details-form')
        else:
            form = None
            if search:
                # User is on the article and questions suggestions step
                statsd.incr('questions.aaq.suggestions')

        return jingo.render(request, template,
                            {'form': form,
                             'results': results,
                             'tried_search': tried_search,
                             'products': products,
                             'current_product': product,
                             'current_category': category,
                             'current_html': html,
                             'current_articles': articles,
                             'current_step': step,
                             'deadend': deadend,
                             'host': Site.objects.get_current().domain})

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get('login'):
            login_form = handle_login(request, only_active=False)
            statsd.incr('questions.user.login')
            register_form = RegisterForm()
        elif request.POST.get('register'):
            login_form = AuthenticationForm()
            email_template = 'questions/email/confirm_question.ltxt'
            email_subject = _('Please confirm your Firefox Help question')
            email_data = request.GET.get('search')
            register_form = handle_register(request, email_template,
                                            email_subject, email_data)
            if register_form.is_valid():  # Now try to log in.
                user = auth.authenticate(username=request.POST.get('username'),
                                         password=request.POST.get('password'))
                auth.login(request, user)
                statsd.incr('questions.user.register')
        else:
            # L10n: This shouldn't happen unless people tamper with POST data.
            message = _lazy('Request type not recognized.')
            return jingo.render(request, 'handlers/400.html',
                            {'message': message}, status=400)
        if request.user.is_authenticated():
            # Redirect to GET the current URL replacing the step parameter.
            # This is also required for the csrf middleware to set the auth'd
            # tokens appropriately.
            url = urlparams(request.get_full_path(), step='aaq-question')
            return HttpResponseRedirect(url)
        else:
            return jingo.render(request, login_t,
                                {'product': product, 'category': category,
                                 'title': request.POST.get('title'),
                                 'register_form': register_form,
                                 'login_form': login_form})

    form = NewQuestionForm(product=product, category=category,
                           data=request.POST)

    if form.is_valid():
        question = Question(creator=request.user,
                            title=form.cleaned_data['title'],
                            content=form.cleaned_data['content'])
        question.save()
        # User successfully submitted a new question
        statsd.incr('questions.new')
        question.add_metadata(**form.cleaned_metadata)
        if product:
            # TODO: This add_metadata call should be removed once we are
            # fully IA-driven (sync isn't special case anymore).
            question.add_metadata(product=product['key'])

            for p in Product.objects.filter(slug__in=product.get('products')):
                question.products.add(p)

            if category:
                # TODO: This add_metadata call should be removed once we are
                # fully IA-driven (sync isn't special case anymore).
                question.add_metadata(category=category['key'])

                t = category.get('topic')
                if t:
                    question.topics.add(Topic.objects.get(slug=t))

        # The first time a question is saved, automatically apply some tags:
        question.auto_tag()

        # Submitting the question counts as a vote
        question_vote(request, question.id)

        if request.user.is_active:
            messages.add_message(request, messages.SUCCESS,
                _('Done! Your question is now posted on the Mozilla community '
                  'support forum.'))
            url = reverse('questions.answers',
                          kwargs={'question_id': question.id})
            return HttpResponseRedirect(url)

        return HttpResponseRedirect(reverse('questions.aaq_confirm'))

    statsd.incr('questions.aaq.details-form-error')
    return jingo.render(request, template,
                        {'form': form, 'products': products,
                         'current_product': product,
                         'current_category': category,
                         'current_articles': articles})
Beispiel #4
0
def new_question(request, template=None):
    """Ask a new question."""

    product_key = request.GET.get('product')
    product = products.get(product_key)
    if product_key and not product:
        raise Http404
    category_key = request.GET.get('category')
    if product and category_key:
        category = product['categories'].get(category_key)
        if not category:
            raise Http404
        deadend = category.get('deadend', False)
        html = category.get('html')
        articles = category.get('articles')
    else:
        category = None
        deadend = product.get('deadend', False) if product else False
        html = product.get('html') if product else None
        articles = None

    login_t = ('questions/mobile/new_question_login.html' if request.MOBILE
               else 'questions/new_question_login.html')
    if request.method == 'GET':
        search = request.GET.get('search', '')
        if search:
            try:
                results = _search_suggestions(
                    search, locale_or_default(request.locale))
            except SearchError:
                # Just quietly advance the user to the next step.
                results = []
            tried_search = True
        else:
            results = []
            tried_search = False

        if request.GET.get('showform'):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(request, login_t,
                                    {'product': product, 'category': category,
                                     'title': search,
                                     'register_form': register_form,
                                     'login_form': login_form})
            form = NewQuestionForm(product=product,
                                   category=category,
                                   initial={'title': search})
        else:
            form = None

        return jingo.render(request, template,
                            {'form': form,
                             'results': results,
                             'tried_search': tried_search,
                             'products': products,
                             'current_product': product,
                             'current_category': category,
                             'current_html': html,
                             'current_articles': articles,
                             'deadend': deadend,
                             'host': Site.objects.get_current().domain})

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get('login'):
            login_form = handle_login(request, only_active=False)
            statsd.incr('questions.user.login')
            register_form = RegisterForm()
        elif request.POST.get('register'):
            login_form = AuthenticationForm()
            email_template = 'questions/email/confirm_question.ltxt'
            email_subject = _('Please confirm your Firefox Help question')
            email_data = request.GET.get('search')
            register_form = handle_register(request, email_template,
                                            email_subject, email_data)
            if register_form.is_valid():  # Now try to log in.
                user = auth.authenticate(username=request.POST.get('username'),
                                         password=request.POST.get('password'))
                auth.login(request, user)
                statsd.incr('questions.user.register')
        else:
            # L10n: This shouldn't happen unless people tamper with POST data.
            message = _lazy('Request type not recognized.')
            return jingo.render(request, 'handlers/400.html',
                            {'message': message}, status=400)
        if request.user.is_authenticated():
            # Redirect to GET the current URL.
            # This is required for the csrf middleware to set the auth'd tokens
            # appropriately.
            return HttpResponseRedirect(request.get_full_path())
        else:
            return jingo.render(request, login_t,
                                {'product': product, 'category': category,
                                 'title': request.POST.get('title'),
                                 'register_form': register_form,
                                 'login_form': login_form})

    form = NewQuestionForm(product=product, category=category,
                           data=request.POST)

    if form.is_valid():
        question = Question(creator=request.user,
                            title=form.cleaned_data['title'],
                            content=form.cleaned_data['content'])
        question.save()
        statsd.incr('questions.new')
        question.add_metadata(**form.cleaned_metadata)
        if product:
            question.add_metadata(product=product['key'])
            if category:
                question.add_metadata(category=category['key'])

        # The first time a question is saved, automatically apply some tags:
        question.auto_tag()

        # Submitting the question counts as a vote
        question_vote(request, question.id)

        if request.user.is_active:
            messages.add_message(request, messages.SUCCESS,
                _('Thanks! Your question has been posted. See it below.'))
            url = reverse('questions.answers',
                          kwargs={'question_id': question.id})
            return HttpResponseRedirect(url)

        auth.logout(request)
        statsd.incr('questions.user.logout')
        confirm_t = ('questions/mobile/confirm_email.html' if request.MOBILE
                     else 'questions/confirm_email.html')
        return jingo.render(request, confirm_t,
                            {'question': question})

    return jingo.render(request, template,
                        {'form': form, 'products': products,
                         'current_product': product,
                         'current_category': category,
                         'current_articles': articles})
Beispiel #5
0
def new_question(request):
    """Ask a new question."""

    product_key = request.GET.get('product')
    product = products.get(product_key)
    if product_key and not product:
        raise Http404
    category_key = request.GET.get('category')
    if product and category_key:
        category = product['categories'].get(category_key)
        if not category:
            raise Http404
        deadend = category.get('deadend', False)
        html = category.get('html')
        articles = category.get('articles')
    else:
        category = None
        deadend = product.get('deadend', False) if product else False
        html = product.get('html') if product else None
        articles = None

    if request.method == 'GET':
        search = request.GET.get('search', '')
        if search:
            try:
                search_results = _search_suggestions(
                                 search, locale_or_default(request.locale))
            except SearchError:
                # Just quietly advance the user to the next step.
                search_results = []
            tried_search = True
        else:
            search_results = []
            tried_search = False

        if request.GET.get('showform'):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(request,
                                    'questions/new_question_login.html',
                                    {'product': product, 'category': category,
                                     'title': search,
                                     'register_form': register_form,
                                     'login_form': login_form})
            form = NewQuestionForm(product=product,
                                   category=category,
                                   initial={'title': search})
        else:
            form = None

        return jingo.render(request, 'questions/new_question.html',
                            {'form': form, 'search_results': search_results,
                             'tried_search': tried_search,
                             'products': products,
                             'current_product': product,
                             'current_category': category,
                             'current_html': html,
                             'current_articles': articles,
                             'deadend': deadend,
                             'host': Site.objects.get_current().domain})

    # Handle the form post.
    just_logged_in = False  # Used below for whether to pre-load Question form.
    if not request.user.is_authenticated():
        type = request.POST.get('type')
        if type not in ('login', 'register'):
            # L10n: This shouldn't happen unless people tamper with POST data
            message = _lazy('Request type not recognized.')
            return jingo.render(request, 'handlers/400.html',
                            {'message': message}, status=400)
        if type == 'login':
            login_form = handle_login(request, only_active=False)
            register_form = RegisterForm()
        else:  # must be 'register'
            login_form = AuthenticationForm()
            register_form = handle_register(request)
            if register_form.is_valid():  # now try to log in
                user = auth.authenticate(username=request.POST.get('username'),
                                         password=request.POST.get('password'))
                auth.login(request, user)
        if not request.user.is_authenticated():
            return jingo.render(request,
                                'questions/new_question_login.html',
                                {'product': product, 'category': category,
                                 'title': request.POST.get('title'),
                                 'register_form': register_form,
                                 'login_form': login_form})
        else:
            just_logged_in = True

    if just_logged_in:
        form = NewQuestionForm(product=product,
                               category=category,
                               initial={'title': request.GET.get('search')})
    else:
        form = NewQuestionForm(product=product, category=category,
                               data=request.POST)

    if form.is_valid():
        question = Question(creator=request.user,
                            title=form.cleaned_data['title'],
                            content=form.cleaned_data['content'])
        question.save()
        question.add_metadata(**form.cleaned_metadata)
        if product:
            question.add_metadata(product=product['key'])
            if category:
                question.add_metadata(category=category['key'])

        # The first time a question is saved, automatically apply some tags:
        question.auto_tag()

        # Submitting the question counts as a vote
        question_vote(request, question.id)

        if request.user.is_active:
            url = reverse('questions.answers',
                          kwargs={'question_id': question.id})
            return HttpResponseRedirect(urlparams(url, new=1))

        auth.logout(request)
        return jingo.render(request, 'questions/confirm_email.html',
                            {'question': question})

    return jingo.render(request, 'questions/new_question.html',
                        {'form': form, 'products': products,
                         'current_product': product,
                         'current_category': category,
                         'current_articles': articles})
Beispiel #6
0
def new_question(request, template=None):
    """Ask a new question."""

    product_key = request.GET.get('product')
    product = products.get(product_key)
    if product_key and not product:
        raise Http404
    category_key = request.GET.get('category')
    if product and category_key:
        category = product['categories'].get(category_key)
        if not category:
            raise Http404
        deadend = category.get('deadend', False)
        html = category.get('html')
        articles = category.get('articles')
    else:
        category = None
        deadend = product.get('deadend', False) if product else False
        html = product.get('html') if product else None
        articles = None

    login_t = ('questions/mobile/new_question_login.html'
               if request.MOBILE else 'questions/new_question_login.html')
    if request.method == 'GET':
        search = request.GET.get('search', '')
        if search:
            try:
                search_results = _search_suggestions(
                    search, locale_or_default(request.locale))
            except SearchError:
                # Just quietly advance the user to the next step.
                search_results = []
            tried_search = True
        else:
            search_results = []
            tried_search = False

        if request.GET.get('showform'):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(
                    request, login_t, {
                        'product': product,
                        'category': category,
                        'title': search,
                        'register_form': register_form,
                        'login_form': login_form
                    })
            form = NewQuestionForm(product=product,
                                   category=category,
                                   initial={'title': search})
        else:
            form = None

        return jingo.render(
            request, template, {
                'form': form,
                'search_results': search_results,
                'tried_search': tried_search,
                'products': products,
                'current_product': product,
                'current_category': category,
                'current_html': html,
                'current_articles': articles,
                'deadend': deadend,
                'host': Site.objects.get_current().domain
            })

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get('login'):
            login_form = handle_login(request, only_active=False)
            register_form = RegisterForm()
        elif request.POST.get('register'):
            login_form = AuthenticationForm()
            email_template = 'questions/email/confirm_question.ltxt'
            email_subject = _('Please confirm your Firefox Help question')
            email_data = request.GET.get('search')
            register_form = handle_register(request, email_template,
                                            email_subject, email_data)
            if register_form.is_valid():  # now try to log in
                user = auth.authenticate(username=request.POST.get('username'),
                                         password=request.POST.get('password'))
                auth.login(request, user)
        else:
            # L10n: This shouldn't happen unless people tamper with POST data
            message = _lazy('Request type not recognized.')
            return jingo.render(request,
                                'handlers/400.html', {'message': message},
                                status=400)
        if request.user.is_authenticated():
            # Redirect to GET the current URL.
            # This is required for the csrf middleware to set the auth'd tokens
            # appropriately.
            return HttpResponseRedirect(request.get_full_path())
        else:
            return jingo.render(
                request, login_t, {
                    'product': product,
                    'category': category,
                    'title': request.POST.get('title'),
                    'register_form': register_form,
                    'login_form': login_form
                })

    form = NewQuestionForm(product=product,
                           category=category,
                           data=request.POST)

    if form.is_valid():
        question = Question(creator=request.user,
                            title=form.cleaned_data['title'],
                            content=form.cleaned_data['content'])
        question.save()
        question.add_metadata(**form.cleaned_metadata)
        if product:
            question.add_metadata(product=product['key'])
            if category:
                question.add_metadata(category=category['key'])

        # The first time a question is saved, automatically apply some tags:
        question.auto_tag()

        # Submitting the question counts as a vote
        question_vote(request, question.id)

        if request.user.is_active:
            messages.add_message(
                request, messages.SUCCESS,
                _('Thanks! Your question has been posted. See it below.'))
            url = reverse('questions.answers',
                          kwargs={'question_id': question.id})
            return HttpResponseRedirect(url)

        auth.logout(request)
        confirm_t = ('questions/mobile/confirm_email.html'
                     if request.MOBILE else 'questions/confirm_email.html')
        return jingo.render(request, confirm_t, {'question': question})

    return jingo.render(
        request, template, {
            'form': form,
            'products': products,
            'current_product': product,
            'current_category': category,
            'current_articles': articles
        })
Beispiel #7
0
def new_question(request, template=None):
    """Ask a new question."""

    product_key = request.GET.get("product")
    product = products.get(product_key)
    if product_key and not product:
        raise Http404
    category_key = request.GET.get("category")
    if product and category_key:
        category = product["categories"].get(category_key)
        if not category:
            raise Http404
        deadend = category.get("deadend", False)
        html = category.get("html")
        articles = category.get("articles")
    else:
        category = None
        deadend = product.get("deadend", False) if product else False
        html = product.get("html") if product else None
        articles = None
        if product:
            # User is on the select category step
            statsd.incr("questions.aaq.select-category")
        else:
            # User is on the select product step
            statsd.incr("questions.aaq.select-product")

    login_t = "questions/mobile/new_question_login.html" if request.MOBILE else "questions/new_question_login.html"
    if request.method == "GET":
        search = request.GET.get("search", "")
        if search:
            try:
                results = _search_suggestions(search, locale_or_default(request.locale), product.get("tags"))
            except SearchError:
                # Just quietly advance the user to the next step.
                results = []
            tried_search = True
        else:
            results = []
            tried_search = False
            if category:
                # User is on the "Ask This" step
                statsd.incr("questions.aaq.search-form")

        if request.GET.get("showform"):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                # User is on the login or register Step
                statsd.incr("questions.aaq.login-or-register")
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(
                    request,
                    login_t,
                    {
                        "product": product,
                        "category": category,
                        "title": search,
                        "register_form": register_form,
                        "login_form": login_form,
                    },
                )
            form = NewQuestionForm(product=product, category=category, initial={"title": search})
            # User is on the question details step
            statsd.incr("questions.aaq.details-form")
        else:
            form = None
            if search:
                # User is on the article and questions suggestions step
                statsd.incr("questions.aaq.suggestions")

        return jingo.render(
            request,
            template,
            {
                "form": form,
                "results": results,
                "tried_search": tried_search,
                "products": products,
                "current_product": product,
                "current_category": category,
                "current_html": html,
                "current_articles": articles,
                "deadend": deadend,
                "host": Site.objects.get_current().domain,
            },
        )

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get("login"):
            login_form = handle_login(request, only_active=False)
            statsd.incr("questions.user.login")
            register_form = RegisterForm()
        elif request.POST.get("register"):
            login_form = AuthenticationForm()
            email_template = "questions/email/confirm_question.ltxt"
            email_subject = _("Please confirm your Firefox Help question")
            email_data = request.GET.get("search")
            register_form = handle_register(request, email_template, email_subject, email_data)
            if register_form.is_valid():  # Now try to log in.
                user = auth.authenticate(username=request.POST.get("username"), password=request.POST.get("password"))
                auth.login(request, user)
                statsd.incr("questions.user.register")
        else:
            # L10n: This shouldn't happen unless people tamper with POST data.
            message = _lazy("Request type not recognized.")
            return jingo.render(request, "handlers/400.html", {"message": message}, status=400)
        if request.user.is_authenticated():
            # Redirect to GET the current URL.
            # This is required for the csrf middleware to set the auth'd tokens
            # appropriately.
            return HttpResponseRedirect(request.get_full_path())
        else:
            return jingo.render(
                request,
                login_t,
                {
                    "product": product,
                    "category": category,
                    "title": request.POST.get("title"),
                    "register_form": register_form,
                    "login_form": login_form,
                },
            )

    form = NewQuestionForm(product=product, category=category, data=request.POST)

    if form.is_valid():
        question = Question(
            creator=request.user, title=form.cleaned_data["title"], content=form.cleaned_data["content"]
        )
        question.save()
        # User successfully submitted a new question
        statsd.incr("questions.new")
        question.add_metadata(**form.cleaned_metadata)
        if product:
            question.add_metadata(product=product["key"])
            if category:
                question.add_metadata(category=category["key"])

        # The first time a question is saved, automatically apply some tags:
        question.auto_tag()

        # Submitting the question counts as a vote
        question_vote(request, question.id)

        if request.user.is_active:
            messages.add_message(request, messages.SUCCESS, _("Thanks! Your question has been posted. See it below."))
            url = reverse("questions.answers", kwargs={"question_id": question.id})
            return HttpResponseRedirect(url)

        auth.logout(request)
        statsd.incr("questions.user.logout")
        confirm_t = "questions/mobile/confirm_email.html" if request.MOBILE else "questions/confirm_email.html"
        return jingo.render(request, confirm_t, {"question": question})

    statsd.incr("questions.aaq.details-form-error")
    return jingo.render(
        request,
        template,
        {
            "form": form,
            "products": products,
            "current_product": product,
            "current_category": category,
            "current_articles": articles,
        },
    )
Beispiel #8
0
def aaq(request, product_key=None, category_key=None, showform=False, template=None, step=0):
    """Ask a new question."""

    if product_key is None:
        product_key = request.GET.get("product")
        if request.MOBILE and product_key is None:
            product_key = "mobile"
    product = products.get(product_key)
    if product_key and not product:
        raise Http404

    if category_key is None:
        category_key = request.GET.get("category")

    if product and category_key:
        category = product["categories"].get(category_key)
        if not category:
            # If we get an invalid category, redirect to previous step.
            return HttpResponseRedirect(reverse("questions.aaq_step2", args=[product_key]))
        deadend = category.get("deadend", False)
        topic = category.get("topic")
        if topic:
            html = None
            articles, fallback = documents_for(
                locale=request.LANGUAGE_CODE,
                products=Product.objects.filter(slug__in=product.get("products")),
                topics=[Topic.objects.get(slug=topic)],
            )
        else:
            html = category.get("html")
            articles = category.get("articles")
    else:
        category = None
        deadend = product.get("deadend", False) if product else False
        html = product.get("html") if product else None
        articles = None
        if product:
            # User is on the select category step
            statsd.incr("questions.aaq.select-category")
        else:
            # User is on the select product step
            statsd.incr("questions.aaq.select-product")

    login_t = "questions/mobile/new_question_login.html" if request.MOBILE else "questions/new_question_login.html"
    if request.method == "GET":
        search = request.GET.get("search", "")
        if search:
            results = _search_suggestions(
                request, search, locale_or_default(request.LANGUAGE_CODE), product.get("products")
            )
            tried_search = True
        else:
            results = []
            tried_search = False
            if category:
                # User is on the "Ask This" step
                statsd.incr("questions.aaq.search-form")

        if showform or request.GET.get("showform"):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                # User is on the login or register Step
                statsd.incr("questions.aaq.login-or-register")
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(
                    request,
                    login_t,
                    {
                        "product": product,
                        "category": category,
                        "title": search,
                        "register_form": register_form,
                        "login_form": login_form,
                    },
                )
            form = NewQuestionForm(product=product, category=category, initial={"title": search})
            # User is on the question details step
            statsd.incr("questions.aaq.details-form")
        else:
            form = None
            if search:
                # User is on the article and questions suggestions step
                statsd.incr("questions.aaq.suggestions")

        return jingo.render(
            request,
            template,
            {
                "form": form,
                "results": results,
                "tried_search": tried_search,
                "products": products,
                "current_product": product,
                "current_category": category,
                "current_html": html,
                "current_articles": articles,
                "current_step": step,
                "deadend": deadend,
                "host": Site.objects.get_current().domain,
            },
        )

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get("login"):
            login_form = handle_login(request, only_active=False)
            statsd.incr("questions.user.login")
            register_form = RegisterForm()
        elif request.POST.get("register"):
            login_form = AuthenticationForm()
            email_template = "questions/email/confirm_question.ltxt"
            email_subject = _("Please confirm your Firefox Help question")
            email_data = request.GET.get("search")
            register_form = handle_register(request, email_template, email_subject, email_data)
            if register_form.is_valid():  # Now try to log in.
                user = auth.authenticate(username=request.POST.get("username"), password=request.POST.get("password"))
                auth.login(request, user)
                statsd.incr("questions.user.register")
        else:
            # L10n: This shouldn't happen unless people tamper with POST data.
            message = _lazy("Request type not recognized.")
            return jingo.render(request, "handlers/400.html", {"message": message}, status=400)
        if request.user.is_authenticated():
            # Redirect to GET the current URL replacing the step parameter.
            # This is also required for the csrf middleware to set the auth'd
            # tokens appropriately.
            url = urlparams(request.get_full_path(), step="aaq-question")
            return HttpResponseRedirect(url)
        else:
            return jingo.render(
                request,
                login_t,
                {
                    "product": product,
                    "category": category,
                    "title": request.POST.get("title"),
                    "register_form": register_form,
                    "login_form": login_form,
                },
            )

    form = NewQuestionForm(product=product, category=category, data=request.POST)

    if form.is_valid():
        question = Question(
            creator=request.user,
            title=form.cleaned_data["title"],
            content=form.cleaned_data["content"],
            locale=request.LANGUAGE_CODE,
        )
        question.save()
        # User successfully submitted a new question
        statsd.incr("questions.new")
        question.add_metadata(**form.cleaned_metadata)
        if product:
            # TODO: This add_metadata call should be removed once we are
            # fully IA-driven (sync isn't special case anymore).
            question.add_metadata(product=product["key"])

            if product.get("products"):
                for p in Product.objects.filter(slug__in=product["products"]):
                    question.products.add(p)

            if category:
                # TODO: This add_metadata call should be removed once we are
                # fully IA-driven (sync isn't special case anymore).
                question.add_metadata(category=category["key"])

                t = category.get("topic")
                if t:
                    question.topics.add(Topic.objects.get(slug=t))

        # The first time a question is saved, automatically apply some tags:
        question.auto_tag()

        # Submitting the question counts as a vote
        question_vote(request, question.id)

        if request.user.is_active:
            messages.add_message(
                request,
                messages.SUCCESS,
                _("Done! Your question is now posted on the Mozilla community " "support forum."),
            )
            url = reverse("questions.answers", kwargs={"question_id": question.id})
            return HttpResponseRedirect(url)

        return HttpResponseRedirect(reverse("questions.aaq_confirm"))

    statsd.incr("questions.aaq.details-form-error")
    return jingo.render(
        request,
        template,
        {
            "form": form,
            "products": products,
            "current_product": product,
            "current_category": category,
            "current_articles": articles,
        },
    )