예제 #1
0
 def received_comments():
     user_id = g.user.uid
     posts_list = Posts.user_posts(user_id)
     posts_ids = [post.id for post in posts_list]
     list = Comments.query.filter(Comments.post_id.in_(posts_ids),
                                  Comments.user_id != user_id).all()
     return list
예제 #2
0
파일: posts.py 프로젝트: GoldL/ji
def user_posts():
    uid = g.user.uid
    user_id = request.args.get('uid')
    user_id = user_id if user_id is not None else uid
    posts_list = Posts.user_posts(user_id)
    list = PostsCollection(posts_list)
    return json.dumps(list.data)
예제 #3
0
파일: admin.py 프로젝트: H4x3rs/flask_blog
def new_blog():
    """new a blog"""
    if request.method == 'POST':
        title = request.form.get('title', None)
        content = request.form.get('content', None)
        tags = request.form.getlist('tags[]', None)
        post = Posts(title=title, content=content)
        post.user_id = current_user.id
        post.tags = tags
        db.session.add(post)
        db.session.commit()
        flash(u'添加成功!')
        return redirect(url_for('admin.list_blog'))
    if request.method == 'GET':
        form = PostForm()
        return render_template('admin.new_blog.html',
                               title='new blog',
                               form=form)
예제 #4
0
파일: server.py 프로젝트: youya66/my_gocci
def find_collections():
	sended_data = {"data": []};
	insert_dict = {"id": None,"user_id": None, "rest_id": None, "movie": None};
	id = request.query.id;
	
	if isinstance(object, dict):
		parse_id = json.loads(id);
	else :
		parse_id= {"id": id};
			
	#postsをDBから取得しレスポンスボディ用の変数に代入
	for i in parse_id["id"]:
		get_document = Posts.objects(_id=i);
		insert_dict["id"] = get_document[0]._id;
		insert_dict["user_id"] = get_document[0].post_user_id;
		insert_dict["rest_id"] = get_document[0].post_rest_id;
		insert_dict["movie"] = get_document[0].movie;
		sended_data["data"].append(insert_dict);

	conversion_sended_data = json.dumps(sended_data);
	res = HTTPResponse(status=200,body=conversion_sended_data);
	res.set_header("Content-Type","application/json; charset=utf-8");
	res.set_header("Content-Language","js-JP");
	return res;
예제 #5
0
파일: posts.py 프로젝트: GoldL/ji
def super_posts_list():
    posts_list = Posts.super_posts_list()
    return jsonify(posts_list)
예제 #6
0
파일: posts.py 프로젝트: GoldL/ji
def address_posts():
    address = request.args.get('address')
    posts_list = Posts.address(address)
    list = PostsCollection(posts_list)
    return json.dumps(list.data)
예제 #7
0
파일: posts.py 프로젝트: GoldL/ji
def search_posts():
    title = request.args.get('title')
    posts_list = Posts.search(title)
    list = PostsCollection(posts_list)
    return json.dumps(list.data)
예제 #8
0
파일: posts.py 프로젝트: GoldL/ji
def recommend_posts():
    posts_list = Posts.recommend()
    list = PostsCollection(posts_list)
    random.shuffle(list.data)
    return json.dumps(list.data)
예제 #9
0
파일: posts.py 프로젝트: GoldL/ji
def save_posts():
    form = PostsForm().validate_for_api()
    Posts.save_posts(form.title.data, form.content.data, form.images.data,
                     form.location.data)
    return Success(msg='随记创建成功!')
예제 #10
0
파일: server.py 프로젝트: youya66/my_gocci
def add_message () :
	
	#variable of reponse;
	sended_data = {
		"status": "success",
		"message": "post successfully added message"
	}

	value = request.json["message"];
	# db = Chats();
	# db._id = Chats.objects.count() + 1;
	# db.chat_room_id = 0;
	# db.message = value;
	# db.save();

	#regex progress
	findall_get_posts = get_post_regex.findall(value);
	match_help_pattern = help_regex.match(value);
	
	#return help info
	if match_help_pattern:
		sended_data["data"] = "-h,help: use command\nmy: 自分の投稿を取得する";
		sended_data["message"] += " and help command";
	
	#return posts data
	elif findall_get_posts:
		
		#variable
		replace_matched_list = [];
		match_list_data = list(findall_get_posts[0]);
		sended_data["data"] = [];
		
		#マッチしたデータを使ってデータベースから情報を取得
		#replace_matched_list["find or search", "count","date","position"];]
		for i, string in enumerate(match_list_data):
			replace_space = space_regex.sub("",string);
			if replace_space.isdigit():
				replace_space = int(replace_space);
			elif i == 0 and not replace_space:
				replace_space = 1;
			elif not replace_space:
				replace_space = 0;

			replace_matched_list.append(replace_space);

		if replace_matched_list[1]:
			term = date_calculation(replace_matched_list[1]);
		else :
			term = datetime.datetime.now();

		get_document = Posts.objects().filter(post_user_id=1,date_time__lte=term).order_by("-_id").limit(replace_matched_list[0]);
		for i in range(get_document.count(with_limit_and_skip=True)):
			temp = get_document[i];
			insert_data = {};
			insert_data["post_id"] = temp._id;
			insert_data["user_id"] = temp.post_user_id._id;
			insert_data["id_name"] = temp.post_user_id.id_name;
			insert_data["user_name"] = temp.post_user_id.user_name;
			insert_data["rest_id"] = temp.post_rest_id._id;
			insert_data["rest_name"] = temp.post_rest_id.rest_name;
			insert_data["movie"] = temp.movie;
			insert_data["date_time"] = calculate_japan_time_strings(temp.date_time);
			sended_data["data"].append(insert_data);

		print(sended_data);
		sended_data["message"] += " and get posts";

	res = HTTPResponse(status=200,body=sended_data);
	res.set_header("Content-Type","application/json; charset=8");
	res.set_header("Content-Language","js-JP");
	return res;