Ejemplo n.º 1
0
def like_endpoint(post_id):
	if request.method == 'POST':
		data = request.json
		user = get_user()

		obj = Like.objects(author=user, post=post_id)
		if len(obj)==0:
			like.save()

			Post.objects(id=post_id).update_one(push__likes=like)
			return jsonify(**{'status':'ok'})
		else: 
			obj.delete()
Ejemplo n.º 2
0
def single_post_manage(id):
	o = Post.objects(id=id)

	if request.method == 'GET':
		o = o.as_pymongo()[0]
		o = json.loads(configs.JSONEncoder().encode(o))
		if 'comments' in o :
			del o['comments']

		o['images'] = list_images(id)

		return jsonify(**{'data':o})

	elif request.method == 'PUT':
		o = o[0]
		data = request.json
		data['last_edit_time'] = datetime.datetime.now() 
		data['background_image'] = str(o.id)+'/banner'
		o.update(**data)

		return jsonify(**{'status':'ok'})

	elif request.method == 'DELETE':
		# add file delete
		o.delete()
		return jsonify(**{"status": "ok"})
Ejemplo n.º 3
0
def comment_endpoint(post_id):

	if request.method == 'POST':
		data = request.json
		user = get_user()

		comment = Comment(comment_text=data['comment_text'], author=user)
		comment.save()

		Post.objects(id=post_id).update_one(push__comments=comment)
		return jsonify(**{'status':'ok'})

	if request.method == 'DELETE':
		comment = Comment.objects(id=post_id).delete()
		return jsonify(**{'status':'ok'})

	if request.method == 'PUT':
		comment = Comment.objects(id=post_id).first()
		comment['comment_text'] = request.json['comment_text']
		comment.save()
		return jsonify(**{'status':'ok'})
Ejemplo n.º 4
0
def post_manage():
	if request.method == 'POST':
		data = request.json
		newPost = Post(**data)
		newPost.background_image = newPost.id+'/banner'
		newPost.save()

		return jsonify(**{"status": "ok"})
	
	elif request.method == 'GET':
		
		params = request.args
		order_by = '+date'
		filter_by = { 'published': True}

		if 'order_by' in params:
			order_by = params['order_by']
		if 'not_published' in params: 
			filter_by['published'] = False
		q = Post.objects(**filter_by).order_by(order_by).exclude('comments')
		
		query = []
		for k in q.as_pymongo():
			if 'comments' in k:
				del k['comments']
			k['_id'] = str(k['_id'])
			query.append(k)
		return jsonify(**{'data':query})

	elif request.method == 'DELETE':
		# add file delete

		ids = request.args['ids'].split(',')
		q = Post.objects(id__in=ids)
		return jsonify(**{"status": "ok"})