Updated expires_at for null, blank False, lte query update, admin expiration logic simplify

This commit is contained in:
kuldeepkhatke 2025-06-10 20:33:56 +05:30 committed by Aleksi Häkli
parent 01ccf5b213
commit ba7b72f9d9
4 changed files with 4 additions and 10 deletions

View file

@ -56,9 +56,7 @@ class AccessAttemptAdmin(admin.ModelAdmin):
return False return False
def expiration(self, obj: AccessAttempt): def expiration(self, obj: AccessAttempt):
if hasattr(obj, "expiration") and obj.expiration.expires_at: return obj.expiration.expires_at if hasattr(obj, "expiration") else _("Not set")
return obj.expiration.expires_at
return _("Not set")
class AccessLogAdmin(admin.ModelAdmin): class AccessLogAdmin(admin.ModelAdmin):
list_display = ( list_display = (

View file

@ -400,7 +400,7 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
if settings.AXES_USE_ATTEMPT_EXPIRATION: if settings.AXES_USE_ATTEMPT_EXPIRATION:
threshold = timezone.now() threshold = timezone.now()
count, _ = AccessAttempt.objects.filter(expiration__expires_at__lt=threshold).delete() count, _ = AccessAttempt.objects.filter(expiration__expires_at__lte=threshold).delete()
log.info( log.info(
"AXES: Cleaned up %s expired access attempts from database that expiry were older than %s", "AXES: Cleaned up %s expired access attempts from database that expiry were older than %s",
count, count,
@ -408,7 +408,7 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
) )
else: else:
threshold = get_cool_off_threshold(request) threshold = get_cool_off_threshold(request)
count, _ = AccessAttempt.objects.filter(attempt_time__lt=threshold).delete() count, _ = AccessAttempt.objects.filter(attempt_time__lte=threshold).delete()
log.info( log.info(
"AXES: Cleaned up %s expired access attempts from database that were older than %s", "AXES: Cleaned up %s expired access attempts from database that were older than %s",
count, count,

View file

@ -1,4 +1,4 @@
# Generated by Django 5.2.1 on 2025-06-08 12:44 # Generated by Django 5.2.1 on 2025-06-10 20:21
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models from django.db import migrations, models
@ -28,9 +28,7 @@ class Migration(migrations.Migration):
( (
"expires_at", "expires_at",
models.DateTimeField( models.DateTimeField(
blank=True,
help_text="The time when access attempt expires and is no longer valid.", help_text="The time when access attempt expires and is no longer valid.",
null=True,
verbose_name="Expires At", verbose_name="Expires At",
), ),
), ),

View file

@ -61,8 +61,6 @@ class AccessAttemptExpiration(models.Model):
) )
expires_at = models.DateTimeField( expires_at = models.DateTimeField(
_("Expires At"), _("Expires At"),
null=True,
blank=True,
help_text=_("The time when access attempt expires and is no longer valid."), help_text=_("The time when access attempt expires and is no longer valid."),
) )