Skip to content
Snippets Groups Projects
Verified Commit 1b484b4b authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Fix view if person is not authenticated.

parent 5b444ff9
No related branches found
No related tags found
1 merge request!100Resolve "Dashboard"
Pipeline #553 failed
...@@ -4,73 +4,75 @@ ...@@ -4,73 +4,75 @@
{% block content %} {% block content %}
<p class="flow-text">{% blocktrans %}AlekSIS (School Information System){% endblocktrans %}</p> <p class="flow-text">{% blocktrans %}AlekSIS (School Information System){% endblocktrans %}</p>
{% for notification in unread_notifications %} {% if user.is_authenticated %}
<div class="alert primary scale-transition"> {% for notification in unread_notifications %}
<div> <div class="alert primary scale-transition">
<i class="material-icons left">info</i> <div>
<i class="material-icons left">info</i>
<div class="right"> <div class="right">
<a class="btn-flat waves-effect" href="{% url "notification_mark_read" notification.id %}"> <a class="btn-flat waves-effect" href="{% url "notification_mark_read" notification.id %}">
<i class="material-icons center">close</i> <i class="material-icons center">close</i>
</a> </a>
</div> </div>
<strong>{{ notification.title }}</strong> <strong>{{ notification.title }}</strong>
<p>{{ notification.description }}</p> <p>{{ notification.description }}</p>
</div>
</div> </div>
</div> {% endfor %}
{% endfor %}
<div class="row"> <div class="row">
<div class="col s12 m6"> <div class="col s12 m6">
<h5>{% blocktrans %}Last activities{% endblocktrans %}</h5> <h5>{% blocktrans %}Last activities{% endblocktrans %}</h5>
{% if activities %} {% if activities %}
<ul class="collection"> <ul class="collection">
{% for activity in activities %} {% for activity in activities %}
<li class="collection-item"> <li class="collection-item">
<span class="badge new primary-color">{{ activity.app }}</span> <span class="badge new primary-color">{{ activity.app }}</span>
<span class="title">{{ activity.title }}</span> <span class="title">{{ activity.title }}</span>
<p> <p>
<i class="material-icons left">access_time</i> {{ activity.created_at }} <i class="material-icons left">access_time</i> {{ activity.created_at }}
</p> </p>
<p> <p>
{{ activity.description }} {{ activity.description }}
</p> </p>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>{% blocktrans %}No activities available yet.{% endblocktrans %}</p> <p>{% blocktrans %}No activities available yet.{% endblocktrans %}</p>
{% endif %} {% endif %}
</div> </div>
<div class="col s12 m6"> <div class="col s12 m6">
<h5>{% blocktrans %}Recent notifications{% endblocktrans %}</h5> <h5>{% blocktrans %}Recent notifications{% endblocktrans %}</h5>
{% if notifications %} {% if notifications %}
<ul class="collection"> <ul class="collection">
{% for notification in notifications %} {% for notification in notifications %}
<li class="collection-item"> <li class="collection-item">
<span class="badge new primary-color">{{ notification.app }}</span> <span class="badge new primary-color">{{ notification.app }}</span>
<span class="title">{{ notification.title }}</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 %}
<p> <p>
<a href="{{ notification.link }}">{% blocktrans %}More information →{% endblocktrans %}</a> <i class="material-icons left">access_time</i> {{ notification.created_at }}
</p> </p>
{% endif %} <p>
</li> {{ notification.description }}
{% endfor %} </p>
</ul> {% if notification.link %}
{% else %} <p>
<p>{% blocktrans %}No notifications available yet.{% endblocktrans %}</p> <a href="{{ notification.link }}">{% blocktrans %}More information →{% endblocktrans %}</a>
{% endif %} </p>
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<p>{% blocktrans %}No notifications available yet.{% endblocktrans %}</p>
{% endif %}
</div>
</div> </div>
</div> {% endif %}
{% endblock %} {% endblock %}
...@@ -23,20 +23,23 @@ from .util import messages ...@@ -23,20 +23,23 @@ from .util import messages
def index(request: HttpRequest) -> HttpResponse: def index(request: HttpRequest) -> HttpResponse:
context = {} context = {}
activities = Activity.objects.filter(user=request.user.person).order_by("-created_at")[:5] user = request.user
notifications = ( if user.is_authenticated:
request.user.person.notifications.all().filter(user=request.user.person).order_by("-created_at")[:5] activities = Activity.objects.filter(user=request.user.person).order_by("-created_at")[:5]
)
unread_notifications = ( notifications = (
request.user.person.notifications.all() request.user.person.notifications.all().filter(user=request.user.person).order_by("-created_at")[:5]
.filter(user=request.user.person, read=False) )
.order_by("-created_at") unread_notifications = (
) request.user.person.notifications.all()
.filter(user=request.user.person, read=False)
context["activities"] = activities .order_by("-created_at")
context["notifications"] = notifications )
context["unread_notifications"] = unread_notifications
context["activities"] = activities
context["notifications"] = notifications
context["unread_notifications"] = unread_notifications
return render(request, "core/index.html", context) return render(request, "core/index.html", context)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment