add searching for posts by date
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -25,6 +25,38 @@ class PostManager(models.Manager):
|
||||
|
||||
return posts
|
||||
|
||||
def get_date_filtered_list(self, year=None, month=None, fet_meeting_only=None):
|
||||
post_list = []
|
||||
|
||||
if not fet_meeting_only:
|
||||
posts = self.get_visible_articles().filter(~Q(post_type="N"))
|
||||
else:
|
||||
posts = self.get_visible_articles().filter(post_type="F")
|
||||
|
||||
if year:
|
||||
posts = posts.filter(event_start__year=year)
|
||||
if month:
|
||||
posts = posts.filter(event_start__month=month)
|
||||
|
||||
for post in posts:
|
||||
post_list.append((post, post.event_start.date()))
|
||||
|
||||
if not fet_meeting_only:
|
||||
posts = self.get_visible_articles().filter(post_type="N")
|
||||
|
||||
if year:
|
||||
posts = posts.filter(public_date__year=year)
|
||||
if month:
|
||||
posts = posts.filter(public_date__month=month)
|
||||
|
||||
for post in posts:
|
||||
post_list.append((post, post.public_date))
|
||||
|
||||
result = sorted(post_list, key=lambda x: x[1], reverse=True)
|
||||
posts = [x[0] for x in result]
|
||||
|
||||
return posts
|
||||
|
||||
def get_last_months_posts(self):
|
||||
date_today = timezone.now().date()
|
||||
return self.get_visible_articles().filter(
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
|
||||
from collections import deque
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponse, JsonResponse, HttpResponseServerError
|
||||
from django.shortcuts import render
|
||||
from django.template.loader import render_to_string
|
||||
@@ -13,6 +14,7 @@ from documents.api import get_pad_link
|
||||
from documents.etherpadlib import add_ep_cookie
|
||||
from members.models import Member, JobMember
|
||||
|
||||
from .forms import PostSearchForm
|
||||
from .models import Post, FetMeeting, FileUpload
|
||||
from .utils import render_to_pdf
|
||||
|
||||
@@ -26,13 +28,55 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def index(request):
|
||||
"Index von aktuellen Posts"
|
||||
posts = deque(Post.objects.get_date_sorted_list())
|
||||
posts = None
|
||||
taglist = None
|
||||
|
||||
taglist = map(lambda post: post.tags, posts)
|
||||
compact_view = None
|
||||
fet_meeting_only = None
|
||||
|
||||
return render(request, "posts/index.html", {"posts": posts, "tags_list": taglist})
|
||||
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
|
||||
|
||||
if not year and month:
|
||||
messages.info(
|
||||
request,
|
||||
"Es kann nicht nur nach einem Monat gesucht werden."
|
||||
)
|
||||
|
||||
posts = deque(Post.objects.get_date_filtered_list(year, month, fet_meeting_only))
|
||||
else:
|
||||
form = PostSearchForm()
|
||||
posts = deque(Post.objects.get_date_sorted_list())
|
||||
|
||||
if posts:
|
||||
taglist = map(lambda post: post.tags, posts)
|
||||
|
||||
context = {
|
||||
"formset": form,
|
||||
"compact_view": compact_view,
|
||||
"fet_meeting_only": fet_meeting_only,
|
||||
"posts": posts,
|
||||
"tags_list": taglist,
|
||||
}
|
||||
|
||||
return render(request, "posts/index.html", context)
|
||||
|
||||
def calendar(request):
|
||||
"Kalender Ansicht ICS zur Verknüpfung mit Outlook"
|
||||
|
||||
@@ -150,3 +150,68 @@ a.thumbnail img {
|
||||
height: 40px; }
|
||||
.social-media-footer .social-media-footer-symbol {
|
||||
font-size:30px; }
|
||||
|
||||
.news-hero-compact {
|
||||
border-radius: 5px;
|
||||
margin-top: 1rem !important;
|
||||
margin-bottom: 1rem !important;
|
||||
font-size: 18px;
|
||||
height: 10vh; }
|
||||
@media print, screen and (min-width: 40em) {
|
||||
.news-hero-compact {
|
||||
height: 10vh; } }
|
||||
@media print, screen and (min-width: 64em) {
|
||||
.news-hero-compact {
|
||||
height: 10vh; } }
|
||||
|
||||
.news-hero-compact-large {
|
||||
height: 100%;
|
||||
min-height: 10vh; }
|
||||
@media print, screen and (min-width: 40em) {
|
||||
.news-hero-compact-large {
|
||||
min-height: 10vh 0.7; } }
|
||||
@media print, screen and (min-width: 64em) {
|
||||
.news-hero-compact-large {
|
||||
min-height: 10vh; } }
|
||||
|
||||
.news-hero-compact, .news-hero-compact-large {
|
||||
background-color: #444;
|
||||
position: relative;
|
||||
background-size: cover;
|
||||
-webkit-box-align: center;
|
||||
-webkit-align-items: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
-webkit-box-pack: center;
|
||||
-webkit-justify-content: center;
|
||||
-ms-flex-pack: center;
|
||||
justify-content: center;
|
||||
vertical-align: middle;
|
||||
text-align: left;
|
||||
display: -webkit-box;
|
||||
display: -webkit-flex;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
width: 100%; }
|
||||
.news-hero-compact .news-hero-compact-text, .news-hero-compact-large .news-hero-compact-text {
|
||||
position: absolute;
|
||||
left: 5%;
|
||||
color: #fefefe;
|
||||
text-shadow: 1px 1px 2px #000, 0px 0px 5px #000, 0px 0px 25px #000; }
|
||||
@media print, screen and (min-width: 40em) {
|
||||
.news-hero-compact .news-hero-compact-text, .news-hero-compact-large .news-hero-compact-text {
|
||||
left: 5%; } }
|
||||
@media print, screen and (min-width: 64em) {
|
||||
.news-hero-compact .news-hero-compact-text, .news-hero-compact-large .news-hero-compact-text {
|
||||
left: 5%; } }
|
||||
.news-hero-compact .news-hero-compact-right, .news-hero-compact-large .news-hero-compact-right {
|
||||
position: absolute;
|
||||
right: 5%;
|
||||
color: #fefefe;
|
||||
text-shadow: 1px 1px 2px #000, 0px 0px 5px #000, 0px 0px 25px #000; }
|
||||
@media print, screen and (min-width: 40em) {
|
||||
.news-hero-compact .news-hero-compact-right, .news-hero-compact-large .news-hero-compact-right {
|
||||
right: 5%; } }
|
||||
@media print, screen and (min-width: 64em) {
|
||||
.news-hero-compact .news-hero-compact-right, .news-hero-compact-large .news-hero-compact-right {
|
||||
right: 5%; } }
|
||||
|
||||
@@ -3,12 +3,55 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="grid-container">
|
||||
<div class="grid-x">
|
||||
<div class="medium-8 cell">
|
||||
{% for post in posts %}
|
||||
{% include 'posts/partials/_posts_hero.html' %}
|
||||
<div class="grid-x grid-margin-x">
|
||||
<div class="cell medium-8">
|
||||
{% for message in messages %}
|
||||
<p id="messages" style="background-color: red">{{message}}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="grid-x grid-margin-x padding-top-1">
|
||||
|
||||
{{ formset.management_form }}
|
||||
|
||||
{% for form in formset %}
|
||||
<div class="cell medium-3 large-2 small-10">
|
||||
{{ form.label }}
|
||||
{{ form }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="cell medium-3 large-2 small-10 align-self-middle">
|
||||
<input type="checkbox" id="compact_view" name="checkbox" value="compact_view" {% if compact_view %} checked {% endif %}>
|
||||
<label for="compact_view">kompakte Ansicht</label>
|
||||
|
||||
<input type="checkbox" id="fet_meeting_only" name="checkbox" value="fet_meeting_only" {% if fet_meeting_only %} checked {% endif %}>
|
||||
<label for="fet_meeting_only">nur FET Sitzung</label>
|
||||
</div>
|
||||
|
||||
<div class="cell medium-3 large-2 small-10 align-self-bottom">
|
||||
<input type="submit" class="button" name="btn_input" value="Suchen">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="grid-x">
|
||||
<div class="cell medium-8">
|
||||
|
||||
{% if compact_view %}
|
||||
{% for post in posts %}
|
||||
{% include 'posts/partials/_posts_hero_compact.html' %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for post in posts %}
|
||||
{% include 'posts/partials/_posts_hero.html' %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
14
fet2020/templates/posts/partials/_posts_hero_compact.html
Normal file
14
fet2020/templates/posts/partials/_posts_hero_compact.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<a href="{% url 'posts.show' post.slug %}">
|
||||
<div class="news-hero-compact">
|
||||
<div class="news-hero-compact-text">
|
||||
<p style="margin-bottom: 0rem;">{{ post.title | safe }}</p>
|
||||
</div>
|
||||
<div class="news-hero-compact-right">
|
||||
{% if post.post_type != 'N' %}
|
||||
<p style="margin-bottom: 0rem;">{{ post.event_start|date:"d. F Y" }}</p>
|
||||
{% else %}
|
||||
<p style="margin-bottom: 0rem;">{{ post.public_date|date:"d. F Y" }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
Reference in New Issue
Block a user