Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Reduce frivolous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Dec 13, 2022
1 parent 830d73e commit a6e3759
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 164 deletions.
21 changes: 6 additions & 15 deletions api/catalog/api/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ class AudioAdmin(admin.ModelAdmin):


class MediaReportAdmin(admin.ModelAdmin):
list_display = ("reason", "status", "description", "created_on")
list_display = ("reason", "status", "description", "created_at")
media_specific_list_display = ()
list_filter = ("status", "reason")
list_display_links = ("status",)
search_fields = (
"description",
"media_obj_id",
)
search_fields = ("description", "media_obj_id")
autocomplete_fields = ("media_obj",)
actions = None

Expand All @@ -52,7 +49,7 @@ def get_readonly_fields(self, request, obj=None):
"reason",
"description",
"media_obj_id",
"created_on",
"created_at",
]
if obj.status == PENDING:
return always_readonly
Expand All @@ -73,15 +70,9 @@ class AudioReportAdmin(MediaReportAdmin):


class MediaSubreportAdmin(admin.ModelAdmin):
exclude = [
"media_obj",
]
search_fields = [
"media_obj_id",
]
readonly_fields = [
"media_obj_id",
]
exclude = ("media_obj",)
search_fields = ("media_obj_id",)
readonly_fields = ("media_obj_id",)

