.
This commit is contained in:
@@ -6,5 +6,6 @@
|
||||
{% block navigation %}
|
||||
<a href="{% url 'oef:entry_table_view' %}">Entries</a> /
|
||||
<a href="{% url 'oef:formats_view' %}">Formats</a> /
|
||||
<a href="{% url 'oef:questions' %}">Questions</a> /
|
||||
<a href="{% url 'oef:replace_questions' %}">Replace Questions</a> /
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
<ul>
|
||||
{% for entry in entries %}
|
||||
<li>{{entry.exam_name}}</li>
|
||||
{% endfor %}
|
||||
<ul>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
{% extends 'oef/base.html' %}
|
||||
{% block content %}
|
||||
<h2>Questions</h2>
|
||||
There are {{ questions|length }} question sets.
|
||||
|
||||
<ul>
|
||||
{% for question in questions %}
|
||||
<li class="question">
|
||||
<pre>{{ question }}</pre>
|
||||
<form>
|
||||
<input type="hidden" name="question" value="{{ question }}">
|
||||
<button
|
||||
hx-post="{% url 'oef:entries_by_question' %}"
|
||||
hx-target="next .result"
|
||||
_="on click toggle @disabled until htmx:afterOnLoad then remove me"
|
||||
>View exams</button>
|
||||
<span class="result"></span>
|
||||
|
||||
</form>
|
||||
<button class="btn btn-sm" _="on click set #question1.value to the innerHTML of the previous <pre/>">
|
||||
Diff1
|
||||
</button>
|
||||
<button class="btn btn-sm" _="on click set #question2.value to the innerHTML of the previous <pre/> then go to #question2 ">
|
||||
Diff2
|
||||
</button>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<div>Diff:</div>
|
||||
<form>
|
||||
<textarea id="question1" name="question1"></textarea>
|
||||
<textarea id="question2" name="question2"></textarea>
|
||||
<button
|
||||
hx-post='{% url "oef:questions_diff" %}'
|
||||
hx-target="#diff-results">Diff</button>
|
||||
<br/>results
|
||||
<span id="diff-results"></span>
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
li.question {
|
||||
border: 1px solid white;
|
||||
}
|
||||
</style>
|
||||
|
||||
{% endblock css %}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
<textarea id="search" name="search" placeholder="Search text.." rows=10 cols=50></textarea>
|
||||
<textarea id="replace" name="replace" placeholder="Replace text.." rows=10 cols=50></textarea>
|
||||
<br/>
|
||||
<label for="exact">Exact match</label><input type="checkbox" name="exact">
|
||||
<br/>
|
||||
<button hx-post="{% url 'oef:replace_questions' %}"
|
||||
hx-target='#result'>Replace</button>
|
||||
<div id="result"></div>
|
||||
|
||||
@@ -23,6 +23,15 @@ urlpatterns = [
|
||||
path(
|
||||
"entries/replace_questions", views.replace_questions, name="replace_questions"
|
||||
),
|
||||
path(
|
||||
"entries/questions", views.questions, name="questions"
|
||||
),
|
||||
path(
|
||||
"entries/questions_diff", views.questions_diff, name="questions_diff"
|
||||
),
|
||||
path(
|
||||
"entries/entries_by_question", views.entries_by_question, name="entries_by_question"
|
||||
),
|
||||
path(
|
||||
"entries/<int:pk>/update", views.EntryUpdateView.as_view(), name="entry_update"
|
||||
),
|
||||
|
||||
+34
-2
@@ -1,3 +1,4 @@
|
||||
from difflib import HtmlDiff
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.views.generic.edit import UpdateView, CreateView
|
||||
@@ -77,7 +78,10 @@ def replace_questions(request):
|
||||
if not search or not replace:
|
||||
return HttpResponse("Please provide both search and replace values")
|
||||
|
||||
entries = Entry.objects.filter(questions__contains=search)
|
||||
if request.POST.get("exact", False):
|
||||
entries = Entry.objects.filter(questions=search)
|
||||
else:
|
||||
entries = Entry.objects.filter(questions__contains=search)
|
||||
|
||||
for entry in entries:
|
||||
entry.questions = entry.questions.replace(search, replace)
|
||||
@@ -85,4 +89,32 @@ def replace_questions(request):
|
||||
|
||||
return HttpResponse(f"{entries.count()} questions replaced")
|
||||
else:
|
||||
return render(request, "oef/replace_questions.html", {})
|
||||
return render(request, "oef/replace_questions.html", {})
|
||||
|
||||
def questions(request):
|
||||
questions = set(Entry.objects.all().values_list("questions", flat=True))
|
||||
|
||||
questions = sorted(questions, key=lambda x: len(x))
|
||||
|
||||
return render(request, "oef/questions.html", {"questions": questions})
|
||||
|
||||
def entries_by_question(request):
|
||||
|
||||
if request.method == "POST":
|
||||
question = request.POST.get("question")
|
||||
entries = Entry.objects.filter(questions=question)
|
||||
|
||||
return render(request, "oef/entries_by_question.html", {"entries": entries})
|
||||
|
||||
return HttpResponse("Please provide a question")
|
||||
|
||||
def questions_diff(request):
|
||||
if request.method == "POST":
|
||||
question1 = request.POST.get("question1")
|
||||
question2 = request.POST.get("question2")
|
||||
|
||||
html = HtmlDiff().make_table(question1.split("\n"), question2.split("\n"))
|
||||
|
||||
return HttpResponse(html)
|
||||
|
||||
return HttpResponse("Please provide two questions")
|
||||
Reference in New Issue
Block a user