- Implemented tagging functionality in the article editing and creation forms, allowing users to select tags for articles. - Updated the article detail view to display related articles based on shared tags. - Added a new portal view for customers to access help articles, including search functionality. - Introduced a suggestions feature in the request form to display relevant articles based on user input. - Enhanced the mobile solution detail screen to support tag selection and display. - Updated data models to include tag IDs for articles, ensuring proper handling of tags in the backend. - Added tests to verify the correct behavior of the tagging system in the solution detail screen.
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""Text handling shared by the two knowledge-base suggesters.
|
|
|
|
There are two of them now: the agent-facing one in `kb_views` and the
|
|
customer-facing one in `portal_views`. They answer to different visibility
|
|
rules and return different shapes, but they read the same articles, so the
|
|
matching and the truncation live here rather than being written twice and
|
|
drifting apart.
|
|
|
|
What is deliberately NOT shared is the queryset. Each caller builds its own,
|
|
because deciding who may see which article is the security boundary and it
|
|
should be written out at each call site rather than inherited from a helper.
|
|
"""
|
|
|
|
from django.db.models import Q
|
|
|
|
SNIPPET_MAX = 200
|
|
|
|
|
|
def snippet(text):
|
|
"""A single-line preview of an article body."""
|
|
if not text:
|
|
return ""
|
|
text = text.strip()
|
|
if len(text) <= SNIPPET_MAX:
|
|
return text
|
|
return text[: SNIPPET_MAX - 1].rstrip() + "…"
|
|
|
|
|
|
def text_match(term):
|
|
"""Match `term` against an article's title or body.
|
|
|
|
Substring matching, not full-text search. At the size of one org's
|
|
knowledge base that is the right trade, and it keeps the two suggesters
|
|
returning the same articles for the same words.
|
|
"""
|
|
return Q(title__icontains=term) | Q(description__icontains=term)
|