This commit is contained in:
Ross
2024-10-09 23:12:56 +01:00
parent f4c82f45f5
commit e69d1a6b9a
4 changed files with 23 additions and 5 deletions
+4
View File
@@ -49,6 +49,7 @@ class Formats(models.Model):
self.format = self.format.replace("\r\n", "\n")
return super().clean()
def save(self, *args, **kwargs):
self.format = self.format.replace("\r\n", "\n")
return super().save(*args, **kwargs)
@@ -62,6 +63,9 @@ class Formats(models.Model):
formats.reverse()
return "\n".join(formats)
def get_entries(self):
return Entry.objects.filter(questions__icontains=self.get_format())
class Specialty(models.Model):
name = models.CharField(max_length=200)
@@ -5,4 +5,10 @@
{{ form }}
<input type="submit" value="Update">
</form>
<h2>Entries</h2>
<ul>
{% for entry in object.get_entries %}
<li>{{ entry.exam_code }} / {{ entry.exam_name }}</li>
{% endfor %}
{% endblock content %}
+12 -4
View File
@@ -3,15 +3,23 @@
<h2>Questions</h2>
There are {{ questions|length }} question sets.
<div>Filter by:
<div>
<textarea type="text" id="search-text" name="search" placeholder="Search text.." rows=5 cols=50 ></textarea>
<button
_="on click repeat for el in <li.question/>
set p to the first <pre/> in el then
if p.title does not contain value of #search-text then hide el">Filter</button>
if p.title does not contain value of #search-text then hide el">Search</button>
</div>
<div>
Filter by
<button
_="on click hide .unnamed then show .named"
>Named</button>
<button
_="on click hide .named then show .unnamed"
>Unnamed</button>
<div class="offcanvas offcanvas-end bg-dark" tabindex="-1" id="offcanvasExample" data-bs-scroll="true" data-bs-backdrop="false" aria-labelledby="offcanvasExampleLabel">
<div class="offcanvas-header">
@@ -32,7 +40,7 @@
<ul>
{% for question, format in questions_and_formats %}
<li class="question">
<li class="question {% if format %}named{% else %}unnamed{% endif %}">
<span class="format-name">
{% if format %}
<a href='{% url "oef:format_update" format.pk %}'>{{format.name}}</a>
@@ -79,7 +87,7 @@
end
"
>Add codes to sidebar</button>
<input type="text" class="format-name" placeholder="format name" style="display:none">
<input type="text" class="format-name" name="format_name" placeholder="format name" style="display:none">
<button
class="btn btn-sm save-format-button" type="button" style="display:none"
hx-post="{% url 'oef:formats_save' %}"
+1 -1
View File
@@ -179,7 +179,7 @@ def formats_save(request):
if Formats.objects.filter(format=question).exists():
return HttpResponse("Format questions already exists")
Formats.objects.create(name="format_name", format=question)
Formats.objects.create(name=format_name, format=question)
return HttpResponse("Format saved")