This commit is contained in:
Ross
2024-10-08 09:34:50 +01:00
parent 850da0c2ac
commit b7a0c60b16
4 changed files with 49 additions and 3 deletions
+6
View File
@@ -15,6 +15,12 @@ There are {{ questions|length }} question sets.
_="on click toggle @disabled until htmx:afterOnLoad then remove me"
>View exams</button>
<span class="result"></span>
<button
hx-post="{% url 'oef:questions_sym' %}"
hx-target="next .results-sym"
{% comment %} _="on click toggle @disabled until htmx:afterOnLoad then remove me" {% endcomment %}
>View similar</button>
<span class="results-sym"></span>
</form>
<button class="btn btn-sm" _="on click set #question1.value to the innerHTML of the previous <pre/>">
+15
View File
@@ -0,0 +1,15 @@
<ul>
{% for q, ratio in output %}
<li title="{{q}}">{{ratio}}
<span
_="on click set s to title of previous <li/> then
repeat for pre in .pre-question
if s is pre.innerHTML
then go to pre then break
">+</span>
</li>
{% endfor %}
</ul>
+4
View File
@@ -29,6 +29,10 @@ urlpatterns = [
path(
"entries/questions_diff", views.questions_diff, name="questions_diff"
),
path(
"entries/questions_sym", views.questions_sym, name="questions_sym"
),
path(
"entries/entries_by_question", views.entries_by_question, name="entries_by_question"
),
+24 -3
View File
@@ -1,5 +1,5 @@
from difflib import HtmlDiff
from django.http import HttpResponse
from difflib import HtmlDiff, SequenceMatcher
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, render
from django.views.generic.edit import UpdateView, CreateView
from django.views.generic.detail import DetailView
@@ -117,4 +117,25 @@ def questions_diff(request):
return HttpResponse(html)
return HttpResponse("Please provide two questions")
return HttpResponse("Please provide two questions")
def questions_sym(request):
if request.method == "POST":
question = request.POST.get("question")
questions = set(Entry.objects.all().values_list("questions", flat=True))
output = []
for q in questions:
ratio = SequenceMatcher(None, question, q).ratio()
if ratio > 0.5:
output.append((q, ratio))
output = sorted(output, key=lambda x: x[1], reverse=True)
return render(request, "oef/questions_sym.html", {"output": output})
return HttpResponse("Please provide a question set")