annoucment logic implemented, fixing looks
This commit is contained in:
@@ -34,6 +34,7 @@ from library.models import (
|
||||
Version,
|
||||
VersionFile,
|
||||
)
|
||||
from announcements.models import Announcement, AnnouncementRead, Notification
|
||||
|
||||
|
||||
def _under_lockout(request):
|
||||
@@ -84,6 +85,26 @@ def home(request):
|
||||
creators = (
|
||||
get_user_model().objects.filter(projects__isnull=False).distinct().count()
|
||||
)
|
||||
|
||||
announcements = (
|
||||
Announcement.objects.filter(published=True)
|
||||
.annotate(comments_count=Count('comments'))
|
||||
.order_by('-created_at', '-pk')[:4]
|
||||
)
|
||||
announcements_total = Announcement.objects.filter(published=True).count()
|
||||
global_read_ids = set()
|
||||
notifications = []
|
||||
unread_notifications = 0
|
||||
if request.user.is_authenticated:
|
||||
global_read_ids = set(
|
||||
AnnouncementRead.objects.filter(user=request.user)
|
||||
.values_list('announcement_id', flat=True)
|
||||
)
|
||||
notifications = list(Notification.objects.filter(user=request.user)[:5])
|
||||
unread_notifications = (
|
||||
Notification.objects.filter(user=request.user, read=False).count()
|
||||
)
|
||||
|
||||
context = {
|
||||
'latest_projects': latest_projects,
|
||||
'stats': {
|
||||
@@ -92,6 +113,11 @@ def home(request):
|
||||
'downloads': total_downloads,
|
||||
'versions': Version.objects.count(),
|
||||
},
|
||||
'announcements': announcements,
|
||||
'announcements_total': announcements_total,
|
||||
'global_read_ids': global_read_ids,
|
||||
'notifications': notifications,
|
||||
'unread_notifications': unread_notifications,
|
||||
}
|
||||
return render(request, 'landing/home.html', context)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user