0.5.26 docs admin add actions for assign version to docs list
This commit is contained in:
@@ -7,6 +7,7 @@ from django.utils.translation import gettext as _
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.db.models import Min
|
from django.db.models import Min
|
||||||
|
from django.contrib import messages
|
||||||
|
|
||||||
|
|
||||||
class DocArtForm(forms.ModelForm):
|
class DocArtForm(forms.ModelForm):
|
||||||
@@ -19,6 +20,26 @@ class DocArtForm(forms.ModelForm):
|
|||||||
self.fields['parent'].queryset = DocArt.objects.exclude(id__exact=self.instance.id)
|
self.fields['parent'].queryset = DocArt.objects.exclude(id__exact=self.instance.id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def make_assign_versions_action(version):
|
||||||
|
def assign_to_version(modeladmin, request, queryset):
|
||||||
|
|
||||||
|
for art in queryset:
|
||||||
|
if version not in art.versions.all():
|
||||||
|
art.versions.add(version) # Method on Order model
|
||||||
|
messages.info(request, f"Статье {art} назначена версия {version.name}")
|
||||||
|
|
||||||
|
assign_to_version.short_description = _(f"Назначить версию {version.name}")
|
||||||
|
# We need a different '__name__' for each action - Django
|
||||||
|
# uses this as a key in the drop-down box.
|
||||||
|
assign_to_version.__name__ = _(f"Назначить версию {version.name}")
|
||||||
|
|
||||||
|
return assign_to_version
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Admin_DocArt(SuperModelAdmin, Admin_Trans_BaseModelViewPage):
|
class Admin_DocArt(SuperModelAdmin, Admin_Trans_BaseModelViewPage):
|
||||||
form = DocArtForm
|
form = DocArtForm
|
||||||
|
|
||||||
@@ -93,6 +114,20 @@ class Admin_DocArt(SuperModelAdmin, Admin_Trans_BaseModelViewPage):
|
|||||||
# inlines = [Admin_StackedInline_Block]
|
# inlines = [Admin_StackedInline_Block]
|
||||||
actions = ["create_copy_arts"]
|
actions = ["create_copy_arts"]
|
||||||
|
|
||||||
|
def get_actions(self, request):
|
||||||
|
actions = super(Admin_DocArt, self).get_actions(request)
|
||||||
|
|
||||||
|
versions = DocVersion.objects.filter(enable=True)
|
||||||
|
for version in versions:
|
||||||
|
action = make_assign_versions_action(version)
|
||||||
|
actions[action.__name__] = (action,
|
||||||
|
action.__name__,
|
||||||
|
action.short_description)
|
||||||
|
|
||||||
|
return actions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@admin.action(description=_("Создать копии выбранных статей"))
|
@admin.action(description=_("Создать копии выбранных статей"))
|
||||||
def create_copy_arts(self, request, queryset):
|
def create_copy_arts(self, request, queryset):
|
||||||
from BaseModels.functions import create_url
|
from BaseModels.functions import create_url
|
||||||
|
|||||||
Reference in New Issue
Block a user