def has_add_permission(self, *args, **kwargs):
"""Create ``_Report`` instances instead."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,6 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RenameField(
model_name='imagereport',
old_name='created_at',
new_name='created_on',
),
migrations.RenameField(
model_name='audioreport',
old_name='created_at',
new_name='created_on',
),
migrations.AddField(
model_name='imagereport',
name='updated_on',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='audioreport',
name='updated_on',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='matureimage',
name='updated_on',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='matureaudio',
name='updated_on',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='deletedimage',
name='identifier',
Expand Down Expand Up @@ -86,37 +56,37 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='imagereport',
name='media_obj',
field=models.ForeignKey(db_constraint=False, null=True, help_text="The foreign key to the 'Image' being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.image', to_field='identifier'),
field=models.ForeignKey(db_constraint=False, null=True, related_name="image_report", help_text="The reference to the image being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.image', to_field='identifier'),
preserve_default=False,
),
migrations.AddField(
model_name='deletedimage',
name='media_obj',
field=models.OneToOneField(db_constraint=False, null=True, help_text="The foreign key from this model to the 'Image' model.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.image', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, null=True, related_name="deleted_image", help_text="The reference to the deleted image.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.image', to_field='identifier'),
preserve_default=False,
),
migrations.AddField(
model_name='matureimage',
name='media_obj',
field=models.OneToOneField(db_constraint=False, null=True, help_text="The foreign key from this model to the 'Image' model.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.image', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, null=True, related_name="mature_image", help_text="The reference to the mature image.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.image', to_field='identifier'),
preserve_default=False,
),
migrations.AddField(
model_name='audioreport',
name='media_obj',
field=models.ForeignKey(db_constraint=False, null=True, help_text="The foreign key to the 'Audio' being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.audio', to_field='identifier'),
field=models.ForeignKey(db_constraint=False, null=True, related_name="audio_report", help_text="The reference to the audio being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.audio', to_field='identifier'),
preserve_default=False,
),
migrations.AddField(
model_name='deletedaudio',
name='media_obj',
field=models.OneToOneField(db_constraint=False, null=True, help_text="The foreign key of this model to the 'Audio' model.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.audio', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, null=True, related_name="deleted_audio", help_text="The reference to the deleted audio.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.audio', to_field='identifier'),
preserve_default=False,
),
migrations.AddField(
model_name='matureaudio',
name='media_obj',
field=models.OneToOneField(db_constraint=False, null=True, help_text="The foreign key of this model to the 'Audio' model.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.audio', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, null=True, related_name="mature_audio", help_text="The reference to the mature audio.", on_delete=django.db.models.deletion.DO_NOTHING, serialize=False, to='api.audio', to_field='identifier'),
preserve_default=False,
),
migrations.RunSQL(
Expand All @@ -126,34 +96,34 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='imagereport',
name='media_obj',
field=models.ForeignKey(db_constraint=False, help_text="The foreign key to the 'Image' being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.image', to_field='identifier'),
field=models.ForeignKey(db_constraint=False, related_name="image_report", help_text="The reference to the image being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.image', to_field='identifier'),
preserve_default=False,
),
migrations.AlterField(
model_name='deletedimage',
name='media_obj',
field=models.OneToOneField(db_constraint=False, help_text="The foreign key from this model to the 'Image' model.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.image', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, related_name="deleted_image", help_text="The reference to the deleted image.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.image', to_field='identifier'),
),
migrations.AlterField(
model_name='matureimage',
name='media_obj',
field=models.OneToOneField(db_constraint=False, help_text="The foreign key from this model to the 'Image' model.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.image', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, related_name="mature_image", help_text="The reference to the mature image.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.image', to_field='identifier'),
),
migrations.AlterField(
model_name='audioreport',
name='media_obj',
field=models.ForeignKey(db_constraint=False, help_text="The foreign key to the 'Audio' being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.audio', to_field='identifier'),
field=models.ForeignKey(db_constraint=False, related_name="audio_report", help_text="The reference to the audio being reported.", on_delete=django.db.models.deletion.DO_NOTHING, to='api.audio', to_field='identifier'),
preserve_default=False,
),
migrations.AlterField(
model_name='deletedaudio',
name='media_obj',
field=models.OneToOneField(db_constraint=False, help_text="The foreign key of this model to the 'Audio' model.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.audio', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, related_name="deleted_audio", help_text="The reference to the deleted audio.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.audio', to_field='identifier'),
),
migrations.AlterField(
model_name='matureaudio',
name='media_obj',
field=models.OneToOneField(db_constraint=False, help_text="The foreign key of this model to the 'Audio' model.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.audio', to_field='identifier'),
field=models.OneToOneField(db_constraint=False, related_name="mature_audio", help_text="The reference to the mature audio.", on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='api.audio', to_field='identifier'),
),
migrations.RemoveField(
model_name='imagereport',
Expand All @@ -179,4 +149,9 @@ class Migration(migrations.Migration):
model_name='matureaudio',
name='identifier',
),
migrations.AddField(
model_name='audio',
name='audioset',
field=models.ForeignObject(from_fields=('audio_set_foreign_identifier', 'provider'), null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api.audioset', to_fields=('foreign_identifier', 'provider')),
),
]
19 changes: 0 additions & 19 deletions api/catalog/api/migrations/0053_audio_audioset.py

This file was deleted.

51 changes: 25 additions & 26 deletions api/catalog/api/models/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from catalog.api.constants.media_types import AUDIO_TYPE
from catalog.api.models import OpenLedgerModel
from catalog.api.models.media import (
AbstractAbstractMediaRelation,
AbstractAltFile,
AbstractDeletedMedia,
AbstractMatureMedia,
Expand Down Expand Up @@ -187,7 +186,7 @@ class Audio(AudioFileMixin, AbstractMedia):

@property
def mature(self) -> bool:
return hasattr(self, "matureaudio")
return hasattr(self, "mature_audio")

@property
def alternative_files(self):
Expand Down Expand Up @@ -230,41 +229,30 @@ class Meta(AbstractMedia.Meta):
db_table = "audio"


class AbstractAudioRelation(AbstractAbstractMediaRelation):
class DeletedAudio(AbstractDeletedMedia):
"""
This class should be inherited by models aiming to have a one-to-one mapping with
`Audio` instances. Note that the mapping is not enforced at the DB level so that
mature reports can continue to exist even if the related `Audio` object has been
deleted.
Stores identifiers of audio tracks that have been deleted from the source. Do not
create instances of this model manually. Create an ``AudioReport`` instance instead.
"""

media_class = Audio
es_index = settings.MEDIA_INDEX_MAPPING[AUDIO_TYPE]

media_obj = models.OneToOneField(
primary_key=True,
to="Audio",
to_field="identifier",
db_constraint=False,
on_delete=models.DO_NOTHING,
help_text="The foreign key of this model to the 'Audio' model.",
primary_key=True,
db_constraint=False,
related_name="deleted_audio",
help_text="The reference to the deleted audio.",
)

class Meta:
abstract = True


class DeletedAudio(AbstractAudioRelation, AbstractDeletedMedia):
"""
Stores identifiers of audio tracks that have been deleted from the source. Do not
create instances of this model manually. Create an ``AudioReport`` instance instead.
"""

media_class = Audio
es_index = settings.MEDIA_INDEX_MAPPING[AUDIO_TYPE]

class Meta:
verbose_name_plural = "Deleted audio"


class MatureAudio(AbstractAudioRelation, AbstractMatureMedia):
class MatureAudio(AbstractMatureMedia):
"""
Stores all audio tracks that have been flagged as 'mature'. Do not create instances
of this model manually. Create an ``AudioReport`` instance instead.
Expand All @@ -273,6 +261,16 @@ class MatureAudio(AbstractAudioRelation, AbstractMatureMedia):
media_class = Audio
es_index = settings.MEDIA_INDEX_MAPPING[AUDIO_TYPE]

