Ejemplo n.º 1
0
def vote_startup(id):
    startup = Startup.query.filter_by(is_confirm=True, id=id).first_or_404()
    ip = "startup" + request.remote_addr
    if r1.get(ip):
        return jsonify({}), 403
    else:
        startup.liked_count += 1
        db.session.add(startup)
        db.session.commit()
        r1.set(ip, ip)
        return jsonify({}), 200
Ejemplo n.º 2
0
def vote_course(id):
    course = Course.query.filter_by(is_confirm=True, id=id).first_or_404()
    ip = "course" + request.remote_addr
    if r1.get(ip):
        return jsonify({}), 403
    else:
        course.liked_count += 1
        db.session.add(course)
        db.session.commit()
        r1.set(ip, ip)
        return jsonify({}), 200
Ejemplo n.º 3
0
def vote_photo(id):
    photo = Photo.query.filter_by(is_confirm=True, id=id).first_or_404()
    ip = "photo" + request.remote_addr
    if r1.get(ip):
        return jsonify({}), 403
    else:
        photo.liked_count += 1
        db.session.add(photo)
        db.session.commit()
        r1.set(ip, ip)
        return jsonify({}), 200
Ejemplo n.º 4
0
def get_movie(id):
    movie = Movie.query.get_or_404(id)
    if 'vote' in session.keys():
        if session['vote'] == 1:
            ip = request.remote_addr
            if r1.get(ip):
                flash("每天只能投一次票!")
            else:
                movie.liked_count += 1
                db.session.add(movie)
                db.session.commit()
                flash("投票成功")
                r1.set(ip, ip)
            session['vote'] = 0
            return redirect(url_for('main.get_movie', id=movie.id))
    else:
        session['vote'] = 0
    return render_template('main/movie.html', movie=movie)
Ejemplo n.º 5
0
def get_movie(id):
    movie = Movie.query.get_or_404(id)
    if 'vote' in session.keys():
        if session['vote'] == 1:
            ip = request.remote_addr
            if r1.get(ip):
                flash("每天只能投一次票!")
            else:
                movie.liked_count += 1
                db.session.add(movie)
                db.session.commit()
                flash("投票成功")
                r1.set(ip, ip)
            session['vote'] = 0
            return redirect(url_for('main.get_movie', id=movie.id))
    else:
        session['vote'] = 0
    return render_template('main/movie.html', movie=movie)