mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 11:59:18 +02:00
See #170: store and compute modification date on artists
This commit is contained in:
parent
b5297150f0
commit
1654044a9f
12 changed files with 85 additions and 7 deletions
|
@ -1,3 +1,5 @@
|
|||
import datetime
|
||||
|
||||
from django.core.files.base import ContentFile
|
||||
from django.utils.deconstruct import deconstructible
|
||||
|
||||
|
@ -14,6 +16,7 @@ from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit
|
|||
from django.conf import settings
|
||||
from django import urls
|
||||
from django.db import models, transaction
|
||||
from django.utils import timezone
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -405,3 +408,17 @@ def get_mimetype_from_ext(path):
|
|||
def get_audio_mimetype(mt):
|
||||
aliases = {"audio/x-mp3": "audio/mpeg", "audio/mpeg3": "audio/mpeg"}
|
||||
return aliases.get(mt, mt)
|
||||
|
||||
|
||||
def update_modification_date(obj, field="modification_date"):
|
||||
IGNORE_DELAY = 60
|
||||
current_value = getattr(obj, field)
|
||||
now = timezone.now()
|
||||
ignore = current_value is not None and current_value < now - datetime.timedelta(
|
||||
seconds=IGNORE_DELAY
|
||||
)
|
||||
if ignore:
|
||||
setattr(obj, field, now)
|
||||
obj.__class__.objects.filter(pk=obj.pk).update(**{field: now})
|
||||
|
||||
return now
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue