-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete related variants when deleting the segment (#183)
* Delete related variants when deleting the segment Closes #155 * Fix typo * Fix migration ordering * Split metadata migrations
- Loading branch information
Showing
10 changed files
with
216 additions
and
12 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...rsonalisation/migrations/0021_personalisablepagemetadata_segment_set_on_delete_protect.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 2.0.7 on 2018-07-04 15:26 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtail_personalisation', '0020_rules_delete_relatedqueryname'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='personalisablepagemetadata', | ||
name='segment', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='page_metadata', to='wagtail_personalisation.Segment'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/wagtail_personalisation/migrations/0023_personalisablepagemetadata_variant_cascade.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 2.0.5 on 2018-07-19 09:57 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtail_personalisation', '0022_personalisablepagemetadata_canonical_protect'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='personalisablepagemetadata', | ||
name='variant', | ||
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='_personalisable_page_metadata', to='wagtailcore.Page'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/delete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{% extends "modeladmin/delete.html" %} | ||
|
||
{% load i18n modeladmin_tags %} | ||
|
||
{% block content_main %} | ||
<div class="nice-padding"> | ||
{% if protected_error %} | ||
<h2>{% blocktrans with view.verbose_name|capfirst as model_name %}{{ model_name }} could not be deleted{% endblocktrans %}</h2> | ||
<p>{% blocktrans with instance as instance_name %}'{{ instance_name }}' is currently referenced by other objects, and cannot be deleted without jeopardising data integrity. To delete it successfully, first remove references from the following objects, then try again:{% endblocktrans %}</p> | ||
<ul> | ||
{% for obj in linked_objects %}<li><b>{{ obj|get_content_type_for_obj|title }}:</b> {{ obj }}</li>{% endfor %} | ||
</ul> | ||
<p><a href="{{ view.index_url }}" class="button">{% trans 'Go back to listing' %}</a></p> | ||
{% elif cannot_delete_page_variants_error %} | ||
<h2>{% blocktrans %}Cannot delete all the page variants{% endblocktrans %}</h2> | ||
<p>{% blocktrans %}You need to have permissions to delete the page variants associated with this segment.{% endblocktrans %} | ||
{% else %} | ||
{% with page_variants=view.get_affected_page_objects %} | ||
{% if page_variants %} | ||
<p> | ||
{% blocktrans %}Deleting the segment will also mean deleting all the page variants associated with it. Do you want to continue?{% endblocktrans %} | ||
</p> | ||
<p> | ||
{% blocktrans %}The page objects that <strong>will be deleted</strong> are:{% endblocktrans %} | ||
</p> | ||
<ul> | ||
{% for variant in page_variants %} | ||
<li> | ||
<a href="{% url 'wagtailadmin_explore' variant.pk %}"> | ||
{{ variant }} | ||
</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% trans 'Yes, delete the segment and associated page variants' as submit_button_value %} | ||
{% else %} | ||
<p> | ||
{% blocktrans %}Do you want to continue deleting this segment?{% endblocktrans %} | ||
</p> | ||
{% trans 'Yes, delete the segment' as submit_button_value %} | ||
{% endif %} | ||
<form action="{{ view.delete_url }}" method="POST"> | ||
{% csrf_token %} | ||
<input type="submit" value="{{ submit_button_value }}" class="button serious" /> | ||
</form> | ||
{% endwith %} | ||
{% endif %} | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters