kopia lustrzana https://github.com/wagtail/wagtail
Move the 'should we offer the copy_subpages checkbox or not' logic into CopyForm itself. This also allows us to move the help text into the actual help_text property, which fixes the dodgy spacing on the form field
rodzic
0f8e3cbe57
commit
b5f63d13b1
|
@ -87,7 +87,12 @@ class CopyForm(forms.Form):
|
|||
self.fields['new_title'] = forms.CharField(initial=self.page.title)
|
||||
self.fields['new_slug'] = forms.SlugField(initial=self.page.slug)
|
||||
|
||||
copy_subpages = forms.BooleanField(required=False, initial=True)
|
||||
pages_to_copy_count = self.page.get_descendants(inclusive=True).count()
|
||||
if pages_to_copy_count > 1:
|
||||
subpage_count = pages_to_copy_count - 1
|
||||
self.fields['copy_subpages'] = forms.BooleanField(required=False, initial=True,
|
||||
help_text=_("This will copy %(count)s subpages.") % {'count': subpage_count})
|
||||
|
||||
publish_copies = forms.BooleanField(required=False, initial=True)
|
||||
|
||||
def clean_new_slug(self):
|
||||
|
|
|
@ -14,17 +14,14 @@
|
|||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.new_title %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.new_slug %}
|
||||
|
||||
{% if pages_to_copy.count > 1 %}
|
||||
{% if form.copy_subpages %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.copy_subpages %}
|
||||
<li class="help">
|
||||
{% blocktrans with copy_page_count=pages_to_copy.count|add:'-1' %}This will copy {{ copy_page_count }} subpages.{% endblocktrans %}
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if pages_to_publish.count and can_publish %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.publish_copies %}
|
||||
<li class="help">
|
||||
{% blocktrans with live_page_count=pages_to_copy.live.count %}{{ live_page_count }} of the pages being copied are live. Would you like to publish their copies?{% endblocktrans %}
|
||||
{% blocktrans with live_page_count=pages_to_publish.count %}{{ live_page_count }} of the pages being copied are live. Would you like to publish their copies?{% endblocktrans %}
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
|
|
@ -687,7 +687,7 @@ def copy(request, page_id):
|
|||
if request.method == 'POST' and form.is_valid():
|
||||
# Copy the page
|
||||
new_page = page.copy(
|
||||
recursive=form.cleaned_data['copy_subpages'],
|
||||
recursive=form.cleaned_data.get('copy_subpages'),
|
||||
update_attrs={
|
||||
'title': form.cleaned_data['new_title'],
|
||||
'slug': form.cleaned_data['new_slug'],
|
||||
|
@ -705,7 +705,7 @@ def copy(request, page_id):
|
|||
new_page.get_descendants(inclusive=True).update(owner=request.user)
|
||||
|
||||
# Give a success message back to the user
|
||||
if form.cleaned_data['copy_subpages']:
|
||||
if form.cleaned_data.get('copy_subpages'):
|
||||
messages.success(request, _("Page '{0}' and {1} subpages copied.").format(page.title, new_page.get_descendants().count()))
|
||||
else:
|
||||
messages.success(request, _("Page '{0}' copied.").format(page.title))
|
||||
|
@ -713,13 +713,10 @@ def copy(request, page_id):
|
|||
# Redirect to explore of parent page
|
||||
return redirect('wagtailadmin_explore', parent_page.id)
|
||||
|
||||
pages_to_copy = page.get_descendants(inclusive=True)
|
||||
|
||||
return render(request, 'wagtailadmin/pages/copy.html', {
|
||||
'page': page,
|
||||
'pages_to_copy': pages_to_copy,
|
||||
'parent_page': parent_page,
|
||||
'pages_to_publish': pages_to_copy.live(),
|
||||
'pages_to_publish': page.get_descendants(inclusive=True).live(),
|
||||
'can_publish': can_publish,
|
||||
'form': form,
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue