Skip to content

Commit

Permalink
Add first_active field to BlossomUser model
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Jun 13, 2021
1 parent 8d7fb71 commit df92a18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Meta:
"id",
"username",
"gamma",
"date_joined",
"first_active",
"last_login",
"last_update_time",
"accepted_coc",
Expand Down
20 changes: 20 additions & 0 deletions authentication/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Models used within the Authentication application."""
import datetime
from typing import Optional

from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone
Expand Down Expand Up @@ -58,6 +61,23 @@ def gamma(self) -> int:
return 0 # see https://github.com/GrafeasGroup/blossom/issues/15
return Submission.objects.filter(completed_by=self).count()

@property
def first_active(self) -> Optional[datetime.datetime]:
"""
Return the date when the user was first active.
Usually, this is the date of their first transcription.
:return: the date when the user was first active or None if they haven't
transcribed yet.
"""
return (
Submission.objects.filter(claimed_by=self)
.order_by("claim_time")
.first()
.claim_time
)

def __str__(self) -> str:
return self.username

Expand Down

0 comments on commit df92a18

Please sign in to comment.