diff --git a/bookwyrm/models/favorite.py b/bookwyrm/models/favorite.py index 9ab300b3..0f7e2d98 100644 --- a/bookwyrm/models/favorite.py +++ b/bookwyrm/models/favorite.py @@ -1,7 +1,6 @@ """ like/fav/star a status """ from django.apps import apps from django.db import models -from django.utils import timezone from bookwyrm import activitypub from .activitypub_mixin import ActivityMixin @@ -29,8 +28,7 @@ class Favorite(ActivityMixin, BookWyrmModel): def save(self, *args, **kwargs): """update user active time""" - self.user.last_active_date = timezone.now() - self.user.save(broadcast=False, update_fields=["last_active_date"]) + self.user.update_active_date() super().save(*args, **kwargs) if self.status.user.local and self.status.user != self.user: diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 343d3c11..e1090f41 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -2,7 +2,6 @@ from django.core import validators from django.db import models from django.db.models import F, Q -from django.utils import timezone from .base_model import BookWyrmModel @@ -30,8 +29,7 @@ class ReadThrough(BookWyrmModel): def save(self, *args, **kwargs): """update user active time""" - self.user.last_active_date = timezone.now() - self.user.save(broadcast=False, update_fields=["last_active_date"]) + self.user.update_active_date() super().save(*args, **kwargs) def create_update(self): @@ -65,6 +63,5 @@ class ProgressUpdate(BookWyrmModel): def save(self, *args, **kwargs): """update user active time""" - self.user.last_active_date = timezone.now() - self.user.save(broadcast=False, update_fields=["last_active_date"]) + self.user.update_active_date() super().save(*args, **kwargs) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index ad43270c..637baa6e 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -195,6 +195,11 @@ class User(OrderedCollectionPageMixin, AbstractUser): queryset = queryset.exclude(blocks=viewer) return queryset + def update_active_date(self): + """this user is here! they are doing things!""" + self.last_active_date = timezone.now() + self.save(broadcast=False, update_fields=["last_active_date"]) + def to_outbox(self, filter_type=None, **kwargs): """an ordered collection of statuses""" if filter_type: diff --git a/bookwyrm/views/login.py b/bookwyrm/views/login.py index 6c40e4ce..e96d421a 100644 --- a/bookwyrm/views/login.py +++ b/bookwyrm/views/login.py @@ -3,7 +3,6 @@ from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from django.shortcuts import redirect from django.template.response import TemplateResponse -from django.utils import timezone from django.utils.decorators import method_decorator from django.utils.translation import gettext_lazy as _ from django.views import View @@ -54,8 +53,7 @@ class Login(View): if user is not None: # successful login login(request, user) - user.last_active_date = timezone.now() - user.save(broadcast=False, update_fields=["last_active_date"]) + user.update_active_date() if request.POST.get("first_login"): return redirect("get-started-profile") return redirect(request.GET.get("next", "/"))