From de5a44721060a78c1646177cd1b39a1e2617853e Mon Sep 17 00:00:00 2001 From: Victor Felder Date: Mon, 7 Jul 2014 12:15:52 +0200 Subject: [PATCH] Close #1068 --- zds/tutorial/models.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/zds/tutorial/models.py b/zds/tutorial/models.py index 8998628afe..c431384a13 100644 --- a/zds/tutorial/models.py +++ b/zds/tutorial/models.py @@ -144,7 +144,10 @@ def get_parts(self): def get_chapter(self): """Gets the chapter associated with the tutorial if it's small.""" # We can use get since we know there'll only be one chapter - return Chapter.objects.get(tutorial__pk=self.pk) + try: + return Chapter.objects.get(tutorial__pk=self.pk) + except Chapter.DoesNotExist: + return None def in_beta(self): return (self.sha_beta is not None) and (self.sha_beta.strip() != '') @@ -303,7 +306,7 @@ def last_read_note(self): .latest('note__pubdate').note except Note.DoesNotExist: return self.first_post() - + def first_unread_note(self): """Return the first note the user has unread.""" try: @@ -344,11 +347,11 @@ def antispam(self, user=None): if t.total_seconds() < settings.SPAM_LIMIT_SECONDS: return True return False - + def update_children(self): for part in self.get_parts(): part.update_children() - + chapter = self.get_chapter() if chapter: chapter.update_children() @@ -830,7 +833,7 @@ def get_path(self, relative=False): return os.path.join(chapter_path, str(self.pk) + "_" + slugify(self.title)) + '.md' def get_prod_path(self): - + if self.chapter.tutorial: data = self.chapter.tutorial.load_json_for_public() mandata = tutorial.load_dic(data)