diff --git a/fet2020/fet2020/views.py b/fet2020/fet2020/views.py index caab4b18..90432738 100644 --- a/fet2020/fet2020/views.py +++ b/fet2020/fet2020/views.py @@ -22,7 +22,7 @@ def index(request): 'posts': posts, 'events': Event.objects.get_five_events(), 'featured_post': featured_post, - 'featured_post2': FetMeeting.objects.first(), + 'featured_meeting': deque(FetMeeting.objects.get_meetings()), 'tags_list': ", ".join(t) } diff --git a/fet2020/posts/models.py b/fet2020/posts/models.py index cfb2a6b9..40087432 100644 --- a/fet2020/posts/models.py +++ b/fet2020/posts/models.py @@ -76,6 +76,24 @@ class FetMeetingManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(Q(post_type='F')) + def _get_last_meeting(self): + date_today = timezone.now() + return self.get_queryset().filter( + Q(event_start__lt=date_today) + ).order_by('-event_start').first() + + def _get_next_meeting(self): + date_today = timezone.now() + return self.get_queryset().filter( + Q(event_start__gt=date_today) + ).order_by('event_start').first() + + def get_meetings(self): + meetings = [] + meetings.append(self._get_next_meeting()) + meetings.append(self._get_last_meeting()) + return meetings + ########## # MODELS # @@ -297,8 +315,9 @@ class FetMeeting(Event): slug = slugify(self.event_start.date()) + "-" + slugify("Fachschaftssitzung") - if Post.objects.filter(slug=slug).count() != 0: - raise ValidationError(_('Es existiert bereits eine Sitzung mit demselben Datum.')) + if Post.objects.filter(slug=slug).exists(): + if Post.objects.get(slug=slug).id != self.id: + raise ValidationError(_('Es existiert bereits eine Sitzung mit demselben Datum.')) def save(self, *args, **kwargs): self.title = "Fachschaftssitzung" diff --git a/fet2020/templates/home.html b/fet2020/templates/home.html index c79ec622..cd5d3f09 100644 --- a/fet2020/templates/home.html +++ b/fet2020/templates/home.html @@ -34,9 +34,9 @@ {% with post=featured_post %} {% include 'posts/partials/_article_row.html' %} {% endwith %} - {% with post=featured_post2 %} - {% include 'posts/partials/_article_row.html' %} - {% endwith %} + {% for post in featured_meeting %} + {% include 'posts/partials/_meeting_row.html' %} + {% endfor %} diff --git a/fet2020/templates/posts/partials/_article_row.html b/fet2020/templates/posts/partials/_article_row.html index d6cf5ce3..55f062ac 100644 --- a/fet2020/templates/posts/partials/_article_row.html +++ b/fet2020/templates/posts/partials/_article_row.html @@ -1,15 +1,12 @@ - -
- +
-

{{post.title}}

- -

{{post.subtitle}}

- - - +

{{post.title}}

+ {% if post.subtitle is not None %} +

{{post.subtitle}}

+ {% endif %} + +
-
- -
\ No newline at end of file +
+ diff --git a/fet2020/templates/posts/partials/_date_box.html b/fet2020/templates/posts/partials/_date_box.html index 63b0adab..a982b693 100644 --- a/fet2020/templates/posts/partials/_date_box.html +++ b/fet2020/templates/posts/partials/_date_box.html @@ -1,10 +1,11 @@ - -
- + +
+ - {{post.event_start_day}} - {{post.event_start_month}} - + {{post.event_start_day}} + {{post.event_start_month}} + + {{post.title}} - -
\ No newline at end of file +
+ diff --git a/fet2020/templates/posts/partials/_meeting_row.html b/fet2020/templates/posts/partials/_meeting_row.html new file mode 100644 index 00000000..7bf9409b --- /dev/null +++ b/fet2020/templates/posts/partials/_meeting_row.html @@ -0,0 +1,11 @@ + +
+
+

{{post.title}}

+ {% if post.subtitle is not None %} +

{{post.subtitle}}

+ {% endif %} + +
+
+