kopia lustrzana https://github.com/jedie/PyInventory
Bugfix missing static files by tagulous bug.
Add a work-a-round for: https://github.com/radiac/django-tagulous/issues/164 The old tagulous implementation raised a silent error with Django >=4.0 The real fix is here: https://github.com/radiac/django-tagulous/pull/167pull/127/head
rodzic
4f16e6de34
commit
88c58a6c9e
|
@ -18,6 +18,7 @@ from inventory.admin.base import (
|
||||||
LimitTreeDepthListFilter,
|
LimitTreeDepthListFilter,
|
||||||
UserInlineMixin,
|
UserInlineMixin,
|
||||||
)
|
)
|
||||||
|
from inventory.admin.tagulous_fix import TagulousModelAdminFix
|
||||||
from inventory.models import ItemLinkModel, ItemModel
|
from inventory.models import ItemLinkModel, ItemModel
|
||||||
from inventory.models.item import ItemFileModel, ItemImageModel
|
from inventory.models.item import ItemFileModel, ItemImageModel
|
||||||
from inventory.string_utils import ltruncatechars
|
from inventory.string_utils import ltruncatechars
|
||||||
|
@ -45,7 +46,7 @@ class ItemModelResource(ModelResource):
|
||||||
|
|
||||||
|
|
||||||
@admin.register(ItemModel)
|
@admin.register(ItemModel)
|
||||||
class ItemModelAdmin(ImportExportMixin, SortableAdminMixin, BaseUserAdmin):
|
class ItemModelAdmin(TagulousModelAdminFix, ImportExportMixin, SortableAdminMixin, BaseUserAdmin):
|
||||||
@admin.display(description=_('Related items'))
|
@admin.display(description=_('Related items'))
|
||||||
def related_items(self, obj):
|
def related_items(self, obj):
|
||||||
if obj.pk is None:
|
if obj.pk is None:
|
||||||
|
|
|
@ -13,6 +13,7 @@ from inventory.admin.base import (
|
||||||
BaseUserAdmin,
|
BaseUserAdmin,
|
||||||
UserInlineMixin,
|
UserInlineMixin,
|
||||||
)
|
)
|
||||||
|
from inventory.admin.tagulous_fix import TagulousModelAdminFix
|
||||||
from inventory.models import MemoLinkModel, MemoModel
|
from inventory.models import MemoLinkModel, MemoModel
|
||||||
from inventory.models.memo import MemoFileModel, MemoImageModel
|
from inventory.models.memo import MemoFileModel, MemoImageModel
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ class MemoModelResource(ModelResource):
|
||||||
|
|
||||||
|
|
||||||
@admin.register(MemoModel)
|
@admin.register(MemoModel)
|
||||||
class MemoModelAdmin(ImportExportMixin, SortableAdminMixin, BaseUserAdmin):
|
class MemoModelAdmin(TagulousModelAdminFix, ImportExportMixin, SortableAdminMixin, BaseUserAdmin):
|
||||||
def get_max_order(self, request, obj=None):
|
def get_max_order(self, request, obj=None):
|
||||||
# Work-a-round for: https://github.com/jrief/django-admin-sortable2/issues/341
|
# Work-a-round for: https://github.com/jrief/django-admin-sortable2/issues/341
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
"""
|
||||||
|
Work-a-round for:
|
||||||
|
https://github.com/radiac/django-tagulous/issues/164
|
||||||
|
"""
|
||||||
|
from django import forms
|
||||||
|
from django.contrib.admin.widgets import AutocompleteMixin
|
||||||
|
from tagulous import settings as tagulous_settings
|
||||||
|
from tagulous.forms import AdminTagWidget, BaseTagField
|
||||||
|
from tagulous.models import SingleTagField, TagField
|
||||||
|
|
||||||
|
|
||||||
|
class AdminTagWidget2(AdminTagWidget):
|
||||||
|
@property
|
||||||
|
def media(self):
|
||||||
|
# Get the media from the AutocompleteMixin - this will give us Django's
|
||||||
|
# vendor jQuery and select2
|
||||||
|
class GetMedia(AutocompleteMixin, forms.Select):
|
||||||
|
pass
|
||||||
|
|
||||||
|
dependency_media = GetMedia(None, None).media
|
||||||
|
tagulous_media = forms.Media(
|
||||||
|
js=tagulous_settings.ADMIN_AUTOCOMPLETE_JS,
|
||||||
|
css=tagulous_settings.ADMIN_AUTOCOMPLETE_CSS,
|
||||||
|
)
|
||||||
|
all_media = dependency_media + tagulous_media
|
||||||
|
|
||||||
|
return all_media
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTagField2(BaseTagField):
|
||||||
|
widget = AdminTagWidget2
|
||||||
|
|
||||||
|
|
||||||
|
class TagulousModelAdminFix:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.formfield_overrides[SingleTagField] = {
|
||||||
|
'form_class': BaseTagField2,
|
||||||
|
'widget': AdminTagWidget2,
|
||||||
|
}
|
||||||
|
self.formfield_overrides[TagField] = {
|
||||||
|
'form_class': BaseTagField2,
|
||||||
|
'widget': AdminTagWidget2,
|
||||||
|
}
|
Ładowanie…
Reference in New Issue