Changeset View
Changeset View
Standalone View
Standalone View
profiles/views/activity.py
- This file was added.
| """Profile activity pages, such as notifications and My activity.""" | |||||
| from django.shortcuts import render | |||||
| from django.contrib.auth import get_user_model | |||||
| from django.contrib.auth.decorators import login_required | |||||
| from django.contrib.auth.mixins import LoginRequiredMixin | |||||
| from django.contrib.contenttypes.models import ContentType | |||||
| from django.db.models.query import QuerySet | |||||
| from django.views.generic import ListView | |||||
| from actstream import models | |||||
| from profiles.models import Notification | |||||
| USER_MODEL = get_user_model() | |||||
| class Notifications(LoginRequiredMixin, ListView): | |||||
| """Display notifications for an authenticated user.""" | |||||
| context_object_name = 'notifications' | |||||
| model = Notification | |||||
| paginate_by = 10 | |||||
| template_name_suffix = 's' | |||||
| def get_queryset(self) -> QuerySet: | |||||
| """Return user notifications instead of all notifications.""" | |||||
| return self.request.user.profile.notifications | |||||
| @login_required | |||||
| def activity(request): | |||||
| """Display latest activity of an authenticated user.""" | |||||
| return render( | |||||
| request, | |||||
| 'profiles/activity.html', | |||||
| context={ | |||||
| 'ctype': ContentType.objects.get_for_model(USER_MODEL), | |||||
| 'actor': request.user, | |||||
| 'action_list': models.actor_stream(request.user), | |||||
| }, | |||||
| ) | |||||