зеркало из https://github.com/mozilla/kitsune.git
allow pinning articles in the AAQ flow
https://github.com/mozilla/sumo-project/issues/912
This commit is contained in:
Родитель
029d8c83a7
Коммит
b8cb682d36
|
@ -1,6 +1,6 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from kitsune.questions.models import QuestionLocale
|
||||
from kitsune.questions.models import QuestionLocale, AAQConfig
|
||||
|
||||
|
||||
class QuestionLocaleAdmin(admin.ModelAdmin):
|
||||
|
@ -10,3 +10,11 @@ class QuestionLocaleAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
admin.site.register(QuestionLocale, QuestionLocaleAdmin)
|
||||
|
||||
|
||||
class AAQConfigAdmin(admin.ModelAdmin):
|
||||
list_display = ("product",)
|
||||
autocomplete_fields = ("pinned_articles",)
|
||||
|
||||
|
||||
admin.site.register(AAQConfig, AAQConfigAdmin)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 2.2.24 on 2021-09-23 04:54
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('products', '0005_auto_20200629_0826'),
|
||||
('wiki', '0012_auto_20200629_0826'),
|
||||
('questions', '0011_auto_20200629_0826'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AAQConfig',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('pinned_articles', models.ManyToManyField(to='wiki.Document')),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='aaq_configs', to='products.Product')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'AAQ configuration',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -33,6 +33,7 @@ from kitsune.sumo.urlresolvers import reverse, split_path
|
|||
from kitsune.tags.models import BigVocabTaggableMixin
|
||||
from kitsune.tags.utils import add_existing_tag
|
||||
from kitsune.upload.models import ImageAttachment
|
||||
from kitsune.wiki.models import Document
|
||||
|
||||
log = logging.getLogger("k.questions")
|
||||
|
||||
|
@ -754,6 +755,14 @@ class QuestionLocale(ModelBase):
|
|||
verbose_name = "AAQ enabled locale"
|
||||
|
||||
|
||||
class AAQConfig(ModelBase):
|
||||
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name="aaq_configs")
|
||||
pinned_articles = models.ManyToManyField(Document)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "AAQ configuration"
|
||||
|
||||
|
||||
class Answer(ModelBase):
|
||||
"""An answer to a support question."""
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import logging
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from kitsune.questions.models import Answer, Question
|
||||
from kitsune.wiki.utils import get_featured_articles as kb_get_featured_articles
|
||||
|
||||
log = logging.getLogger("k.questions")
|
||||
|
||||
|
@ -52,3 +54,34 @@ def get_mobile_product_from_ua(user_agent):
|
|||
return None
|
||||
else:
|
||||
return "mobile"
|
||||
|
||||
|
||||
def get_featured_articles(product, locale):
|
||||
"""
|
||||
Returns 4 featured articles for the AAQ.
|
||||
|
||||
Will return pinned articles first, then fill randomly from the most visited articles.
|
||||
|
||||
For pinned articles in WIKI_DEFAULT_LANGUAGE, return a localized version if it exists.
|
||||
For pinned articles in other locales, return them only if `locale` matches.
|
||||
"""
|
||||
|
||||
if config := product.aaq_configs.first():
|
||||
pinned_articles = [
|
||||
localized_article
|
||||
for article in config.pinned_articles.filter(
|
||||
locale__in=(locale, settings.WIKI_DEFAULT_LANGUAGE)
|
||||
)
|
||||
if (
|
||||
localized_article := article
|
||||
if article.locale == locale
|
||||
else article.translated_to(locale)
|
||||
)
|
||||
]
|
||||
else:
|
||||
pinned_articles = []
|
||||
|
||||
if len(pinned_articles) < 4:
|
||||
return (pinned_articles + kb_get_featured_articles(product=product, locale=locale))[:4]
|
||||
|
||||
return pinned_articles
|
||||
|
|
|
@ -46,7 +46,7 @@ from kitsune.questions.forms import (
|
|||
WatchQuestionForm,
|
||||
)
|
||||
from kitsune.questions.models import Answer, AnswerVote, Question, QuestionLocale, QuestionVote
|
||||
from kitsune.questions.utils import get_mobile_product_from_ua
|
||||
from kitsune.questions.utils import get_mobile_product_from_ua, get_featured_articles
|
||||
from kitsune.sumo.decorators import ratelimit, ssl_required
|
||||
from kitsune.sumo.templatetags.jinja_helpers import urlparams
|
||||
from kitsune.sumo.urlresolvers import reverse, split_path
|
||||
|
@ -56,7 +56,6 @@ from kitsune.upload.models import ImageAttachment
|
|||
from kitsune.upload.views import upload_imageattachment
|
||||
from kitsune.users.models import Setting
|
||||
from kitsune.wiki.facets import topics_for
|
||||
from kitsune.wiki.utils import get_featured_articles
|
||||
|
||||
log = logging.getLogger("k.questions")
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче