Cascade-delete progress updates
Add a warning about it, and update test to confirm it works
This commit is contained in:
parent
60b42827f4
commit
32346cf9a3
|
@ -42,7 +42,7 @@ class ReadThrough(BookWyrmModel):
|
||||||
class ProgressUpdate(BookWyrmModel):
|
class ProgressUpdate(BookWyrmModel):
|
||||||
''' Store progress through a book in the database. '''
|
''' Store progress through a book in the database. '''
|
||||||
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
||||||
readthrough = models.ForeignKey('ReadThrough', on_delete=models.PROTECT)
|
readthrough = models.ForeignKey('ReadThrough', on_delete=models.CASCADE)
|
||||||
progress = models.IntegerField()
|
progress = models.IntegerField()
|
||||||
mode = models.CharField(
|
mode = models.CharField(
|
||||||
max_length=3,
|
max_length=3,
|
||||||
|
|
|
@ -7,11 +7,10 @@
|
||||||
</h2>
|
</h2>
|
||||||
{% include 'snippets/toggle/toggle_button.html' with label="close" class="delete" nonbutton=True %}
|
{% include 'snippets/toggle/toggle_button.html' with label="close" class="delete" nonbutton=True %}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{% block modal-form-open %}{% endblock %}
|
{% block modal-form-open %}{% endblock %}
|
||||||
|
<section class="modal-card-body">
|
||||||
{% block modal-body %}{% endblock %}
|
{% block modal-body %}{% endblock %}
|
||||||
|
</section>
|
||||||
<footer class="modal-card-foot">
|
<footer class="modal-card-foot">
|
||||||
{% block modal-footer %}{% endblock %}
|
{% block modal-footer %}{% endblock %}
|
||||||
</footer>
|
</footer>
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
{% extends 'snippets/components/modal.html' %}
|
{% extends 'snippets/components/modal.html' %}
|
||||||
{% block modal-title %}Delete these read dates?{% endblock %}
|
{% block modal-title %}Delete these read dates?{% endblock %}
|
||||||
|
{% block modal-body %}
|
||||||
|
{% if readthrough.progress_updates|length > 0 %}
|
||||||
|
You are deleting this readthrough and its {{ readthrough.progress_updates|length }} associated progress updates.
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
{% block modal-footer %}
|
{% block modal-footer %}
|
||||||
<form name="delete-readthrough-{{ readthrough.id }}" action="/delete-readthrough" method="POST">
|
<form name="delete-readthrough-{{ readthrough.id }}" action="/delete-readthrough" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -77,3 +77,12 @@ class ReadThrough(TestCase):
|
||||||
self.assertEqual(progress_updates[1].mode, models.ProgressMode.PAGE)
|
self.assertEqual(progress_updates[1].mode, models.ProgressMode.PAGE)
|
||||||
self.assertEqual(progress_updates[1].progress, 100)
|
self.assertEqual(progress_updates[1].progress, 100)
|
||||||
self.assertEqual(delay_mock.call_count, 1) # Edit doesn't publish anything
|
self.assertEqual(delay_mock.call_count, 1) # Edit doesn't publish anything
|
||||||
|
|
||||||
|
self.client.post('/delete-readthrough', {
|
||||||
|
'id': readthroughs[0].id,
|
||||||
|
})
|
||||||
|
|
||||||
|
readthroughs = self.edition.readthrough_set.all()
|
||||||
|
updates = self.user.progressupdate_set.all()
|
||||||
|
self.assertEqual(len(readthroughs), 0)
|
||||||
|
self.assertEqual(len(updates), 0)
|
||||||
|
|
Loading…
Reference in New Issue