Skip to content

Commit

Permalink
temporary testing
Browse files Browse the repository at this point in the history
  • Loading branch information
escattone committed Feb 14, 2025
1 parent 0f7dc59 commit 7282e78
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions kitsune/questions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

urlpatterns = [
re_path(r"^$", views.product_list, name="questions.home"),
re_path(r"^session$", views.view_session, name="questions.session"),
re_path(
r"^answer-preview-async$",
views.answer_preview_async,
Expand Down
9 changes: 7 additions & 2 deletions kitsune/questions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
)


def view_session(request):
kb_visited = request.session.get("kb-visited") or {}
return JsonResponse(kb_visited)


def product_list(request):
"""View to select a product to see related questions."""
return render(
Expand Down Expand Up @@ -607,7 +612,7 @@ def aaq(request, product_slug=None, step=1, is_loginless=False):
if zendesk_form.is_valid() and not is_ratelimited(request, "loginless", "3/d"):

if has_visited_kb(request.session, product):
print("RYAN: FAILED DEFLECTION!!")
print("\nRYAN: FAILED DEFLECTION!!\n")

try:
zendesk_form.send(request.user, product)
Expand Down Expand Up @@ -653,7 +658,7 @@ def aaq(request, product_slug=None, step=1, is_loginless=False):
)

if has_visited_kb(request.session, question.product, question.topic):
print("RYAN: FAILED DEFLECTION!!")
print("\nRYAN: FAILED DEFLECTION!!\n")
# question.is_failed_deflection = True
# question.save()

Expand Down
22 changes: 22 additions & 0 deletions kitsune/sumo/static/sumo/js/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ import AAQSystemInfo from "sumo/js/aaq";
* Scripts for the questions app.
*/

// // The "DOMContentLoaded" event is guaranteed not to have been
// // called by the time the following code is run, because it always
// // waits until all deferred scripts have been loaded, and the code
// // in this file is always bundled into a script that is deferred.
// document.addEventListener("DOMContentLoaded", async () => {
// const newQuestionForm = document.querySelector('body.new-question #question-form');
// if (newQuestionForm) {
// newQuestionForm.addEventListener('submit', (event) => {
// event.preventDefault();
// if (this.validateForm()) {
// trackEvent('article_survey_submitted', {
// survey_type: this.surveyType,
// reason: this.selectedReason
// });
// // Allow HTMX to handle the submission
// return true;
// }
// return false;
// });
// }
// });

// TODO: Figure out how to break out the functionality here into
// testable parts.

Expand Down
14 changes: 10 additions & 4 deletions kitsune/wiki/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ def build_topics_data(request: HttpRequest, product: Product, topics: list[Topic

def clean_kb_visited(session, ttl=KB_VISITED_DEFAULT_TTL):
"""
Within the given session, remove expired KB-visited slugs.
Remove expired slugs from the "kb-visited" dictionary within the given session.
"""
if not (session and ((kb_visited := session.get("kb-visited")) is not None)):
if (not session) or ((kb_visited := session.get("kb-visited")) is None):
return None

now = time.time()
Expand All @@ -316,13 +316,19 @@ def clean_kb_visited(session, ttl=KB_VISITED_DEFAULT_TTL):

def update_kb_visited(session, doc, ttl=KB_VISITED_DEFAULT_TTL):
"""
Update the "kb_visited" dictionary within the given session.
Update the "kb-visited" dictionary within the given session.
"""
if (kb_visited := clean_kb_visited(session, ttl=ttl)) is None:
if not session:
return

if (kb_visited := clean_kb_visited(session, ttl=ttl)) is None:
session["kb-visited"] = kb_visited = {}

# Note that we have visited the given KB article.
kb_visited[doc.original.slug] = time.time()

print(f"\nRYAN: {kb_visited}\n")

session.modified = True


Expand Down

0 comments on commit 7282e78

Please sign in to comment.