See #890: Ensure report handled_date is populated automatically when handling the report

This commit is contained in:
Eliot Berriot 2019-08-26 14:47:01 +02:00
commit 177f06cf2a
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
2 changed files with 32 additions and 1 deletions

View file

@ -6,13 +6,14 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.urls import reverse
from django.utils import timezone
from funkwhale_api.federation import models as federation_models
from funkwhale_api.federation import utils as federation_utils
class InstancePolicyQuerySet(models.QuerySet):
def active(self):
return self.filter(is_active=True)
@ -160,3 +161,11 @@ class Report(federation_models.FederationMixin):
self.fid = self.get_federation_id()
return super().save(**kwargs)
@receiver(pre_save, sender=Report)
def set_handled_date(sender, instance, **kwargs):
if instance.is_handled is True and not instance.handled_date:
instance.handled_date = timezone.now()
elif not instance.is_handled:
instance.handled_date = None