simplify Posts Search Form
This commit is contained in:
@@ -2,6 +2,7 @@ from ckeditor_uploader.widgets import CKEditorUploadingWidget
|
||||
from taggit.models import Tag
|
||||
|
||||
from django import forms
|
||||
from django.forms.widgets import CheckboxInput
|
||||
from django.utils import timezone
|
||||
from django.utils.dates import MONTHS
|
||||
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)
|
||||
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):
|
||||
super().__init__(*args, **kwargs) # to get the self.fields set
|
||||
|
||||
|
||||
@@ -22,43 +22,16 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def index(request):
|
||||
posts = None
|
||||
|
||||
compact_view = None
|
||||
fet_meeting_only = None
|
||||
|
||||
public_only = not request.user.is_authenticated
|
||||
|
||||
if request.method == "POST":
|
||||
if "btn_input" in request.POST:
|
||||
form = PostSearchForm(request.POST)
|
||||
|
||||
if "compact_view" in request.POST.getlist("checkbox"):
|
||||
compact_view = True
|
||||
|
||||
if "fet_meeting_only" in request.POST.getlist("checkbox"):
|
||||
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,
|
||||
form.cleaned_data["year"],
|
||||
form.cleaned_data["month"],
|
||||
form.cleaned_data["fet_meeting_only"],
|
||||
)
|
||||
else:
|
||||
last_year = Post.objects.get_queryset().first()
|
||||
@@ -83,8 +56,6 @@ def index(request):
|
||||
|
||||
context = {
|
||||
"formset": form,
|
||||
"compact_view": compact_view,
|
||||
"fet_meeting_only": fet_meeting_only,
|
||||
"posts": posts,
|
||||
}
|
||||
|
||||
|
||||
@@ -89,13 +89,14 @@
|
||||
</select>
|
||||
</label>
|
||||
<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">
|
||||
<span class="ml-2 text-gray-700 dark:text-gray-200">Kompakte Ansicht</span>
|
||||
<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">{{ formset.compact_view.label }}</span>
|
||||
</label>
|
||||
<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">
|
||||
<span class="ml-2 text-gray-700 dark:text-gray-200">nur FET-Sitzungen</span>
|
||||
<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">{{ formset.fet_meeting_only.label }}</span>
|
||||
</label>
|
||||
|
||||
<input type="submit" class="block btn btn-primary" value="Anzeigen" name="btn_input">
|
||||
</form>
|
||||
|
||||
@@ -116,7 +117,7 @@
|
||||
</aside>
|
||||
|
||||
<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 %}
|
||||
{% include 'posts/partials/_posts_hero_compact.html' %}
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user