add searching for posts by date

This commit is contained in:
2021-05-07 11:01:21 +00:00
parent d6de6218c3
commit b314611cdb
6 changed files with 224 additions and 22 deletions

View File

@@ -1,7 +1,8 @@
from django import forms
from django.utils.translation import gettext_lazy as _
from ckeditor_uploader.widgets import CKEditorUploadingWidget
from django import forms
from django.utils import timezone
from django.utils.dates import MONTHS
from django.utils.translation import gettext_lazy as _
from taggit.models import Tag
from .models import Post, Event, News, FetMeeting
@@ -136,24 +137,19 @@ class EventForm(PostForm):
class FetMeetingForm(PostForm):
# agenda_html = forms.CharField(widget = forms.TextInput())
class Meta:
model = FetMeeting
fields = ["event_start", "event_end", "tags"] # , 'has_agenda', 'has_protocol']
fields = ["event_start", "event_end", "tags"]
labels = {
"event_start": _("Start der Sitzung"),
"event_end": _("Ende der Sitzung") # ,
# 'has_agenda': _("Agenda"),
# 'has_protocol': _("Protokoll"),
"event_end": _("Ende der Sitzung"),
}
help_texts = {
"tags": _(
"Die Hashtags ohne '#' eintragen, und mit Komma kann man mehrere Tags anfügen."
) # ,
#'has_agenda': _("Agenda zur Sitzung hinzufügen."),
#'has_protocol': _("Protokoll zur Sitzung hinzufügen."),
),
}
def __init__(self, *args, **kwargs):
@@ -162,10 +158,18 @@ class FetMeetingForm(PostForm):
self.fields["event_start"].required = True
self.fields["event_end"].required = False
# self.fields['has_agenda'].initial = True
# self.fields['has_protocol'].initial = True
tags = []
tags.append(Tag())
tags[0].name = "fachschaft"
self.fields["tags"].initial = tags
class PostSearchForm(forms.Form):
year_of_first_post = Post.objects.get_queryset().last().public_date.year
years = range(year_of_first_post, timezone.now().date().year + 1)
year_choices = [('', _('Alle'))] + [(i, i) for i in years]
month_choices = [('', _('Alle'))] + list(MONTHS.items())
year = forms.ChoiceField(label="Jahr", choices=year_choices, required=False)
month = forms.ChoiceField(label="Monat", choices=month_choices, required=False)