Example #1
0
def new_thread(key=None):
	user = active_user()
	if has_permission(user,'new-thread'):
		new_thread = Thread()
		first_post = Post()
		name = bottle.request.forms.get("name")
		content = bottle.request.forms.get("content")
		tags = parse_tags(bottle.request.forms.get("tags",""))
		first_post.update({
			"owner":user.key,
			"content":content
		})
		new_thread.update({
			"name":name,
			"owner":user.key,
			"posts":[first_post.key],
			"tags":tags
		})
		forum = Forum.load(forum_key())
		target = Category.load(decrypt(key)) if key else forum
		target.threads.append(new_thread.key)
		target.save()
		new_thread.save()
		return flash_message("Your thread has been created.","/thread/"+new_thread.slug+"/","Success")
	raise bottle.HTTPError(404,
	"""Sorry, but we weren't able to find what you were looking for.
	  I hope that someday you do find it, but when you do, it won't be here.
	""")
Example #2
0
def create_post(urlsafe_chatroom_id, user_email, content):
    chatroom = get_chatroom(urlsafe_chatroom_id)
    if chatroom.status != 'active':
        raise ValueError(
            "Posts cannot be published while chatroom is suspended.")
    post = Post(chatroom_key=chatroom.key,
                user_email=user_email,
                content=content)
    post.put()

    return post
Example #3
0
def submit_post(key):
	user = active_user()
	if has_permission(user,'create-post'):
		post = Post()
		thread = Thread.load(decrypt(key))
		content = bottle.request.forms.get("content","").strip()
		assert len(content)>0
		post.update({"content":content,"owner":user.key})
		thread.posts.append(post)
		thread.save()
		post.save()
Example #4
0
 def post(self):
     subject = self.request.get('subject')
     content = self.request.get('content')
     # let's check we have a subject and a content
     if subject and content:
         post = Post(subject=subject,
                     content=content,
                     user=User.by_id(self.uid()))
         # post creation
         post.put()
         self.redirect('/')
     # if something is wrong let's show the error
     else:
         error = 'Sorry, we need both, title and content.'
         self.render_new_post(subject, content, error)
Example #5
0
 def create(self) -> Post:
     return Post(
         title=self.fake.name(),
         content=self.fake.text(),
     )