Exemple #1
0
def edit_book(book_id):
    if 'username' not in login_session:
        return redirect('/books')
    editedBook = session.query(models.Book).filter_by(id=book_id).one()
    user = c.get_current_user()

    if editedBook.user_id != login_session['user_id']:
        return user_error()
    if user.id == editedBook.user_id:
        if request.method == 'POST':
            editedBook.book_img = request.form['book_img']
            editedBook.book_title = request.form['book_title']
            editedBook.book_author = request.form['book_author']
            editedBook.book_description = request.form['book_description']
            editedBook.book_url = request.form['book_url']
            editedBook.language_id = request.form['language_id']

            session.add(editedBook)
            session.commit()
            return redirect(url_for('books.index'))
        else:
            return render_template('edit_book.jinja2',
                                   book=c.get_book(book_id),
                                   languages=c.get_languages(),
                                   user=c.get_current_user())
def check_images():
    
    if app.config['ENABLE_IMAGE_MODERATION'] == False:
        return index()

    subreddit = request.args.get('article_source')
    pic_source_url = "http://www.reddit.com"
    pic_source_name = 'reddit'
    
    #We should first check that the game is actually there


    current_uuid = get_uuid_from_cookie(request.cookies)
    update_article_source(current_uuid, subreddit)
    update_images_validation(current_uuid)
    current_user = get_current_user(current_uuid)

    response = make_response( render_template('validate_images.html', 
        pic_source_url = pic_source_url,
        pic_source_name = pic_source_name,
        image_1_id = current_user.current_image_1.id,
        image_1_title = current_user.current_image_1.title,
        image_1_src = current_user.current_image_1.url,
        image_2_id = current_user.current_image_2.id,
        image_2_src = current_user.current_image_2.url,
        image_2_title = current_user.current_image_2.title
        )
    )
    response.set_cookie(UUID_NAME, current_uuid)
    return response
Exemple #3
0
def get_language_page(language_id):
    if 'username' in login_session:
        return render_template('books.jinja2',
                               books=c.get_book_language(language_id),
                               languages=c.get_languages(),
                               user=c.get_current_user())
    return render_template('books.jinja2',
                           books=c.get_book_language(language_id),
                           languages=c.get_languages(),
                           user='******',
                           STATE=c.make_state())
Exemple #4
0
def delete_book(book_id):
    if get_book(book_id) != login_session['user_id']:
        return user_error()
    if request.method == 'POST':
        session.delete(get_book(book_id))
        session.commit()
        return redirect(url_for('books.index', books=get_books()))
    else:
        return render_template('delete_book.jinja2',
                               books=c.get_book(book_id),
                               languages=c.get_languages(),
                               user=c.get_current_user())
Exemple #5
0
def index():
    if 'username' in login_session:
        return render_template('books.jinja2',
                               books=models.Book.get_books(),
                               languages=models.Language.get_languages(),
                               user=c.get_current_user())
    # This creates a random string of information that will be used in the
    # thrid-party authentication.
    return render_template('books.jinja2',
                           books=models.Book.get_books(),
                           languages=models.Language.get_languages(),
                           STATE=c.make_state())
def remove_image():
    print 'remove image called'
    print request.args.get('id')

    image_id = int(request.args.get('id'))

    current_uuid =  get_uuid_from_cookie(request.cookies)
    current_user = get_current_user(current_uuid)

    if image_id == 1:
        temp = current_user.current_image_1

    if image_id == 2:
        temp = current_user.current_image_2
        
    temp.show_to_users = False
    db.session.commit()

    return json.dumps({'status':'OK'})
def update_images_validation(current_uuid):
    current_user = get_current_user(current_uuid)
    query_kwargs = {}
    query_kwargs['hand_validated'] = None
    query_kwargs['year_posted'] = 2014
    if current_user.current_image_source is not None:
        query_kwargs['subreddit'] = current_user.current_image_source


    # [image_1, image_2] = Post.query.filter(Post.hand_validated == None).order_by(db.func.random()).limit(2).all()
    query = Post.query.filter_by(**query_kwargs).order_by(db.func.random())
    print 'remaining', int(query.count())

    [image_1, image_2] = query.limit(2).all()

    current_user.current_image_1_id = image_1.id
    current_user.current_image_2_id = image_2.id

    db.session.commit()
Exemple #8
0
def add_book():
    form = BookForm()
    if request.method == 'POST' and form.validate():
        books = session.query(models.Books).all()
        # Creating a books object to add to the databse.
        book = Books(book_img=request.form['book_img'],
                     book_title=request.form['book_title'],
                     book_author=request.form['book_author'],
                     book_description=request.form['book_description'],
                     book_url=request.form['book_url'],
                     language_id=request.form['language_id'],
                     user_id=login_session['user_id'])
        session.add(book)
        session.commit()
        return redirect(url_for('books.index'))
    else:
        return render_template('add_book.jinja2',
                               languages=c.get_languages(),
                               form=form,
                               user=c.get_current_user())
def get_next_images_validation():

    current_uuid =  get_uuid_from_cookie(request.cookies)
    current_user = get_current_user(current_uuid)

    current_user.current_image_1.hand_validated = True
    current_user.current_image_2.hand_validated = True

    if current_user.current_image_1.show_to_users is None:
        current_user.current_image_1.show_to_users = True

    if current_user.current_image_2.show_to_users is None:
        current_user.current_image_2.show_to_users = True

    db.session.commit()


    update_images_validation(current_uuid)

    next_image_data = {}

    next_image_data['image_1_src'] = current_user.current_image_1.url
    next_image_data['image_1_id']  = current_user.current_image_1.reddit_id
    next_image_data['image_1_title']  = current_user.current_image_1.title




    next_image_data['image_2_src'] = current_user.current_image_2.url
    next_image_data['image_2_id']  = current_user.current_image_2.reddit_id
    next_image_data['image_2_title']  = current_user.current_image_2.title


    next_image_data['status'] = 'OK'


    return json.dumps(next_image_data)