diff --git a/qgis-app/api/migrations/0001_initial.py b/qgis-app/api/migrations/0001_initial.py index 950f36bf..ba61f5da 100644 --- a/qgis-app/api/migrations/0001_initial.py +++ b/qgis-app/api/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.16 on 2024-09-12 07:16 +# Generated by Django 4.2.16 on 2024-11-18 03:02 from django.conf import settings from django.db import migrations, models @@ -22,9 +22,10 @@ class Migration(migrations.Migration): ('is_blacklisted', models.BooleanField(default=False)), ('is_newly_created', models.BooleanField(default=False)), ('description', models.CharField(blank=True, help_text="Describe this token so that it's easier to remember where you're using it.", max_length=512, null=True, verbose_name='Description')), - ('last_used_on', models.DateTimeField(blank=True, null=True, verbose_name='Last used on')), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')), + ('last_used_at', models.DateTimeField(blank=True, null=True, verbose_name='Last used at')), ('token', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='token_blacklist.outstandingtoken')), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], ), - ] + ] \ No newline at end of file diff --git a/qgis-app/api/models.py b/qgis-app/api/models.py index 6db86a94..3129e17c 100644 --- a/qgis-app/api/models.py +++ b/qgis-app/api/models.py @@ -25,8 +25,12 @@ class UserOutstandingToken(models.Model): blank=True, null=True, ) - last_used_on = models.DateTimeField( - verbose_name=_("Last used on"), + created_at = models.DateTimeField( + verbose_name=_("Created at"), + auto_now_add=True, + ) + last_used_at = models.DateTimeField( + verbose_name=_("Last used at"), blank=True, null=True ) \ No newline at end of file diff --git a/qgis-app/api/permissions.py b/qgis-app/api/permissions.py index 491634ce..bfaa8f02 100644 --- a/qgis-app/api/permissions.py +++ b/qgis-app/api/permissions.py @@ -50,7 +50,7 @@ def has_permission(self, request, view): if not user: return False user_token = UserOutstandingToken.objects.get(token__pk=token_id, user=user) - user_token.last_used_on = datetime.datetime.now() + user_token.last_used_at = datetime.datetime.now() user_token.save() request.user_token = user_token return True diff --git a/qgis-app/api/templates/user_token_list.html b/qgis-app/api/templates/user_token_list.html index c9f42224..705f22b9 100644 --- a/qgis-app/api/templates/user_token_list.html +++ b/qgis-app/api/templates/user_token_list.html @@ -22,9 +22,9 @@

{% trans "My Tokens" %}

{% for user_token in object_list %} {{ user_token.description|default:"-" }} - {{ user_token.token.created_at|local_timezone }} + {{ user_token.created_at|local_timezone }} {% comment %} {{ user_token.token.expires_at|local_timezone }} {% endcomment %} - {{ user_token.last_used_on|default:"-"|local_timezone }} + {{ user_token.last_used_at|default:"-"|local_timezone }}