Exemple #1
0
def create_vote(phone_id, db):
    """Creates vote."""
    user = controller.get_user(db, phone_id)
    if not user:
        abort(400, "Invalid or unregistered phone id")

    title = request.query.title
    text = request.query.text
    is_private = request.query.is_private or False
    is_multiple_choice = request.query.is_multiple_choice or False
    start_date = get_date(request.query.start_date)
    end_date = get_date(request.query.end_date)

    #    if not fullname or not email:
    #        abort(400, 'User name or email are not specified in request')
    #
    # TODO: params
    vote = controller.create_vote(
        db=db,
        author=user,
        title=title,
        text=text,
        is_private=is_private,
        is_multiple_choice=is_multiple_choice,
        start_date=start_date,
        end_date=end_date,
    )
    response.content_type = "application/json"
    return json_encode(vote)
    finally:
        session.close()

    # create users
    logger.debug('Creating users')
    user1 = controller.create_user(db, 'test_id_1', 'Barak Obama', '*****@*****.**')
    user2 = controller.create_user(db, 'test_id_2', 'John Smith', '*****@*****.**')
    user3 = controller.create_user(db, 'test_id_3', 'Ivan Petrov', '*****@*****.**')
    db.commit()

    # create vote and options
    logger.debug('Creating vote and options')
    vote1 = controller.create_vote(db=db,
        author=user1,
        title='USA President Election',
        text='Choose new USA president',
        is_private=False,
        is_multiple_choice=False,
        start_date=datetime.now() - timedelta(hours=2),
        end_date=datetime.now() + timedelta(hours=10))
    db.commit()

    controller.create_vote_options(db=db,
        vote=vote1,
        options=['Theodore Roosevelt',
                 'John F. Kennedy',
                 'William Howard Taft',
                 'Lyndon B. Johnson',
                 'Woodrow Wilson',
                 'Richard M. Nixon',
                 'Warren G. Harding',
                 'Gerald R. Ford',