Ejemplo n.º 1
0
def users_presence(day):
    """
    Get list of user presence of day
    :param day: day_id eg: 'histories_1'
    :return:
    """
    history = Histories(day)
    users = history.get_history_of_day()
    return get_users_detail(users)
Ejemplo n.º 2
0
def draw():
    restaurants = Restaurants.query.all()

    if not restaurants:
        return redirect('/create-restaurant')

    random_restaurant = choice(restaurants)

    # If there is a connection error, use try except module
    try:
        restaurant = Restaurants.query.get(random_restaurant.id)
        restaurant.draw += 1

        history = Histories(restaurant_id=restaurant.id)

        db_session.add(history)
        db_session.commit()

    # If Histories cannot be saved, do a rollback of the whole user operation and redirect the user back to the homepage.
    # It rolls back any change that wasn't commited:
    except:
        db_session.rollback()
        return redirect('/')

    now = datetime.datetime.now()

    return render_template('draw.html', restaurant=restaurant, now=now)
Ejemplo n.º 3
0
def draw():
    restaurants = Restaurants.query.all()

    if not restaurants:
        redirect('/create-restaurant')
    random_restaurant = choice(restaurants)
    try:
        restaurant = Restaurants.query.get(random_restaurant.id)
        restaurant.draw += 1
        history = Histories(restaurant_id=restaurant.id)
        db_session.add(history)
        db_session.commit()
    except:
        db_session.rollback()
        return redirect('/')
    now = datetime.datetime.now()
    return render_template('draw.html', restaurant=restaurant, now=now)
Ejemplo n.º 4
0
def login_user(form, user_id):
    """
    Generate
    :param form:
    :return:
    """
    if 'day' in form:
        # Need check permission of user.
        history = Histories(day=form['day'])
    else:
        history = Histories()
    history.append(user_id)
    return history