search form works

This commit is contained in:
Christoph J. Scherr 2023-05-30 15:23:04 +02:00
parent f43c506538
commit ca066e7c16
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
10 changed files with 191 additions and 38 deletions

View File

@ -3,5 +3,5 @@ from django.urls import path
from . import views
urlpatterns = [
path("", views.IndexView.as_view(), name="index"),
path("", views.IndexView.as_view(), name="BlogIndex"),
]

16
gawa/start/forms.py Normal file
View File

@ -0,0 +1,16 @@
from django import forms
from django.utils.translation import gettext as _
class MainSearchForm(forms.Form):
search = forms.CharField(
max_length=100,
label=''
)
search.widget = forms.TextInput(
attrs={
'class': "form-control me-2",
'type': "search",
'aria-label': "Search",
'placeholder': _("Search")
}
)

View File

@ -0,0 +1 @@
400 you fucked up

View File

@ -11,7 +11,7 @@
<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<a class="navbar-brand" href="{% url 'StartIndex' %}">
<img src="https://static.cscherr.de/images/profile/profile-margin.png" alt="Logo" height="30" class="d-inline-block align-text-top">
{% translate "cscherr.de" noop %}
</a>
@ -21,10 +21,10 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/">{% translate "Start" %}</a>
<a class="nav-link active" aria-current="page" href="{% url 'StartIndex' %}">{% translate "Start" %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/blog">{% translate "Blog" %}</a>
<a class="nav-link" href="{% url 'BlogIndex' %}">{% translate "Blog" %}</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
@ -38,10 +38,12 @@
</ul>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
{% block MainSearchFormSpace %}
<form class="d-flex" role="search" action="{% url 'StartMainSearch' %}" method="GET">
{{ MainSearchForm }}
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
{% endblock MainSearchFormSpace %}
</div>
</div>
</nav>
@ -49,29 +51,27 @@
{% block main %}{% endblock main %}
</main>
<footer class="text-center text-lg-start bg-white text-muted">
<section class="d-flex justify-content-center justify-content-lg-between p-4 border-bottom">
<div>
<a href="" class="me-4 link-secondary">
<i class="fab fa-facebook-f"></i>
</a>
<a href="" class="me-4 link-secondary">
<i class="fab fa-twitter"></i>
</a>
<a href="" class="me-4 link-secondary">
<i class="fab fa-google"></i>
</a>
<a href="" class="me-4 link-secondary">
<i class="fab fa-instagram"></i>
</a>
<a href="" class="me-4 link-secondary">
<i class="fab fa-linkedin"></i>
</a>
<a href="" class="me-4 link-secondary">
<i class="fab fa-github"></i>
</a>
<div class="container overflow-hidden text-center">
<div class="row gy-5">
<div class="col-6">
<div class="p-3"></div>
</div>
<div class="col-6">
<div class="p-3"></div>
</div>
</div>
</div>
<section class="bg-secondary-subtle">
<div class="container overflow-hidden text-center">
<div class="row gy-5">
<div class="col-6">
<div class="p-3"></div>
</div>
<div class="col-6">
<div class="p-3"></div>
</div>
</div>
</div>
</section>
<section class="">
<div class="container text-center text-md-start mt-5">
<div class="row mt-3">
<div class="col-md-3 col-lg-4 col-xl-3 mx-auto mb-4">

View File

@ -4,10 +4,34 @@
{% block languagecode %}{{ LANGUAGE_CODE }}{% endblock languagecode %}
{% block title %}{% translate "cscherr.de" %} - {% translate "startpage" %}{% endblock title %}
{% block main %}
<div class="jumbotron text-center">
<div class="container-xxl">
<div class="jumbotron text-center">
<h1>My First Bootstrap Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>
<div class="container-fluid">
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
</div>
{% endblock main %}

View File

@ -0,0 +1,36 @@
{% extends 'start/base.html' %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% block languagecode %}{{ LANGUAGE_CODE }}{% endblock languagecode %}
{% block title %}{% translate "cscherr.de" %} - {% translate "startpage" %}{% endblock title %}
{% block main %}
<div class="container-xxl">
<div class="jumbotron text-center">
<h1>{% translate "Search for: " %}</h1>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
</div>
{% endblock main %}

View File

@ -0,0 +1,36 @@
{% extends 'start/base.html' %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% block languagecode %}{{ LANGUAGE_CODE }}{% endblock languagecode %}
{% block title %}{% translate "cscherr.de" %} - {% translate "startpage" %}{% endblock title %}
{% block main %}
<div class="container-xxl">
<div class="jumbotron text-center">
<h1>{% translate "Search for:" %} {{ searchstr }}</h1>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
<div class="row text-center">
<div class="col">
Column
</div>
<div class="col">
Column
</div>
</div>
</div>
{% endblock main %}

View File

@ -3,5 +3,7 @@ from django.urls import path
from . import views
urlpatterns = [
path("", views.IndexView.as_view(), name="index"),
path("", views.IndexView.as_view(), name="StartIndex"),
path("search/", views.MainSearchView.as_view(), name="StartMainSearch"),
path("legal/", views.LegalInfoView.as_view(), name="StartLegalInfo"),
]

View File

@ -1,8 +1,13 @@
from django.http import HttpResponse
from django.views.generic.base import TemplateView
from http.client import HTTPResponse
from django.apps import AppConfig
from django.http import Http404, HttpResponse, HttpResponseBadRequest, response
from django.urls import Resolver404
from django.views.generic import TemplateView, ListView
from django.views import View
from django.template import Template, loader
from django.template import Template, context, loader
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import MainSearchForm
class IndexView(TemplateView):
"""
@ -14,3 +19,36 @@ class IndexView(TemplateView):
template_name: str = "start/index.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["MainSearchForm"] = MainSearchForm()
return context
class LegalInfoView(TemplateView):
"""
Legal info that the german authorities want.
"""
template_name: str = "start/legalinfo.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["MainSearchForm"] = MainSearchForm()
return context
class MainSearchView(TemplateView):
"""
Search for anything.
"""
template_name: str = "start/search.html"
def get(self, request, *args, **kwargs):
form = MainSearchForm(request.GET)
if not form.is_valid():
return render(request, "errors/bad_request.html")
context = {
"searchstr": form.cleaned_data['search'],
"MainSearchForm": MainSearchForm()
}
return render(request=request, template_name=self.template_name, context=context)