예제 #1
0
def postdata(type):
    # get all deactivate user
    deactivate_users_list = get_deactivate_userid_list()
    # print(deactivate_users_list)

    # print(type)
    post_list = []
    if type == "All resources":
        post_list = list(
            Post.find({'author.id': {
                '$nin': deactivate_users_list
            }}))
        # print(post_list)
    elif type == "Photos":
        post_list = Post.find({
            "type": "photo",
            'author.id': {
                '$nin': deactivate_users_list
            }
        })
    elif type == "Vectors":
        post_list = Post.find({
            "type": "vector",
            'author.id': {
                '$nin': deactivate_users_list
            }
        })
    elif type == "PSD":
        post_list = Post.find({
            "type": "psd",
            'author.id': {
                '$nin': deactivate_users_list
            }
        })
    return dumps({"message": "success", "post_list": post_list})
예제 #2
0
def post_message():
    if request.method == 'POST':
        newComment = Comments.insert_one({
            'author': session['ids'],
            'content': request.json['message']
        })
        # find post
        Post.find_one_and_update(
            {'_id': ObjectId(request.json['postId'])},
            {'$push': {
                'comments': str(newComment.inserted_id)
            }})

        # Post.update(
        #     {},
        #     {'$unset': {'comments': 1}},
        #     False, True
        # )

    return jsonify({
        'status': 'sucssess',
        'comment': {
            'userid': session['ids'],
            'content': request.json['message'],
            'username': session['username'],
        }
    })
예제 #3
0
def upload():
    if request.method == "GET":
        if 'loggedin' in session:
            return render_template('upload.html')
        else:
            return redirect('/login')
    elif request.method == "POST":
        form = request.form
        title = form['title']
        type = form['type']
        link = form['link']
        file = request.files['file']
        file_name = file.filename
        user_info = User.find_one(loads(session['id']))

        user_data = {
            "id": user_info['_id'],
            "username": user_info['username'],
            "email": user_info['email']
        }

        print(user_data)
        if file and allowed_file(file_name):
            file_name = secure_filename(file_name)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], file_name))
        Post.insert_one({
            'title': title,
            'type': type,
            'link': link,
            'thumbnail': file_name,
            'like': [],
            'check': False,
            "author": user_data
        })
        return redirect("/")
예제 #4
0
def post_dislike(post_id, viewer_name):
    post_data = Post.find_one({'_id': ObjectId(post_id)})
    # print(post_data['like'])
    like_list = post_data['like']
    like_list.remove(viewer_name)

    Post.update_one({'_id': ObjectId(post_id)}, {'$set': {'like': like_list}})
    return redirect('/detail/' + post_id)
예제 #5
0
def post_like(post_id, viewer_name):
    post_data = Post.find_one({'_id': ObjectId(post_id)})
    # print(post_data['like'])
    like_list = post_data['like']
    like_list.append(viewer_name)

    Post.update_one({'_id': ObjectId(post_id)}, {'$set': {'like': like_list}})
    # return redirect(url_for('detail', id = post_id))
    return redirect('/detail/' + post_id)
예제 #6
0
def postdata(type):
    print(type)
    post_list = []
    if type == "All resources":
        post_list = Post.find()
    elif type == "Photos":
        post_list = Post.find({"type": "photo"})
    elif type == "Vectors":
        post_list = Post.find({"type": "vector"})
    elif type == "PSD":
        post_list = Post.find({"type": "psd"})
    return dumps({"message": "success", "post_list": post_list})
예제 #7
0
def detail(id):
    # print(id)
    user_isdeactivated = check_deactivate_post(id)
    post_info = Post.find_one({"_id": ObjectId(id)})
    usr_id = str(post_info['author']['id'])

    if user_isdeactivated and 'admin_ids' not in session:
        if 'loggedin' in session:
            if usr_id != session['ids']:
                return 'post not found'
        else:
            return 'post not found'

        # if 'loggedin' in session:
        #     if usr_id == session['ids']:
        #         like_data = post_info['like']
        #         like = len(like_data)
        #         return render_template('detail.html',post_info = post_info, usr_id = usr_id, like = like)

        # print 'post not found'

    # print(post_info)
    # print(type(session['ids']))
    # print(usr_id)
    like_data = post_info['like']
    like = len(like_data)

    return render_template('detail.html',
                           post_info=post_info,
                           usr_id=usr_id,
                           like=like)
예제 #8
0
def get_all_messages(postId):

    all_comments = []
    all_post_comment = Post.find_one({'_id': ObjectId(postId)},
                                     {'comments': 1})
    print(all_post_comment)
    all_post_comment_id = all_post_comment['comments'][-5:]
    all_post_comment_id.reverse()
    print(all_post_comment_id)

    for comment_id in all_post_comment_id:
        comment = Comments.find_one({'_id': ObjectId(comment_id)})
        author = User.find_one({'_id': ObjectId(comment['author'])})
        comment_checked = {
            'username': author['username'],
            'userid': comment['author'],
            'content': comment['content']
        }

        all_comments.append(comment_checked)
        # comment['username'] = author['username']
        # all_comments.append(comment)

    # print(all_comments)
    return jsonify({
        'status': 'success',
        'message': 'get all message successfull',
        'all_comments': dumps(all_comments)
    })
