diff --git a/aleksis/core/templates/core/index.html b/aleksis/core/templates/core/index.html index 812c968c6cbda5d3164cb3f86585b76bc1e732b0..a8fbbcbb57b724337062af6d3906486fa0211268 100644 --- a/aleksis/core/templates/core/index.html +++ b/aleksis/core/templates/core/index.html @@ -4,73 +4,75 @@ {% block content %} <p class="flow-text">{% blocktrans %}AlekSIS (School Information System){% endblocktrans %}</p> - {% for notification in unread_notifications %} - <div class="alert primary scale-transition"> - <div> - <i class="material-icons left">info</i> + {% if user.is_authenticated %} + {% for notification in unread_notifications %} + <div class="alert primary scale-transition"> + <div> + <i class="material-icons left">info</i> - <div class="right"> - <a class="btn-flat waves-effect" href="{% url "notification_mark_read" notification.id %}"> - <i class="material-icons center">close</i> - </a> - </div> + <div class="right"> + <a class="btn-flat waves-effect" href="{% url "notification_mark_read" notification.id %}"> + <i class="material-icons center">close</i> + </a> + </div> - <strong>{{ notification.title }}</strong> - <p>{{ notification.description }}</p> + <strong>{{ notification.title }}</strong> + <p>{{ notification.description }}</p> + </div> </div> - </div> - {% endfor %} + {% endfor %} - <div class="row"> - <div class="col s12 m6"> - <h5>{% blocktrans %}Last activities{% endblocktrans %}</h5> + <div class="row"> + <div class="col s12 m6"> + <h5>{% blocktrans %}Last activities{% endblocktrans %}</h5> - {% if activities %} - <ul class="collection"> - {% for activity in activities %} - <li class="collection-item"> - <span class="badge new primary-color">{{ activity.app }}</span> - <span class="title">{{ activity.title }}</span> - <p> - <i class="material-icons left">access_time</i> {{ activity.created_at }} - </p> - <p> - {{ activity.description }} - </p> - </li> - {% endfor %} - </ul> - {% else %} - <p>{% blocktrans %}No activities available yet.{% endblocktrans %}</p> - {% endif %} - </div> + {% if activities %} + <ul class="collection"> + {% for activity in activities %} + <li class="collection-item"> + <span class="badge new primary-color">{{ activity.app }}</span> + <span class="title">{{ activity.title }}</span> + <p> + <i class="material-icons left">access_time</i> {{ activity.created_at }} + </p> + <p> + {{ activity.description }} + </p> + </li> + {% endfor %} + </ul> + {% else %} + <p>{% blocktrans %}No activities available yet.{% endblocktrans %}</p> + {% endif %} + </div> - <div class="col s12 m6"> - <h5>{% blocktrans %}Recent notifications{% endblocktrans %}</h5> + <div class="col s12 m6"> + <h5>{% blocktrans %}Recent notifications{% endblocktrans %}</h5> - {% if notifications %} - <ul class="collection"> - {% for notification in notifications %} - <li class="collection-item"> - <span class="badge new primary-color">{{ notification.app }}</span> - <span class="title">{{ notification.title }}</span> - <p> - <i class="material-icons left">access_time</i> {{ notification.created_at }} - </p> - <p> - {{ notification.description }} - </p> - {% if notification.link %} + {% if notifications %} + <ul class="collection"> + {% for notification in notifications %} + <li class="collection-item"> + <span class="badge new primary-color">{{ notification.app }}</span> + <span class="title">{{ notification.title }}</span> <p> - <a href="{{ notification.link }}">{% blocktrans %}More information →{% endblocktrans %}</a> + <i class="material-icons left">access_time</i> {{ notification.created_at }} </p> - {% endif %} - </li> - {% endfor %} - </ul> - {% else %} - <p>{% blocktrans %}No notifications available yet.{% endblocktrans %}</p> - {% endif %} + <p> + {{ notification.description }} + </p> + {% if notification.link %} + <p> + <a href="{{ notification.link }}">{% blocktrans %}More information →{% endblocktrans %}</a> + </p> + {% endif %} + </li> + {% endfor %} + </ul> + {% else %} + <p>{% blocktrans %}No notifications available yet.{% endblocktrans %}</p> + {% endif %} + </div> </div> - </div> + {% endif %} {% endblock %} diff --git a/aleksis/core/views.py b/aleksis/core/views.py index f96cae5495bbb0664d782b2b69e67c5a2a30857b..eec57c85ea3bdcf1e0a544665c225b5200f6d22c 100644 --- a/aleksis/core/views.py +++ b/aleksis/core/views.py @@ -23,20 +23,23 @@ from .util import messages def index(request: HttpRequest) -> HttpResponse: context = {} - activities = Activity.objects.filter(user=request.user.person).order_by("-created_at")[:5] - - notifications = ( - request.user.person.notifications.all().filter(user=request.user.person).order_by("-created_at")[:5] - ) - unread_notifications = ( - request.user.person.notifications.all() - .filter(user=request.user.person, read=False) - .order_by("-created_at") - ) - - context["activities"] = activities - context["notifications"] = notifications - context["unread_notifications"] = unread_notifications + user = request.user + + if user.is_authenticated: + activities = Activity.objects.filter(user=request.user.person).order_by("-created_at")[:5] + + notifications = ( + request.user.person.notifications.all().filter(user=request.user.person).order_by("-created_at")[:5] + ) + unread_notifications = ( + request.user.person.notifications.all() + .filter(user=request.user.person, read=False) + .order_by("-created_at") + ) + + context["activities"] = activities + context["notifications"] = notifications + context["unread_notifications"] = unread_notifications return render(request, "core/index.html", context)