def topic_addtopic(): form = request.form title = form['title'] u = current_user() Topic.add_topic(form, user_id=u.id) m = Topic.one(title=title) return redirect(url_for('.detail', id=m.id))
def post(self): user = users.get_current_user() if not user: return self.write("you are not loged in!") title = self.request.get("title") content = self.request.get("content") author = User.query(User.email == user.email()).get() topic = Topic.query( Topic.title == title).get() # check if topic exists if author: if not topic: # if not, create new one author_email = author.email author_avatar = author.avatar_url new_topic = Topic.add_topic(title=title, content=content, author_email=author_email, author_avatar=author_avatar) return self.redirect_to("topic", topic_id=new_topic.key.id()) else: return self.write("Topic with the same title already exists!")
def addtopic(): user = current_user() if user is None: return 'fail' res = Topic.add_topic(user, request.form) if res is not None: return 'success' else: return 'fail'
def create_topic(self, user_id, topic_name): Topic.add_topic(user_id, topic_name, auto_commit=True)