From 58267e9f8258f4840f92b8af926339ef1226a0c2 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sun, 6 Mar 2011 18:06:31 +0000 Subject: [PATCH] =?UTF-8?q?La=20til=20st=C3=B8tte=20for=20persons=20og=20r?= =?UTF-8?q?eferences=20i=20commit=20av=20edit-book.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/worblehat.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/python/worblehat.py b/python/worblehat.py index 1f61e8c..0094ff3 100755 --- a/python/worblehat.py +++ b/python/worblehat.py @@ -129,7 +129,27 @@ def perform_action(a): else: b.series = None if 'description' in a: b.description = a['description'] - # TODO persons, references, pictures + if 'persons' in a: + for bp in b.persons.all(): + if bp.person.id not in a['persons'][bp.relation.name]: + bp.delete() + for rel, person_list in a['persons'].items(): + for person_id in person_list: + if person_id not in map(lambda p: p.id, b.get_persons(rel)): + BookPerson(book=b, + person=Person.objects.get(id=person_id), + relation=Relation.objects.get(name=rel)).save() + if 'references' in a: + for ref in b.references.all(): + if ref.text not in a['references'][ref.reference_type]: + ref.delete() + for reftype, text_list in a['references'].items(): + for text in text_list: + if text not in map(lambda r: r.text, b.references.all()): + Reference(book=b, + reference_type=ReferenceType.objects.get(name=reftype), + text=text).save() + # TODO pictures b.save() def edit_book_or_person(ids):