def editResto(resto_id):
    restaurant = session.query(Restaurant).filter_by(id=resto_id).one()
    name_resto = restaurant.name
    description_resto = restaurant.description
    image_resto = restaurant.image[15:]
    user = session.query(User).filter_by(name=login_session['username']).one()
    if restaurant.user_id != user.id:
        flash("""You are not allowed to edit this content, 
        you are allowed to edit only the restaurants that you created""")
        return redirect(url_for('showallrestaurants'))
    if request.method == 'POST':
        if request.form['name']:
            restaurant.name = request.form['name']
            restaurant.description = request.form['description']
            file_img = request.files['file']
            filename = secure_filename(file_img.filename)
            file_img.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            img_url = '/static/images/' + filename
            restaurant.image = img_url
            session.add(restaurant)
            session.commit()
            return redirect(url_for('showallrestaurants'))
    else:
        return render_template('editresto.html',
                               resto_identif=resto_id,
                               name_resto=name_resto,
                               resto_desc=description_resto,
                               resto_image=image_resto)
def editMenuItems(resto_id, item_id):
    item = session.query(MenuItem).filter_by(id=item_id).one()
    item_name = item.name
    restaurant = session.query(Restaurant).filter_by(id=resto_id).one()
    user = session.query(User).filter_by(name=login_session['username']).one()
    if restaurant.user_id != user.id:
        flash("""You are not allowed to edit this content,
        you are allowed to edit only the restaurants that you created""")
        return redirect(url_for('restoMenu', resto_ID=resto_id))
    if request.method == 'POST':
        if request.form['name']:
            item.name = request.form['name']
            item.description = request.form['description']
            item.price = request.form['price']
            item.course = request.form['course']
            session.add(item)
            session.commit()
            return redirect(url_for('restoMenu', resto_ID=resto_id))
    else:
        return render_template('edit_menu_item.html',
                               price=item.price,
                               course=item.course,
                               resto=resto_id,
                               item=item_id,
                               item_name=item_name,
                               item_description=item.description)
def restoMenu(resto_ID):
    resto = session.query(Restaurant).filter_by(id=resto_ID).one()
    menu = session.query(MenuItem).filter_by(restaurant_id=resto_ID).all()
    name_resto = resto.name
    if 'username' not in login_session:
        return render_template('public_resto_menu.html',
                               resto_identif=resto_ID,
                               menu=menu,
                               name_resto=name_resto)
    else:
        user = session.query(User).filter_by(
            name=login_session['username']).one()  # NOQA
        if resto.user_id != user.id:
            return render_template('public_resto_menu.html',
                                   resto_identif=resto_ID,
                                   menu=menu,
                                   name_resto=name_resto)
        else:
            if menu == []:
                return redirect(url_for('addNewMenuItem', resto_id=resto_ID))
            return render_template('resto_menu.html',
                                   resto_identif=resto_ID,
                                   menu=menu,
                                   name_resto=name_resto,
                                   creator=resto.user_id)
def showallrestaurants():
    restaurants = session.query(Restaurant).order_by(Restaurant.name).all()
    if 'username' not in login_session:
        return render_template('public_allrestos.html', restos=restaurants)
    else:
        user = session.query(User).\
            filter_by(name=login_session['username']).one()
        return render_template('allrestos.html', restos=restaurants, user=user)
Esempio n. 5
0
def getUserID(email):
    try:
        user = session.query(User).\
            filter_by(email=login_session['email']).one()
        return user.id
    except:
        return None
Esempio n. 6
0
 def process(cls):
     email_sender = EmailServer()
     while True:
         session.commit(
         )  # to refresh the transaction in case of multiple sessions,
         # as long-living sessions/transactions won't detect changes
         unprocessed_payment = session.query(Payments)\
                                      .filter(Payments.process_error == false())\
                                      .filter(Payments.payment_processed_date.is_(None))\
                                      .first()
         try:
             # payment rounting by account account_number
             # Rounting can be done with multiple ways, stored in Partner.notify_method'''
             if unprocessed_payment.partner.notify_method == 'api':
                 requests.post(
                     unprocessed_payment.partner.contact_path,
                     data=unprocessed_payment.as_dict_for_partner())
             if unprocessed_payment.partner.notify_method == 'email':
                 email_sender.send_email(
                     data=unprocessed_payment.as_dict_for_partner())
         except Exception as e:
             logging.error('error with payment id {0}. Error: {1}'.format(
                 unprocessed_payment.id, e))
             unprocessed_payment.process_error = True
         else:
             unprocessed_payment.payment_processed_date = datetime.datetime.now(
             )
         session.commit()
