From 55953c705567baf05403303de45c3720685571eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Tue, 27 Oct 2009 19:35:49 +0100 Subject: [PATCH] =?utf8?q?Wypisywanie=20b=C5=82=C4=99d=C3=B3w=20przy=20imp?= =?utf8?q?ortowaniu=20ksi=C4=85=C5=BCek=20(obecnie=20wypisujemy=20po=20pro?= =?utf8?q?stu=20wyj=C4=85tek=20Django).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- apps/catalogue/models.py | 13 ++++++++----- apps/catalogue/views.py | 14 ++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 58025fabd..2c1f66a6b 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -231,11 +231,14 @@ class Book(models.Model): if hasattr(book_info, 'parts'): for n, part_url in enumerate(book_info.parts): base, slug = part_url.rsplit('/', 1) - child_book = Book.objects.get(slug=slug) - child_book.parent = book - child_book.parent_number = n - child_book.save() - + try: + child_book = Book.objects.get(slug=slug) + child_book.parent = book + child_book.parent_number = n + child_book.save() + except Book.DoesNotExist, e: + raise Book.DoesNotExist(u'Book with slug = "%s" does not exist.' % slug) + book_descendants = list(book.children.all()) while len(book_descendants) > 0: child_book = book_descendants.pop(0) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index b61d5e803..cc7669b06 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- import tempfile import zipfile +import sys +import pprint +import traceback from django.template import RequestContext from django.shortcuts import render_to_response, get_object_or_404 @@ -369,10 +372,13 @@ def import_book(request): """docstring for import_book""" book_import_form = forms.BookImportForm(request.POST, request.FILES) if book_import_form.is_valid(): - # try: - book_import_form.save() - # except: - # return HttpResponse("Error importing book: %r" % (sys.exc_info(),)) + try: + book_import_form.save() + except: + info = sys.exc_info() + exception = pprint.pformat(info[1]) + tb = '\n'.join(traceback.format_tb(info[2])) + return HttpResponse("An error occurred: %s\n\n%s" % (exception, tb), mimetype='text/plain') return HttpResponse("Book imported successfully") else: return HttpResponse("Error importing file: %r" % book_import_form.errors) \ No newline at end of file -- 2.20.1