예제 #9
0
def user(id):
    print(id)
    post_list = []
    user_info = User.find_one({"_id": ObjectId(id)})
    # check if user is deactiate
    if user_info['isActive'] == False:
        if 'loggedin' in session:
            if session['ids'] == str(user_info['_id']):
                return render_template('user_deactivate.html',
                                       deactivate_status='user_valid')

        return render_template('user_deactivate.html',
                               deactivate_status='guest')

    user_post = Post.find({"author.id": ObjectId(id)})
    print(user_info)
    for post in user_post:
        # print(post)
        post_list.append(post)
    post_number = len(post_list)
    post_list.reverse()
    return render_template('user.html',
                           user_ids=str(user_info['_id']),
                           user_info=user_info,
                           user_post=post_list,
                           post_number=post_number)
예제 #10
0
def get_album_suggest(userId):
    all_suggest_post = Post.find({'author.id': ObjectId(userId)})

    return jsonify({
        'status': 'success',
        'suggestPost': dumps(all_suggest_post)
    })
예제 #11
0
def get_messages_lazy(postId):
    if request.method == 'POST':

        all_comments = []
        start_message_index = request.json['lazyIndex']

        all_post_comment = Post.find_one({'_id': ObjectId(postId)},
                                         {'comments': 1})
        reversed_post_comment_list = all_post_comment[
            'comments'][::-1]  #reverse array
        all_post_comment_id = reversed_post_comment_list[
            start_message_index:start_message_index + 5]
        print(all_post_comment_id)

        for comment_id in all_post_comment_id:
            comment = Comments.find_one({'_id': ObjectId(comment_id)})
            author = User.find_one({'_id': ObjectId(comment['author'])})
            comment_checked = {
                'username': author['username'],
                'userid': comment['author'],
                'content': comment['content']
            }

            all_comments.append(comment_checked)
            # comment['username'] = author['username']
            # all_comments.append(comment)

        return jsonify({
            'status': 'success',
            'message': 'get all message successfull',
            'all_comments': dumps(all_comments)
        })
    else:
        return 'invalid method'
예제 #12
0
def post_delete(id):
    if 'loggedin' in session:
        post_data = Post.find_one({'_id': ObjectId(id)})
        author_id = str(post_data['author']['id'])
        # print(author_id)
        if author_id == session['ids']:
            try:
                Post.delete_one({'_id': ObjectId(id)})
                print('post delete')

                return redirect('/')
            except:
                return jsonify({'message': 'post delete fail'})
        else:
            return ('', 204)
    else:
        return redirect('/login')
예제 #13
0
def get_album_detail(albumId):
    album_info = Albums.find_one({'_id': ObjectId(albumId)})
    # print(album_info['postId'])
    post_list = Post.find({'_id': {'$in': album_info['postId']}})

    return jsonify({
        'status': 'success',
        'postList': dumps(post_list),
        'albumName': album_info['title'],
    })
예제 #14
0
def user(id):
    print(id)
    post_list = []
    user_info = User.find_one({"_id": ObjectId(id)})
    user_post = Post.find({"author.id": ObjectId(id)})
    # print(user_info)
    for post in user_post:
        # print(post)
        post_list.append(post)
    post_number = len(post_list)
    post_list.reverse()
    return render_template('user.html',
                           user_info=user_info,
                           user_post=post_list,
                           post_number=post_number)
예제 #15
0
def check_deactivate_post(id):
    deactivate_users_list = get_deactivate_userid_list()

    try:
        deactivate_post = Post.find_one({
            '_id': ObjectId(id),
            'author.id': {
                '$in': deactivate_users_list
            }
        })
        print(deactivate_post)
        if deactivate_post:
            return True
        else:
            return False
    except:
        print('error:', sys.exc_info()[0])
예제 #16
0
def admin_page(page):
    if 'admin_logged' in session:
        post_list = []
        posts = Post.find()
        # print(posts)
        for post in posts:
            post_list.append(post)
        post_list.reverse()
        print(post_list)

        if page == 'waiting':
            return render_template('admin_waiting_post.html', posts=post_list)
        elif page == 'checked':
            return render_template('admin_checked_post.html', posts=post_list)
        elif page == 'admin_manager':
            if session['is_admin'] == True:
                return render_template('admin_admin_manager.html')
            else:
                return 'You are not allowed'
        else:
            return 'page not found 404!'
    else:
        return redirect('/admin_login')
예제 #17
0
def detail(id):
    # print(id)
    post_info = Post.find_one({"_id": ObjectId(id)})
    # print(post_info)
    return render_template('detail.html', post_info=post_info)
예제 #18
0
def post_allow(id):
    Post.update_one({'_id': ObjectId(id)}, {'$set': {'check': True}})
    return redirect('/admin_page/checked')
예제 #19
0
def post_ban(id):
    Post.update_one({'_id': ObjectId(id)}, {'$set': {'check': False}})
    return redirect('/admin_page/waiting')