Exemplo n.º 1
0
def save(gall_name):
    collection = conn_board('counters')
    collection.update_one({'collection': 'boardall'}, {'$inc': {'c_id': 1}})
    counter = collection.find_one({'collection': 'boardall'})
    gall_id = counter['c_id']

    collection = conn_board('boardall')

    user_name = current_user.user_name
    gall_title = request.form['gall_title']
    gall_content = request.form['gall_content']
    hit = 0
    now = datetime.datetime.now()
    nowDatetime = now.strftime('%Y-%m-%d %H:%M:%S')

    collection.insert_one({
        'gallid': int(gall_id),
        'name': user_name,
        'title': gall_title,
        'content': gall_content,
        'hit': 0,
        'datetime': nowDatetime,
        'gall': gall_name
    })

    return redirect(url_for('gallery.gall', gall_name=gall_name))
Exemplo n.º 2
0
def search():
    search_name = request.args.get('search_name')
    mongo_conn = conn_board('boardtype')
    result = mongo_conn.find_one({'krname': search_name})
    if result:
        return render_template('search_result.html', search_result=result)
    else:
        return render_template('search_result.html', search_result=None)
Exemplo n.º 3
0
def gall(gall_name):
    cap_gall_name = gall_name.capitalize()
    collection = conn_board('boardtype')
    result = collection.find_one({'name': cap_gall_name})
    krname = result['krname']

    collection = conn_board('boardall')
    result = collection.find({'gall': gall_name})

    if current_user.is_authenticated:
        return render_template('gallery.html',
                               gname=gall_name,
                               gall_name=krname,
                               userinfo=current_user.user_name,
                               data=result)
    return render_template('gallery.html',
                           gname=gall_name,
                           gall_name=krname,
                           data=result)
Exemplo n.º 4
0
def index():
    collection = conn_board('boardtype')
    result = collection.find({})

    collection = conn_board('boardall')
    sorted_collection = collection.find().sort('hit', -1)
    hit_data = []
    cnt = 0
    for document in sorted_collection:
        cnt += 1
        hit_data.append(document)
        if cnt == 4:
            break

    if current_user.is_authenticated:
        return render_template('index.html',
                               hit_data=hit_data,
                               data=result,
                               userinfo=current_user.user_name)
    else:
        return render_template('index.html', hit_data=hit_data, data=result)
Exemplo n.º 5
0
def lookup(gall_name, gall_id):
    collection = conn_board('boardall')
    collection.update_one({'gallid': int(gall_id)}, {'$inc': {'hit': 1}})
    result = collection.find_one({'gallid': int(gall_id)})
    return render_template('lookup.html', data=result, gname=gall_name)