handle series properly

pull/91/head
eric 2018-06-18 17:04:19 -04:00
parent 3bc7d5c003
commit 53a0791da0
4 changed files with 41 additions and 2 deletions

View File

@ -521,6 +521,20 @@ def merge_works(w1, w2, user=None):
#(for example, when w2 has already been deleted)
if w1 is None or w2 is None or w1.id == w2.id or w1.id is None or w2.id is None:
return w1
#don't merge if the works are related.
if w2 in w1.works_related_to.all() or w1 in w2.works_related_to.all():
return w1
# check if one of the works is a series with parts (that have their own isbn)
if w1.works_related_from.filter(relation='part'):
models.WorkRelation.objects.get_or_create(to_work=w2, from_work=w1, relation='part')
return w1
if w2.works_related_from.filter(relation='part'):
models.WorkRelation.objects.get_or_create(to_work=w1, from_work=w2, relation='part')
return w1
if w2.selected_edition is not None and w1.selected_edition is None:
#the merge should be reversed
temp = w1

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0013_ebookfile_mobied'),
]
operations = [
migrations.AlterField(
model_name='workrelation',
name='relation',
field=models.CharField(max_length=15, choices=[(b'translation', b'translation'), (b'revision', b'revision'), (b'sequel', b'sequel'), (b'part', b'part')]),
),
]

View File

@ -20,7 +20,7 @@ TEXT_RELATION_CHOICES = (
('translation', 'translation'),
('revision', 'revision'),
('sequel', 'sequel'),
('compilation', 'compilation')
('part', 'part')
)
ID_CHOICES = (

View File

@ -298,7 +298,13 @@ class BookLoaderTests(TestCase):
# first try to merge work 1 into itself -- should not do anything
bookloader.merge_works(w1, w1)
self.assertEqual(models.Work.objects.count(), before + 2)
# first try to merge related works -- should not do anything
rel, created = models.WorkRelation.objects.get_or_create(to_work=w1, from_work=w2, relation='part')
bookloader.merge_works(w1, w2)
self.assertEqual(models.Work.objects.count(), before + 2)
rel.delete()
# merge the second work into the first
bookloader.merge_works(e1.work, e2.work)
self.assertEqual(models.Work.objects.count(), before + 1)