media_obj = models.OneToOneField(
to="Audio",
to_field="identifier",
on_delete=models.DO_NOTHING,
primary_key=True,
db_constraint=False,
related_name="mature_audio",
help_text="The reference to the mature audio.",
)

class Meta:
verbose_name_plural = "Mature audio"

Expand All @@ -285,9 +283,10 @@ class AudioReport(AbstractMediaReport):
media_obj = models.ForeignKey(
to="Audio",
to_field="identifier",
db_constraint=False,
on_delete=models.DO_NOTHING,
help_text="The foreign key to the 'Audio' being reported.",
db_constraint=False,
related_name="audio_report",
help_text="The reference to the audio being reported.",
)

class Meta:
Expand Down
51 changes: 25 additions & 26 deletions api/catalog/api/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from catalog.api.constants.media_types import IMAGE_TYPE
from catalog.api.models.media import (
AbstractAbstractMediaRelation,
AbstractDeletedMedia,
AbstractMatureMedia,
AbstractMedia,
Expand Down Expand Up @@ -52,41 +51,30 @@ class Meta(AbstractMedia.Meta):

@property
def mature(self) -> bool:
return hasattr(self, "matureimage")
return hasattr(self, "mature_image")


class AbstractImageRelation(AbstractAbstractMediaRelation):
class DeletedImage(AbstractDeletedMedia):
"""
This class should be inherited by models aiming to have a one-to-one mapping with
`Audio` instances. Note that the mapping is not enforced at the DB level so that
mature reports can continue to exist even if the related `Audio` object has been
deleted.
Stores identifiers of images that have been deleted from the source. Do not create
instances of this model manually. Create an ``ImageReport`` instance instead.
"""

media_class = Image
es_index = settings.MEDIA_INDEX_MAPPING[IMAGE_TYPE]

media_obj = models.OneToOneField(
primary_key=True,
to="Image",
to_field="identifier",
db_constraint=False,
on_delete=models.DO_NOTHING,
help_text="The foreign key from this model to the 'Image' model.",
primary_key=True,
db_constraint=False,
related_name="deleted_image",
help_text="The reference to the deleted image.",
)

class Meta:
abstract = True


class DeletedImage(AbstractImageRelation, AbstractDeletedMedia):
"""
Stores identifiers of images that have been deleted from the source. Do not create
instances of this model manually. Create an ``ImageReport`` instance instead.
"""

media_class = Image
es_index = settings.MEDIA_INDEX_MAPPING[IMAGE_TYPE]


class MatureImage(AbstractImageRelation, AbstractMatureMedia):
class MatureImage(AbstractMatureMedia):
"""
Stores all images that have been flagged as 'mature'. Do not create instances of
this model manually. Create an ``ImageReport`` instance instead.
Expand All @@ -95,6 +83,16 @@ class MatureImage(AbstractImageRelation, AbstractMatureMedia):
media_class = Image
es_index = settings.MEDIA_INDEX_MAPPING[IMAGE_TYPE]

media_obj = models.OneToOneField(
to="Image",
to_field="identifier",
on_delete=models.DO_NOTHING,
primary_key=True,
db_constraint=False,
related_name="mature_image",
help_text="The reference to the mature image.",
)


class ImageReport(AbstractMediaReport):
media_class = Image
Expand All @@ -104,9 +102,10 @@ class ImageReport(AbstractMediaReport):
media_obj = models.ForeignKey(
to="Image",
to_field="identifier",
db_constraint=False,
on_delete=models.DO_NOTHING,
help_text="The foreign key to the 'Image' being reported.",
db_constraint=False,
related_name="image_report",
help_text="The reference to the image being reported.",
)

class Meta:
Expand Down
Loading

0 comments on commit a6e3759

Please sign in to comment.