This commit is contained in:
Ross
2024-10-14 14:39:18 +01:00
parent 6b064b2653
commit 87c1ac4e96
5 changed files with 44 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
{% extends 'oef/base.html' %}
{% block content %}
<h2>Search</h2>
<form action="" method="post">
<textarea name="search" rows="10" cols="50"></textarea>
<input type="button" value="Search"
hx-post="{% url 'oef:format_search' %}"
hx-target="#search-results"
>
</form>
<div id="search-results"></div>
{% endblock %}
@@ -0,0 +1,10 @@
<ul>
{% for entry in entries %}
<li>
{{ entry.exam_code}} - {{ entry.exam_name }} (<a href='{{entry.get_absolute_url}}'>view</a>)
</li>
{% endfor %}
</ul>
+1 -1
View File
@@ -43,7 +43,7 @@
<li class="question {% if format %}named{% else %}unnamed{% endif %}"> <li class="question {% if format %}named{% else %}unnamed{% endif %}">
<span class="format-name"> <span class="format-name">
{% if format %} {% if format %}
<a href='{% url "oef:format_update" format.pk %}'>{{format.name}}</a> Name: <a href='{% url "oef:format_update" format.pk %}'>{{format.name}}</a>
{% endif %} {% endif %}
</span> </span>
<pre class="pre-question" title="{{ question }}">{{ question }}</pre> <pre class="pre-question" title="{{ question }}">{{ question }}</pre>
+3
View File
@@ -20,6 +20,9 @@ urlpatterns = [
path( path(
"formats/create", views.FormatsCreateView.as_view(), name="format_create" "formats/create", views.FormatsCreateView.as_view(), name="format_create"
), ),
path(
"formats/search", views.format_search, name="format_search"
),
path( path(
"entries/replace_questions", views.replace_questions, name="replace_questions" "entries/replace_questions", views.replace_questions, name="replace_questions"
), ),
+11
View File
@@ -95,6 +95,17 @@ def entries(request):
entries = Entry.objects.all().order_by("exam_code") entries = Entry.objects.all().order_by("exam_code")
return render(request, "oef/entries.html", {"entries": entries}) return render(request, "oef/entries.html", {"entries": entries})
def format_search(request):
if request.method == "POST":
search = request.POST.get("search")
entries = Entry.objects.filter(questions__icontains=search)
return render(request, "oef/format_search_results.html", {"entries": entries})
return render(request, "oef/format_search.html",)
def questions(request): def questions(request):
questions = set(Entry.objects.filter(inactive=False).values_list("questions", flat=True)) questions = set(Entry.objects.filter(inactive=False).values_list("questions", flat=True))