зеркало из https://github.com/mozilla/kitsune.git
Merge pull request #6071 from akatsoulas/required-country
Required country
This commit is contained in:
Коммит
97f8fdad9d
|
@ -56,7 +56,7 @@ class ZendeskForm(forms.Form):
|
|||
description = forms.CharField(
|
||||
label=_lazy("Tell us more"), widget=forms.Textarea(), required=False
|
||||
)
|
||||
country = forms.CharField(widget=forms.HiddenInput)
|
||||
country = forms.CharField(widget=forms.HiddenInput, required=False)
|
||||
|
||||
def __init__(self, *args, product, user=None, **kwargs):
|
||||
kwargs.update({"initial": {"product": product.slug}})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.conf import settings
|
||||
from django.urls import re_path
|
||||
from django.urls import path, re_path
|
||||
|
||||
from kitsune.flagit import views as flagit_views
|
||||
from kitsune.questions import views
|
||||
|
@ -29,6 +29,8 @@ urlpatterns = [
|
|||
views.metrics,
|
||||
name="questions.locale_metrics",
|
||||
),
|
||||
# Mozilla location service proxy url
|
||||
path("mozilla/location/", views.aaq_location_proxy, name="questions.location_proxy"),
|
||||
# AAQ
|
||||
re_path(r"^new$", views.aaq, name="questions.aaq_step1"),
|
||||
re_path(r"^new/(?P<product_key>[\w\-]+)$", views.aaq_step2, name="questions.aaq_step2"),
|
||||
|
|
|
@ -4,6 +4,7 @@ import random
|
|||
from collections import OrderedDict
|
||||
from datetime import date, datetime, timedelta
|
||||
|
||||
import requests
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.views import redirect_to_login
|
||||
|
@ -19,6 +20,7 @@ from django.http import (
|
|||
HttpResponseBadRequest,
|
||||
HttpResponseForbidden,
|
||||
HttpResponseRedirect,
|
||||
JsonResponse,
|
||||
)
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
|
@ -45,13 +47,7 @@ from kitsune.questions.forms import (
|
|||
NewQuestionForm,
|
||||
WatchQuestionForm,
|
||||
)
|
||||
from kitsune.questions.models import (
|
||||
Answer,
|
||||
AnswerVote,
|
||||
Question,
|
||||
QuestionLocale,
|
||||
QuestionVote,
|
||||
)
|
||||
from kitsune.questions.models import Answer, AnswerVote, Question, QuestionLocale, QuestionVote
|
||||
from kitsune.questions.utils import get_featured_articles, get_mobile_product_from_ua
|
||||
from kitsune.sumo import NAVIGATION_TOPICS
|
||||
from kitsune.sumo.decorators import ratelimit
|
||||
|
@ -491,6 +487,12 @@ def edit_details(request, question_id):
|
|||
return redirect(reverse("questions.details", kwargs={"question_id": question_id}))
|
||||
|
||||
|
||||
def aaq_location_proxy(request):
|
||||
"""Proxy request from the Mozilla service to our form."""
|
||||
response = requests.get(settings.MOZILLA_LOCATION_SERVICE)
|
||||
return JsonResponse(response.json())
|
||||
|
||||
|
||||
def aaq(request, product_key=None, category_key=None, step=1, is_loginless=False):
|
||||
"""Ask a new question."""
|
||||
|
||||
|
|
|
@ -1314,6 +1314,10 @@ MOZILLA_ACCOUNT_ARTICLES = [
|
|||
"im-having-problems-confirming-my-firefox-account",
|
||||
]
|
||||
|
||||
MOZILLA_LOCATION_SERVICE = config(
|
||||
"MOZILLA_LOCATION_SERVICE",
|
||||
default="https://location.services.mozilla.com/v1/country?key=fa6d7fc9-e091-4be1-b6c1-5ada5815ae9d", # noqa
|
||||
)
|
||||
# Wagtail settings
|
||||
WAGTAIL_ENABLE_ADMIN = config("WAGTAIL_ENABLE_ADMIN", default=False, cast=bool)
|
||||
WAGTAIL_I18N_ENABLED = True
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
window.addEventListener("DOMContentLoaded", (event) => {
|
||||
const geoIPUrl = 'https://location.services.mozilla.com/v1/country?key=fa6d7fc9-e091-4be1-b6c1-5ada5815ae9d';
|
||||
// const geoIPUrl = 'https://location.services.mozilla.com/v1/country?key=fa6d7fc9-e091-4be1-b6c1-5ada5815ae9d';
|
||||
const proxyUrl = "/questions/mozilla/location/"
|
||||
const countryField = document.querySelector('input#id_country');
|
||||
|
||||
if (countryField) {
|
||||
fetch(geoIPUrl)
|
||||
fetch(proxyUrl)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`Fetch failed, status ${response.status}`)
|
||||
|
@ -12,7 +13,17 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
|||
|
||||
})
|
||||
.then(data => {
|
||||
countryField.value = data.country_name;
|
||||
|
||||
if(data && data.country_name) {
|
||||
countryField.value = data.country_name;
|
||||
} else {
|
||||
countryField.value = '';
|
||||
console.log('No country name found in response.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching country:', error);
|
||||
countryField.value = '';
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче