From adb302ebe32d104cdc2e987f993b15e9d8d5f9a4 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 13 Nov 2017 08:54:23 +1100 Subject: [PATCH] Hide likes and replies from the homepage --- entries/kinds.py | 6 +++++- home/views.py | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/entries/kinds.py b/entries/kinds.py index 447454c..315f358 100644 --- a/entries/kinds.py +++ b/entries/kinds.py @@ -1,8 +1,9 @@ class Entry: - def __init__(self, id, plural, icon, slug=False): + def __init__(self, id, plural, icon, on_home=True, slug=False): self.id = id self.plural = plural self.icon = icon + self.on_home = on_home self.slug = slug @property @@ -46,12 +47,14 @@ Reply = Entry( id='reply', icon='fa fa-comment', plural='replies', + on_home=False, ) Like = Entry( id='like', icon='fa fa-heart', plural='likes', + on_home=False, ) Repost = Entry( @@ -61,5 +64,6 @@ Repost = Entry( ) all = (Note, Article, Photo, Reply, Like, Repost) +on_home = (k.id for k in all if k.on_home) from_id = {k.id: k for k in all} from_plural = {k.plural: k for k in all} diff --git a/home/views.py b/home/views.py index 17ff38a..2534a23 100644 --- a/home/views.py +++ b/home/views.py @@ -3,9 +3,11 @@ from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.urls import reverse from users.models import User -from lemoncurry import breadcrumbs, utils from urllib.parse import urljoin +from entries import kinds +from lemoncurry import breadcrumbs, utils + breadcrumbs.add('home:index', 'home') @@ -13,10 +15,11 @@ breadcrumbs.add('home:index', 'home') def index(request): query = User.objects.prefetch_related('entries', 'profiles', 'keys') user = get_object_or_404(query, pk=1) + entries = user.entries.filter(kind__in=kinds.on_home) return { 'user': user, - 'entries': user.entries.all(), + 'entries': entries, 'atom': 'entries:atom', 'rss': 'entries:rss', 'meta': user.as_meta(request),