Skip to content

Commit de5a447

Browse files
committed
Close #1068
1 parent 1a6a5ca commit de5a447

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

zds/tutorial/models.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ def get_parts(self):
144144
def get_chapter(self):
145145
"""Gets the chapter associated with the tutorial if it's small."""
146146
# We can use get since we know there'll only be one chapter
147-
return Chapter.objects.get(tutorial__pk=self.pk)
147+
try:
148+
return Chapter.objects.get(tutorial__pk=self.pk)
149+
except Chapter.DoesNotExist:
150+
return None
148151

149152
def in_beta(self):
150153
return (self.sha_beta is not None) and (self.sha_beta.strip() != '')
@@ -303,7 +306,7 @@ def last_read_note(self):
303306
.latest('note__pubdate').note
304307
except Note.DoesNotExist:
305308
return self.first_post()
306-
309+
307310
def first_unread_note(self):
308311
"""Return the first note the user has unread."""
309312
try:
@@ -344,11 +347,11 @@ def antispam(self, user=None):
344347
if t.total_seconds() < settings.SPAM_LIMIT_SECONDS:
345348
return True
346349
return False
347-
350+
348351
def update_children(self):
349352
for part in self.get_parts():
350353
part.update_children()
351-
354+
352355
chapter = self.get_chapter()
353356
if chapter:
354357
chapter.update_children()
@@ -830,7 +833,7 @@ def get_path(self, relative=False):
830833
return os.path.join(chapter_path, str(self.pk) + "_" + slugify(self.title)) + '.md'
831834

832835
def get_prod_path(self):
833-
836+
834837
if self.chapter.tutorial:
835838
data = self.chapter.tutorial.load_json_for_public()
836839
mandata = tutorial.load_dic(data)

0 commit comments

Comments
 (0)