switch media.can_download flag to a db value
This commit is contained in:
parent
c31ed0af28
commit
35bd26727b
|
@ -15,6 +15,6 @@ class SourceAdmin(admin.ModelAdmin):
|
||||||
class MediaAdmin(admin.ModelAdmin):
|
class MediaAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
ordering = ('-created',)
|
ordering = ('-created',)
|
||||||
list_display = ('key', 'source')
|
list_display = ('key', 'source', 'can_download', 'downloaded')
|
||||||
readonly_fields = ('uuid', 'created')
|
readonly_fields = ('uuid', 'created')
|
||||||
search_fields = ('uuid', 'source__key', 'key')
|
search_fields = ('uuid', 'source__key', 'key')
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.1.4 on 2020-12-09 08:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('sync', '0017_auto_20201208_0521'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='media',
|
||||||
|
name='can_download',
|
||||||
|
field=models.BooleanField(db_index=True, default=False, help_text='Media has a matching format and can be downloaded', verbose_name='can download'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -439,6 +439,12 @@ class Media(models.Model):
|
||||||
null=True,
|
null=True,
|
||||||
help_text=_('JSON encoded metadata for the media')
|
help_text=_('JSON encoded metadata for the media')
|
||||||
)
|
)
|
||||||
|
can_download = models.BooleanField(
|
||||||
|
_('can download'),
|
||||||
|
db_index=True,
|
||||||
|
default=False,
|
||||||
|
help_text=_('Media has a matching format and can be downloaded')
|
||||||
|
)
|
||||||
downloaded = models.BooleanField(
|
downloaded = models.BooleanField(
|
||||||
_('downloaded'),
|
_('downloaded'),
|
||||||
db_index=True,
|
db_index=True,
|
||||||
|
@ -538,14 +544,6 @@ class Media(models.Model):
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
|
||||||
def can_download(self):
|
|
||||||
'''
|
|
||||||
Returns boolean True if the media can be downloaded, that is, the media
|
|
||||||
has stored formats which are compatible with the source requirements.
|
|
||||||
'''
|
|
||||||
return self.get_format_str() is not False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def loaded_metadata(self):
|
def loaded_metadata(self):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -46,6 +46,10 @@ def source_post_save(sender, instance, created, **kwargs):
|
||||||
queue=str(instance.pk),
|
queue=str(instance.pk),
|
||||||
verbose_name=verbose_name.format(instance.name)
|
verbose_name=verbose_name.format(instance.name)
|
||||||
)
|
)
|
||||||
|
# Trigger the post_save signal for each media item linked to this source as various
|
||||||
|
# flags may need to be recalculated
|
||||||
|
for media in Media.objects.filter(source=instance):
|
||||||
|
media.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete, sender=Source)
|
@receiver(pre_delete, sender=Source)
|
||||||
|
@ -91,6 +95,16 @@ def media_post_save(sender, instance, created, **kwargs):
|
||||||
queue=str(instance.source.pk),
|
queue=str(instance.source.pk),
|
||||||
verbose_name=verbose_name.format(instance.name)
|
verbose_name=verbose_name.format(instance.name)
|
||||||
)
|
)
|
||||||
|
# Recalculate the "can_download" flag, this may need to change if the source
|
||||||
|
# specifications have been changed
|
||||||
|
if instance.get_format_str():
|
||||||
|
if not instance.can_download:
|
||||||
|
instance.can_download = True
|
||||||
|
instance.save()
|
||||||
|
else:
|
||||||
|
if instance.can_download:
|
||||||
|
instance.can_download = True
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete, sender=Media)
|
@receiver(pre_delete, sender=Media)
|
||||||
|
|
Loading…
Reference in New Issue