simplify Posts Search Form

This commit is contained in:
2022-06-17 09:35:59 +00:00
parent e6ef76e235
commit 22747c1206
3 changed files with 19 additions and 43 deletions

View File

@@ -2,6 +2,7 @@ from ckeditor_uploader.widgets import CKEditorUploadingWidget
from taggit.models import Tag from taggit.models import Tag
from django import forms from django import forms
from django.forms.widgets import CheckboxInput
from django.utils import timezone from django.utils import timezone
from django.utils.dates import MONTHS from django.utils.dates import MONTHS
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@@ -170,6 +171,9 @@ class PostSearchForm(forms.Form):
year = forms.ChoiceField(label="Jahr", choices=year_choices, required=False) year = forms.ChoiceField(label="Jahr", choices=year_choices, required=False)
month = forms.ChoiceField(label="Monat", choices=month_choices, required=False) month = forms.ChoiceField(label="Monat", choices=month_choices, required=False)
compact_view = forms.BooleanField(label="Kompakte Ansicht", required=False, widget=CheckboxInput)
fet_meeting_only = forms.BooleanField(label="nur FET Sitzungen", required=False, widget=CheckboxInput)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # to get the self.fields set super().__init__(*args, **kwargs) # to get the self.fields set

View File

@@ -22,44 +22,17 @@ logger = logging.getLogger(__name__)
def index(request): def index(request):
posts = None posts = None
compact_view = None
fet_meeting_only = None
public_only = not request.user.is_authenticated public_only = not request.user.is_authenticated
if request.method == "POST": if request.method == "POST":
if "btn_input" in request.POST: form = PostSearchForm(request.POST)
form = PostSearchForm(request.POST) if form.is_valid():
posts = Post.objects.date_filtered_list(
if "compact_view" in request.POST.getlist("checkbox"): public_only,
compact_view = True form.cleaned_data["year"],
form.cleaned_data["month"],
if "fet_meeting_only" in request.POST.getlist("checkbox"): form.cleaned_data["fet_meeting_only"],
fet_meeting_only = True )
if form.is_valid():
month = form.cleaned_data["month"]
year = form.cleaned_data["year"]
if month == "":
month = None
if year == "":
year = None
month = None
if not year and month:
messages.info(
request, "Es kann nicht nur nach einem Monat gesucht werden."
)
posts = Post.objects.date_filtered_list(
public_only,
year,
month,
fet_meeting_only,
)
else: else:
last_year = Post.objects.get_queryset().first() last_year = Post.objects.get_queryset().first()
if last_year: if last_year:
@@ -83,8 +56,6 @@ def index(request):
context = { context = {
"formset": form, "formset": form,
"compact_view": compact_view,
"fet_meeting_only": fet_meeting_only,
"posts": posts, "posts": posts,
} }

View File

@@ -45,7 +45,7 @@
<div class="alert alert-danger"> <div class="alert alert-danger">
<i class="alert-icon fa-solid fa-exclamation-circle"></i> <i class="alert-icon fa-solid fa-exclamation-circle"></i>
<h2 class="alert-title">Fehler:</h2> <h2 class="alert-title">Fehler:</h2>
<div class="alert-body">{{message}}</div> <div class="alert-body">{{ message }}</div>
</div> </div>
{% endfor %} {% endfor %}
@@ -89,13 +89,14 @@
</select> </select>
</label> </label>
<label class="inline-flex items-center"> <label class="inline-flex items-center">
<input type="checkbox" id="compact_view" name="checkbox" value="compact_view" {% if compact_view %} checked {% endif %} class="rounded border-gray-300 dark:border-none text-proprietary shadow-sm focus:border-blue-300 focus:ring focus:ring-offset-0 focus:ring-blue-200 dark:focus:ring-sky-700 focus:ring-opacity-50"> <input type="checkbox" id="id_compact_view" name="compact_view" {% if formset.compact_view.value %}checked{% endif %} class="rounded border-gray-300 dark:border-none text-proprietary shadow-sm focus:border-blue-300 focus:ring focus:ring-offset-0 focus:ring-blue-200 dark:focus:ring-sky-700 focus:ring-opacity-50">
<span class="ml-2 text-gray-700 dark:text-gray-200">Kompakte Ansicht</span> <span class="ml-2 text-gray-700 dark:text-gray-200">{{ formset.compact_view.label }}</span>
</label> </label>
<label class="inline-flex items-center"> <label class="inline-flex items-center">
<input type="checkbox" id="fet_meeting_only" name="checkbox" value="fet_meeting_only" {% if fet_meeting_only %} checked {% endif %} class="rounded border-gray-300 dark:border-none text-proprietary shadow-sm focus:border-blue-300 focus:ring focus:ring-offset-0 focus:ring-blue-200 dark:focus:ring-sky-700 focus:ring-opacity-50"> <input type="checkbox" id="id_fet_meeting_only" name="fet_meeting_only" {% if formset.fet_meeting_only.value %}checked{% endif %} class="rounded border-gray-300 dark:border-none text-proprietary shadow-sm focus:border-blue-300 focus:ring focus:ring-offset-0 focus:ring-blue-200 dark:focus:ring-sky-700 focus:ring-opacity-50">
<span class="ml-2 text-gray-700 dark:text-gray-200">nur FET-Sitzungen</span> <span class="ml-2 text-gray-700 dark:text-gray-200">{{ formset.fet_meeting_only.label }}</span>
</label> </label>
<input type="submit" class="block btn btn-primary" value="Anzeigen" name="btn_input"> <input type="submit" class="block btn btn-primary" value="Anzeigen" name="btn_input">
</form> </form>
@@ -116,7 +117,7 @@
</aside> </aside>
<section class="my-8 sm:my-0 sm:w-3/5 xl:w-2/5 flex flex-col gap-4"> <section class="my-8 sm:my-0 sm:w-3/5 xl:w-2/5 flex flex-col gap-4">
{% if compact_view %} {% if formset.compact_view.value %}
{% for post in posts %} {% for post in posts %}
{% include 'posts/partials/_posts_hero_compact.html' %} {% include 'posts/partials/_posts_hero_compact.html' %}
{% endfor %} {% endfor %}