add search feature

This commit is contained in:
erichhasl
2017-11-27 15:44:24 +01:00
parent fc9a00cc6f
commit b2b0ea0e2a
4 changed files with 56 additions and 28 deletions
@@ -14,6 +14,15 @@
</p> </p>
</td> </td>
</tr> </tr>
{% if rows|length == 0 %}
<tr>
<td class="tddatabase", colspan=4>
<p id="description">
<b>Keine Einträge für den Suchbegriff "{{ query }}" gefunden.</b>
</p>
</td>
</tr>
{% endif %}
{% for row in rows %} {% for row in rows %}
<tr class="trdatabase"> <tr class="trdatabase">
{% for entry in row %} {% for entry in row %}
+9 -3
View File
@@ -6,9 +6,15 @@ from .models import Entry
# Create your views here. # Create your views here.
def index(request): def index(request):
rows = group(Entry.objects.all(), 3) query = ""
print("rows", rows) if request.method == 'POST':
return render(request, "datenbank/index.html", {'rows': rows}) query = request.POST['query']
objects = Entry.objects.filter(title__icontains=query)
else:
objects = Entry.objects.all()
rows = group(objects, 3)
return render(request, "datenbank/index.html", {'rows': rows,
'query': query})
def group(l, n): def group(l, n):
@@ -23,6 +23,16 @@ html {
vertical-align: middle; vertical-align: middle;
padding-left: 0px; padding-left: 0px;
} }
#submit_search {
border: none;
background-color: transparent;
color: transparent;
background-image: url('../images/search_icon.png');
background-size: 100%;
background-position: center;
height: 64px;
background-repeat: no-repeat;
}
table{ table{
border-collapse: collapse; border-collapse: collapse;
border: none; border: none;
+5 -2
View File
@@ -3,6 +3,8 @@
<link rel="stylesheet" type="text/css" href="{% static "public/css/header.css" %}"> <link rel="stylesheet" type="text/css" href="{% static "public/css/header.css" %}">
<div id=header> <div id=header>
<form action="{% url "datenbank:index" %}" method="post">
{% csrf_token %}
<table class="table"> <table class="table">
<tr> <tr>
<td id ="logotablerow", width="20%"> <td id ="logotablerow", width="20%">
@@ -21,13 +23,14 @@
<a class="top-links", href="https://www.bpb.de">bpb.de</a> <a class="top-links", href="https://www.bpb.de">bpb.de</a>
</td> </td>
<td vertical-align="middle", width="25%" class="allcenter"> <td vertical-align="middle", width="25%" class="allcenter">
<input type="text" id="search" maxlength="30" placeholder="Datenbank durchsuchen"> <input type="text" id="search" name="query" maxlength="30" placeholder="Datenbank durchsuchen" value="{{ query }}">
</td> </td>
<td width="5%" class="allcenter"> <td width="5%" class="allcenter">
<a href="http://www.dohiy.com/wp-content/uploads/2014/06/itsatrap.jpg"><img id="search_icon" src="{% static "public/images/search_icon.png" %}" alt="search"></a> <input id="submit_search" type="submit" value="Suchen">
</td> </td>
</tr> </tr>
</table> </table>
</form>
<div id="navigation"> <div id="navigation">
<ul class="navbar"> <ul class="navbar">
<li class ="navbar"><a {% if appname == "startpage" %}class="active"{% endif %} href="/">Information</a></li> <li class ="navbar"><a {% if appname == "startpage" %}class="active"{% endif %} href="/">Information</a></li>