def createNewResto():
    #if 'username' not in login_session:
    #    return redirect('/login')
    if request.method == 'POST':
        file_img = request.files['file']
        filename = secure_filename(file_img.filename)
        file_img.save(os.path.join(UPLOAD_FOLDER, filename))
        filename_full = './static/images/' + filename
        new_image = Image.open(filename_full)
        new_image.thumbnail((500, 400))
        img_url_resize = filename[:-4] + '_thumb.jpg'
        new_image.save(os.path.join(UPLOAD_FOLDER, img_url_resize))
        resized_url = '/static/images/' + img_url_resize
        user = session.query(User). \
            filter_by(name=login_session['username']).one()
        new_resto = Restaurant(image=resized_url,
                               name=request.form['name'],
                               description=request.form['description'],
                               user_id=user.id)
        # print new_resto.image
        session.add(new_resto)
        session.commit()
        flash("The restaurant has been added to the list fof restaurants.")
        return redirect(url_for('showallrestaurants'))
    return render_template('addresto.html')
def deleteResto(resto_id):
    resto_to_delete = session.query(Restaurant).filter_by(id=resto_id).one()
    resto_name = resto_to_delete.name
    user = session.query(User).filter_by(name=login_session['username']).one()
    #if 'username' not in login_session:
    #    return redirect('/login')
    if resto_to_delete.user_id != user.id:
        flash("You are not allowed to delete this content")
        return redirect(url_for('showallrestaurants'))
    if request.method == 'POST':
        session.delete(resto_to_delete)
        session.commit()
        flash("The restaurant %s has been deleted" % resto_name)
        return redirect(url_for('showallrestaurants'))
    return render_template('deleteresto.html',
                           resto=resto_id,
                           resto_name=resto_to_delete.name)
def deleteMenuItem(resto_id, item_id):
    res = session.query(Restaurant).filter_by(id=resto_id).one()
    resto_name = res.name
    item_to_delete = session.query(MenuItem).filter_by(id=item_id).one()
    item_name = item_to_delete.name
    user = session.query(User).filter_by(name=login_session['username']).one()
    if res.user_id != user.id:
        flash("You are not allowed to delete this content")
        return redirect(url_for('restoMenu', resto_ID=resto_id))
    if request.method == 'POST':
        session.delete(item_to_delete)
        session.commit()
        return redirect(url_for('restoMenu', resto_ID=resto_id))
    return render_template('delete_menu_item.html',
                           resto=resto_id,
                           item=item_id,
                           item_name=item_name,
                           resto_name=resto_name)
Esempio n. 10
0
def createUser(login_session):
    newUser = User(
        name=login_session['username'],
        email=login_session['email'],
        picture=login_session['picture']
    )
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(email=login_session['email']).one()
    return user.id
def addNewMenuItem(resto_id):
    resto = session.query(Restaurant).filter_by(id=resto_id).one()
    resto_name = resto.name
    user = session.query(User).filter_by(name=login_session['username']).one()
    if resto.user_id != user.id:
        flash("""You are not allowed to edit this content,
        you are allowed to edit only the restaurants that you created""")
        return redirect(url_for('restoMenu', resto_ID=resto_id))
    if request.method == 'POST':
        added_item = MenuItem(name=request.form['name'],
                              description=request.form['description'],
                              price=request.form['price'],
                              course=request.form['course'],
                              restaurant_id=resto_id,
                              user_id=resto.user_id)
        session.add(added_item)
        session.commit()
        return redirect(url_for('restoMenu', resto_ID=resto_id))
    return render_template('add_menu_item.html',
                           resto=resto_id,
                           resto_name=resto_name)
Esempio n. 12
0
def africa_bank():
    if request.headers['Content-Type'] == 'application/json':
        json_object = request.json
        storage_key = payment_store(json_object)
        partner = session.query(Partners).get(json_object['account_number'])
        if not partner:
            # we can handle this, throwing logging etc here
            return Response('Account number not registered', status=500)
        payer = session.query(Payers).get(json_object['reference_number'])
        if not payer:
            # we can handle this to create a new payer with this reference number, throwing logging etc here
            return Response('Reference number not registered', status=500)
        session.add(
            Payments(
                partner=partner,
                payer=payer,
                amount=json_object['amount'],
                currency=json_object['currency'],
                # payment_date=json_object['payment_date'],
                proof_key=storage_key))
        session.commit()
        return Response('Success', status=200)
    else:
        return '415 Unsupported Content-Type'
Esempio n. 13
0
def getUserInfo(user_id):
    try:
        user = session.query(User).filter_by(id=user_id).one()
        return user
    except:
        return None
def menuItem(resto_id, item_id):
    restaurant = session.query(Restaurant).filter_by(id=resto_id).one()
    item = session.query(MenuItem).filter_by(id=item_id).one()
    return jsonify(MenuItem=item.serialize)
def listrestoJSON():
    restaurants = session.query(Restaurant).all()
    return jsonify(
        Restaurants=[restaurant.serialize for restaurant in restaurants])
def restoMenuJSON(resto_ID):
    menu = session.query(MenuItem).filter_by(restaurant_id=resto_ID).all()
    if menu != []:
        return jsonify(MenuItems=[item.serialize for item in menu])
    else:
        print 'No menu items'