예제 #1
0
def movie(id):

    if request.method == "GET":

        movie = _fetch_movie(id)
        if movie is not None:
            if request.is_xhr:
                return jsonify({
                    "service_id": movie.service_id,
                    "title": movie.title,
                    "description": movie.description,
                    "poster": movie.poster,
                    "year": movie.year,
                    "imdb_id": movie.imdb_id,
                    "votes": movie.votes,
                    "in_production": movie.being_made,
                    "produced": movie.already_made,
                    "facebook_uid": movie.facebook_uid,
                    "facebook_name": movie.facebook_name
                })

            voters = _fetch_latest_votes(id)

            return render_template('single.html',
                                   movie=movie,
                                   image_path=settings.IMAGE_PATH,
                                   voters=voters)

    if request.method == "POST":
        form = MovieForm(request.form)
        if form.validate() is False:

            for error in form.errors:
                logging.info(error)

            return abort(500)

        if _validate_user(form.facebook_uid.data, form.facebook_token.data):

            movie = _fetch_movie(form.service_id.data)

            if movie is None:

                m = Movie(service_id=form.service_id.data,
                          title=form.title.data,
                          year=form.year.data.split("-")[0],
                          poster=form.poster.data,
                          description=form.description.data,
                          imdb_id=form.imdb_id.data,
                          facebook_uid=form.facebook_uid.data,
                          facebook_name=form.facebook_name.data)
                m.save()

            return jsonify(result="success")

        return abort(500)

    return abort(404)
예제 #2
0
def new_movie():
    form = MovieForm(request.form)
    if request.method == 'POST' and form.validate():
        # save the album
        movie_created = Movie()

        movie_save_changes(movie_created, form, new=True)
        flash('Movie created successfully!')
        return redirect('/movie')
    return render_template('new_movie.html', form=form)
예제 #3
0
파일: views.py 프로젝트: Skaggivara/reboot
def movie(id):
    
    if request.method == "GET":
        
        movie = _fetch_movie(id)
        if movie is not None:
            if request.is_xhr:
                return jsonify({"service_id":movie.service_id, "title": movie.title, "description": movie.description, "poster": movie.poster, "year": movie.year, "imdb_id": movie.imdb_id, "votes": movie.votes, "in_production": movie.being_made, "produced": movie.already_made, "facebook_uid": movie.facebook_uid, "facebook_name": movie.facebook_name})
            
            voters = _fetch_latest_votes(id)
            
            return render_template('single.html', movie=movie, image_path=settings.IMAGE_PATH, voters=voters)
    
    if request.method == "POST":
        form = MovieForm(request.form)
        if form.validate() is False:
            
            for error in form.errors:
                logging.info(error)
            
            return abort(500)
        
        if _validate_user(form.facebook_uid.data, form.facebook_token.data):
            
            movie = _fetch_movie(form.service_id.data)
            
            if movie is None:
                
                m = Movie(service_id=form.service_id.data, title=form.title.data, year=form.year.data.split("-")[0], poster=form.poster.data, description=form.description.data, imdb_id=form.imdb_id.data, facebook_uid=form.facebook_uid.data, facebook_name=form.facebook_name.data)
                m.save()
            
            return jsonify(result="success")
        
        return abort(500)
    
    return abort(404)