def save(self, *args, **kwargs): """ Create comment thread if one does not exist""" super(ProjectPrototype, self).save(*args, **kwargs) if not ProjectComment.objects.filter(project=self): thread = Post(text='Project Comments', creator=self.creator, subject='Comments for project') thread.save() ProjectComment(thread=thread, project=self).save()
def createPost(request): if request.method == "POST": content = request.POST.get('content') title = request.POST.get('title') author = request.user slug1 = str(datetime.now().time()) slug1 = slug1.replace(':', '-') slug1 = slug1.replace('.', '-') slug2 = str(datetime.now().date()) slug = slug1 + '-' + slug2 # timeStamp = now post = Post(title=title, author=author, content=content, slug=slug) post.save() messages.success(request, "Your post has been posted successfully") return redirect(f"/discussions")
def save(self, *args, **kwargs): self.slug = slugify(unicode(self.title)) self.slug = self.slug[:49] super(Lesson, self).save(*args, **kwargs) if not self.sections.all(): section = LessonSection(content_type='topic', lesson=self) section.save() section = LessonSection(content_type='media', lesson=self) section.save() section = LessonSection(content_type='reading', lesson=self) section.save() section = LessonSection(content_type='apply', lesson=self) section.save() if not self.lesson_discussion.all(): try: user = self.creator except: user = User.objects.filter(is_superuser=True)[0] try: thread = Post(text="Start a discussion!", creator=user, subject=self.title + ' Talk', parent_post=None) thread.save() discussion = LessonDiscussion(thread=thread, lesson=self) discussion.save() except: pass # Fail silently... if not self.lesson_quiz.all(): try: title = '%s Quiz' % (self.title) quiz = Quiz(title=title, url=title, random_order=False, answers_at_end=True) quiz.save() lesson_quiz = LessonQuiz(quiz=quiz, lesson=self) lesson_quiz.save() except Exception as e: pass # Fail silently...
def save(self, *args, **kwargs): self.slug = slugify(unicode(self.title)) self.slug = self.slug[:49] super(Lesson, self).save(*args, **kwargs) if not self.sections.all(): section = LessonSection(content_type='topic', lesson=self) section.save() section = LessonSection(content_type='media', lesson=self) section.save() section = LessonSection(content_type='reading', lesson=self) section.save() section = LessonSection(content_type='apply', lesson=self) section.save() if not self.lesson_discussion.all(): try: user = self.creator except: user = User.objects.filter(is_superuser=True)[0] try: thread = Post(text="Start a discussion!", creator=user, subject=self.title+' Talk', parent_post=None) thread.save() discussion = LessonDiscussion(thread=thread, lesson=self) discussion.save() except: pass # Fail silently... if not self.lesson_quiz.all(): try: title = '%s Quiz'% (self.title) quiz = Quiz(title=title, url=title, random_order=False, answers_at_end=True) quiz.save() lesson_quiz = LessonQuiz(quiz=quiz, lesson=self) lesson_quiz.save() except Exception as e: pass # Fail silently...