allow delete unused podcasts

This commit is contained in:
Your Name 2024-07-16 17:49:10 -04:00 committed by Henri Dickson
parent 41c265295b
commit a89aef2538
5 changed files with 30 additions and 17 deletions

View file

@ -173,7 +173,7 @@ class Edition(Item):
)
language = LanguageListField()
pub_house = jsondata.CharField(
_("publishing house"), null=True, blank=False, max_length=500
_("publishing house"), null=True, blank=True, max_length=500
)
pub_year = jsondata.IntegerField(
_("publication year"),

View file

@ -419,6 +419,14 @@ class Item(PolymorphicModel):
]
]
def can_soft_delete(self):
return (
not self.is_deleted
and not self.merged_to_item_id
and not self.merged_from_items.exists()
and not self.child_items.exists()
)
def delete(
self,
using: Any = None,

View file

@ -17,7 +17,7 @@ from catalog.common import (
PrimaryLookupIdDescriptor,
jsondata,
)
from catalog.common.models import LanguageListField
from catalog.common.models import LIST_OF_ONE_PLUS_STR_SCHEMA, LanguageListField
class PodcastInSchema(ItemInSchema):
@ -52,10 +52,12 @@ class Podcast(Item):
language = LanguageListField()
host = jsondata.ArrayField(
host = jsondata.JSONField(
verbose_name=_("host"),
base_field=models.CharField(blank=True, default="", max_length=200),
null=False,
blank=False,
default=list,
schema=LIST_OF_ONE_PLUS_STR_SCHEMA,
)
official_site = jsondata.CharField(
@ -97,6 +99,14 @@ class Podcast(Item):
def child_items(self):
return self.episodes.filter(is_deleted=False, merged_to_item=None)
def can_soft_delete(self):
# override can_soft_delete() and allow delete podcast with episodes
return (
not self.is_deleted
and not self.merged_to_item_id
and not self.merged_from_items.exists()
)
class PodcastEpisode(Item):
category = ItemCategory.Podcast

View file

@ -157,7 +157,7 @@
{% endif %}
{% if item.class_name == "tvseason" or item.class_name == "performanceproduction" %}
<details>
<summary>{% trans "link to parent item" %}</summary>
<summary>{% trans "Link to parent item" %}</summary>
<form method="post"
action="{% url 'catalog:assign_parent' item.url_path item.uuid %}"
onsubmit="return confirm('{% trans "Sure to link?" %}');">
@ -173,7 +173,7 @@
{% endif %}
{% if item.class_name == "tvshow" %}
<details>
<summary>{% trans "cleanup seasons" %}</summary>
<summary>{% trans "Cleanup seasons" %}</summary>
<form method="post"
action="{% url 'catalog:remove_unused_seasons' item.url_path item.uuid %}"
onsubmit="return confirm('{% trans "This operation cannot be undone. Sure to delete?" %}');">
@ -186,7 +186,7 @@
{% endif %}
{% if not item.journal_exists or request.user.is_staff %}
<details>
<summary>{% trans 'merge' %}</summary>
<summary>{% trans 'Merge' %}</summary>
<form method="post"
action="{% url 'catalog:merge' item.url_path item.uuid %}">
{% csrf_token %}
@ -201,20 +201,13 @@
value="{% trans 'merge to another item' %}">
</form>
</details>
{% if item.child_items %}
<!-- contains child items -->
{% elif item.merged_from_items.all %}
<!-- merged from other items -->
{% else %}
{% if item.can_soft_delete %}
<details>
<summary>{% trans 'Delete' %}</summary>
<form method="post"
action="{% url 'catalog:delete' item.url_path item.uuid %}">
{% csrf_token %}
<input class="contrast"
type="submit"
{% if item.is_deleted or item.merged_to_item %}disabled{% endif %}
value="{% trans 'delete' %}">
<input class="contrast" type="submit" value="{% trans 'delete' %}">
</form>
</details>
{% endif %}

View file

@ -119,7 +119,9 @@ def edit(request, item_path, item_uuid):
def delete(request, item_path, item_uuid):
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
if not request.user.is_staff and item.journal_exists():
raise PermissionDenied(_("Insufficient permission"))
raise PermissionDenied(_("Item in use."))
if not item.can_soft_delete():
raise PermissionDenied(_("Item cannot be deleted."))
if request.POST.get("sure", 0) != "1":
return render(request, "catalog_delete.html", {"item": item})
else: