.
This commit is contained in:
@@ -15,6 +15,12 @@ There are {{ questions|length }} question sets.
|
|||||||
_="on click toggle @disabled until htmx:afterOnLoad then remove me"
|
_="on click toggle @disabled until htmx:afterOnLoad then remove me"
|
||||||
>View exams</button>
|
>View exams</button>
|
||||||
<span class="result"></span>
|
<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>
|
</form>
|
||||||
<button class="btn btn-sm" _="on click set #question1.value to the innerHTML of the previous <pre/>">
|
<button class="btn btn-sm" _="on click set #question1.value to the innerHTML of the previous <pre/>">
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
@@ -29,6 +29,10 @@ urlpatterns = [
|
|||||||
path(
|
path(
|
||||||
"entries/questions_diff", views.questions_diff, name="questions_diff"
|
"entries/questions_diff", views.questions_diff, name="questions_diff"
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"entries/questions_sym", views.questions_sym, name="questions_sym"
|
||||||
|
),
|
||||||
|
|
||||||
path(
|
path(
|
||||||
"entries/entries_by_question", views.entries_by_question, name="entries_by_question"
|
"entries/entries_by_question", views.entries_by_question, name="entries_by_question"
|
||||||
),
|
),
|
||||||
|
|||||||
+24
-3
@@ -1,5 +1,5 @@
|
|||||||
from difflib import HtmlDiff
|
from difflib import HtmlDiff, SequenceMatcher
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.views.generic.edit import UpdateView, CreateView
|
from django.views.generic.edit import UpdateView, CreateView
|
||||||
from django.views.generic.detail import DetailView
|
from django.views.generic.detail import DetailView
|
||||||
@@ -117,4 +117,25 @@ def questions_diff(request):
|
|||||||
|
|
||||||
return HttpResponse(html)
|
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user