allow edit primary_lookup_id if not present or not ideal
This commit is contained in:
parent
0d601a63dc
commit
f3b868d314
3 changed files with 25 additions and 15 deletions
|
@ -80,6 +80,18 @@ class IdType(models.TextChoices):
|
|||
ApplePodcast = "apple_podcast", _("苹果播客")
|
||||
|
||||
|
||||
IdealIdTypes = [
|
||||
IdType.ISBN,
|
||||
IdType.CUBN,
|
||||
IdType.ASIN,
|
||||
IdType.GTIN,
|
||||
IdType.ISRC,
|
||||
IdType.MusicBrainz,
|
||||
IdType.RSS,
|
||||
IdType.IMDB,
|
||||
]
|
||||
|
||||
|
||||
class ItemType(models.TextChoices):
|
||||
Book = "book", _("书")
|
||||
TV = "tv", _("剧集")
|
||||
|
@ -269,17 +281,7 @@ class Item(SoftDeleteMixin, PolymorphicModel):
|
|||
@classmethod
|
||||
def get_best_lookup_id(cls, lookup_ids):
|
||||
"""get best available lookup id, ideally commonly used"""
|
||||
best_id_types = [
|
||||
IdType.ISBN,
|
||||
IdType.CUBN,
|
||||
IdType.ASIN,
|
||||
IdType.GTIN,
|
||||
IdType.ISRC,
|
||||
IdType.MusicBrainz,
|
||||
IdType.RSS,
|
||||
IdType.IMDB,
|
||||
]
|
||||
for t in best_id_types:
|
||||
for t in IdealIdTypes:
|
||||
if lookup_ids.get(t):
|
||||
return t, lookup_ids[t]
|
||||
return list(lookup_ids.items())[0]
|
||||
|
|
|
@ -27,7 +27,7 @@ def _EditForm(item_model: Item):
|
|||
label=_("主要标识类型"),
|
||||
)
|
||||
primary_lookup_id_value = forms.CharField(
|
||||
required=False, label=_("主要标识数据通常由系统自动检测,请勿随意更改,不确定留空即可")
|
||||
required=False, label=_("主要标识数据通常由系统自动检测,请勿随意更改现有值,新增条目不确定留空即可")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.core.exceptions import BadRequest, PermissionDenied, ObjectDoesNotEx
|
|||
from django.db.models import Count
|
||||
from django.utils import timezone
|
||||
from django.core.paginator import Paginator
|
||||
from catalog.common.models import ExternalResource
|
||||
from catalog.common.models import ExternalResource, IdealIdTypes
|
||||
from .models import *
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
from journal.models import Mark, ShelfMember, Review, query_item_category
|
||||
|
@ -159,7 +159,11 @@ def edit(request, item_path, item_uuid):
|
|||
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
|
||||
form_cls = CatalogForms[item.__class__.__name__]
|
||||
form = form_cls(instance=item)
|
||||
if item.external_resources.all().count() > 0:
|
||||
if (
|
||||
item.external_resources.all().count() > 0
|
||||
and item.primary_lookup_id_value
|
||||
and item.primary_lookup_id_type in IdealIdTypes
|
||||
):
|
||||
form.fields["primary_lookup_id_type"].disabled = True
|
||||
form.fields["primary_lookup_id_value"].disabled = True
|
||||
return render(request, "catalog_edit.html", {"form": form, "item": item})
|
||||
|
@ -167,7 +171,11 @@ def edit(request, item_path, item_uuid):
|
|||
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
|
||||
form_cls = CatalogForms[item.__class__.__name__]
|
||||
form = form_cls(request.POST, request.FILES, instance=item)
|
||||
if item.external_resources.all().count() > 0:
|
||||
if (
|
||||
item.external_resources.all().count() > 0
|
||||
and item.primary_lookup_id_value
|
||||
and item.primary_lookup_id_type in IdealIdTypes
|
||||
):
|
||||
form.fields["primary_lookup_id_type"].disabled = True
|
||||
form.fields["primary_lookup_id_value"].disabled = True
|
||||
if form.is_valid():
|
||||
|
|
Loading…
Add table
Reference in a new issue