Abdelrahman Hamada 2024-05-02 09:36:04 +00:00 zatwierdzone przez GitHub
commit 97b163b247
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
5 zmienionych plików z 27 dodań i 2 usunięć

Wyświetl plik

@ -34,6 +34,7 @@ export class PageChooser extends Chooser {
matchSubclass: this.opts.matchSubclass, matchSubclass: this.opts.matchSubclass,
canChooseRoot: this.opts.canChooseRoot, canChooseRoot: this.opts.canChooseRoot,
userPerms: this.opts.userPerms, userPerms: this.opts.userPerms,
instanceId: this.opts.instanceId,
}; };
if (this.state && this.state.parentId) { if (this.state && this.state.parentId) {
opts.parentId = this.state.parentId; opts.parentId = this.state.parentId;

Wyświetl plik

@ -251,6 +251,9 @@ class PageChooserModal extends ChooserModal {
if (opts.userPerms) { if (opts.userPerms) {
urlParams.user_perms = opts.userPerms; urlParams.user_perms = opts.userPerms;
} }
if (opts.instanceId) {
urlParams.instance_id = opts.instanceId;
}
return urlParams; return urlParams;
} }
} }

Wyświetl plik

@ -1,5 +1,6 @@
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.forms import models
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.utils.translation import ngettext from django.utils.translation import ngettext
@ -166,6 +167,19 @@ class WagtailAdminPageForm(WagtailAdminModelForm):
self.parent_page = parent_page self.parent_page = parent_page
# bind the parent page of this forms page to the PageChooser widget
for obj in self.fields.values():
if isinstance(obj, models.ModelChoiceField):
try:
obj.widget.page_instance = (
self.instance
if self.instance.id is not None
else self.parent_page
)
except AttributeError:
# Then propably it isn't a page chooser
pass
if not self.show_comments_toggle: if not self.show_comments_toggle:
del self.fields["comment_notifications"] del self.fields["comment_notifications"]

Wyświetl plik

@ -296,9 +296,12 @@ class BrowseView(View):
selected_locale = get_object_or_404( selected_locale = get_object_or_404(
Locale, language_code=request.GET["locale"] Locale, language_code=request.GET["locale"]
) )
active_locale_id = selected_locale.pk elif request.GET.get("instance_id"):
page_instance = Page.objects.get(id=request.GET["instance_id"])
selected_locale = page_instance.locale
else: else:
active_locale_id = Locale.get_active().pk selected_locale = Locale.get_active()
active_locale_id = selected_locale.pk
# we are at the Root level, so get the locales from the current pages # we are at the Root level, so get the locales from the current pages
choose_url = reverse("wagtailadmin_choose_page") choose_url = reverse("wagtailadmin_choose_page")

Wyświetl plik

@ -224,6 +224,7 @@ class AdminPageChooser(BaseChooser):
icon = "doc-empty-inverse" icon = "doc-empty-inverse"
classname = "page-chooser" classname = "page-chooser"
js_constructor = "PageChooser" js_constructor = "PageChooser"
page_instance = None
def __init__( def __init__(
self, target_models=None, can_choose_root=False, user_perms=None, **kwargs self, target_models=None, can_choose_root=False, user_perms=None, **kwargs
@ -301,6 +302,9 @@ class AdminPageChooser(BaseChooser):
parent_id = value_data.get("parent_id") parent_id = value_data.get("parent_id")
if parent_id is not None: if parent_id is not None:
opts["parentId"] = parent_id opts["parentId"] = parent_id
if self.page_instance is not None:
opts["instanceId"] = self.page_instance.id
return opts return opts
@property @property