Пример #1
0
	def add_dish(self, name, ingrd, price):
		items = ItemCom().get_all_items()
		d = Dish()
		d.name = name
		d.price = float(price)
		itm_list = ingrd.split(',')
		for i in itm_list:
			for it in items:
				if i == it.name:
					d.items.append(it)
		db.session.add(d)
		db.session.commit()
Пример #2
0
def processEdit(id, eventName, discountPercent, discountAmount, contact,
                rooms):
    """Save the form data into a booking"""
    b = Booking.select().where(Booking.id == id).get()
    food = {}
    for field in request.form:
        if field.startswith('dish_'):
            food[int(field.replace('dish_', ''))] = int(request.form[field])
    b.eventName = eventName
    b.discountPercent = discountPercent
    b.discountAmount = discountAmount
    b.contact_id = contact
    rooms = Room.select().where(Room.id << rooms).execute()
    if Room.areRoomsFree(rooms, b.startTime, b.endTime, id):
        BookingRoom.delete().where(BookingRoom.booking == b).execute()
        for room in rooms:
            br = BookingRoom(booking=b, room=room)
            br.save()
        Order.delete().where(Order.booking == b).execute()
        for f in food:
            if food[f] > 0:
                Order(dish=Dish.get(Dish.id == int(f)),
                      booking=b,
                      quantity=food[f]).save()
        b.calculateTotal()
        b.save()
    else:
        flash(
            'A room that you selected is no longer available.  Please select a new room.',
            'error')
        return redirect(request.referrer)
    flash('Booking Updated', 'success')
    return redirect(url_for('bookings.index'))
Пример #3
0
def post_dish():
    form = DishForm()
    if form.validate_on_submit():
        dish = Dish(dish_name=form.dishName.data,
                    price=form.dishPrice.data,
                    photo=form.dishPhoto.data,
                    deliveryTime=form.dishDeliveryTime.data,
                    expected_order_number=form.dishExpectedOrderNumber.data,
                    current_order_number=0,
                    flavour=form.dishFlavour.data,
                    potential_taboo=form.dishTaboo.data,
                    description=form.dishDescription.data,
                    pick_up_location=form.dishPickUpLocation.data,
                    seller=current_user)
        db.session.add(dish)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('post_dish.html', title='Post a dish', form=form)
Пример #4
0
def edit(id):
    """Display a form to edit a booking"""
    b = Booking.select().where(Booking.id == id)
    booking = prefetch(b, Order, Dish, Caterer, Contact, Organization,
                       BookingRoom, Room, User)[0]
    dishes = prefetch(Dish.select().where(Dish.isDeleted == False),
                      Caterer.select().where(Caterer.isDeleted == False))
    orgs = Organization.select().where((Organization.isDeleted == False) | (
        Organization.id == booking.contact.organization_id))
    cons = Contact.select().where((Contact.isDeleted == False)
                                  | (Contact.id == booking.contact_id))
    print(booking.startTime, booking.endTime, type(booking.endTime))
    rooms = Room.openRooms(booking.startTime, booking.endTime,
                           booking.id).execute()
    contactjson = {}
    for c in cons:
        oid = c.organization_id if c.organization_id is not None else 0
        if oid not in contactjson:
            contactjson[oid] = {}
        contactjson[oid][c.id] = c.name
    roomjson = {}
    for room in rooms:
        roomjson[room.id] = {
            'capacity': room.capacity,
            'rate': float(room.price),
            'adjacentRooms': room.adjacentRoomIds(),
            'name': room.name,
            'id': room.id
        }
    return render_template('bookings/edit.html',
                           booking=booking,
                           dishes=dishes,
                           orgs=orgs,
                           contacts=cons,
                           contactjson=contactjson,
                           rooms=rooms,
                           roomjson=roomjson)
Пример #5
0
def index():
    """List all caterers and their dishes"""
    caterer = Caterer.select().where(Caterer.isDeleted == False)
    dishes = Dish.select().where(Dish.isDeleted == False)
    caterers = prefetch(caterer, dishes)
    return render_template('admin/caterers/index.html', caterers=caterers)
Пример #6
0
          [
              'Italian Beef w/ Fries', 11.85,
              ['Beef', 'Onion', 'Pepper', 'Bread', 'Potato']
          ],
          [
              'Jibarito', 5.95,
              ['Beef', 'Lettuce', 'Tomato', 'Plantain', 'Onion', 'Garlic']
          ]]

ingred_obj = {}
dish_obj = []

for i in ingredients:
    ingred_obj[i[0]] = Item(name=i[0], count=i[1], price=i[2])

for d in dishes:
    dish = Dish(name=d[0], price=d[1])
    for i in d[2]:
        dish.items.append(ingred_obj[i])
    dish_obj.append(dish)

for i in ingred_obj.values():
    db.session.add(i)

for d in dish_obj:
    db.session.add(d)

c = Cash(cash=50000)
db.session.add(c)

db.session.commit()
Пример #7
0
    def post(self, menuid, catid):

        try:
            dish = Dish()

            category = Category.query.filter_by(id=catid).first()
            if category is None or category.delete is True:
                return {'message': 'Bad category'}, 400

            if category.menuId != menuid:
                return {'message': 'Bad menu'}, 400

            form = request.get_json(force=True)

            name = form.get('name')
            if name is None:
                return {'message': 'Dish name is required'}, 400

            rank = form.get('rank')
            if rank is None:
                return {'message': 'Dish rank is required'}, 400
            try:
                rank = int(rank)
            except Exception as e:
                print(e)
                return {'message': 'Dish rank must be integer'}, 400

            img = form.get('img')
            if img is None:
                img = 'https://raw.githubusercontent.com/OrderEase/Server/master/assets/default.png'

            price = form.get('price')
            if price is None:
                return {'message': 'Price is required'}, 400
            try:
                price = float(price)
            except Exception as e:
                print(e)
                return {'message': 'Price must be float number'}, 400

            stock = form.get('stock')
            if stock is None:
                return {'message': 'Dish stock is required'}, 400
            try:
                stock = int(stock)
            except Exception as e:
                print(e)
                return {'message': 'Dish stock must be integer'}, 400

            avaliable = form.get('avaliable')
            if avaliable is None:
                return {'message': 'Dish avaliable is required'}, 400
            try:
                avaliable = int(avaliable)
            except Exception as e:
                print(e)
                return {
                    'message': 'Avaliable must be 0 or 1, 1 means avaliable'
                }, 400
            if avaliable != 0 and avaliable != 1:
                return {
                    'message': 'Avaliable must be 0 or 1, 1 means avaliable'
                }, 400

            description = form.get('description')
            if description is None:
                description = ""

            dish.name = name
            dish.rank = rank
            dish.img = img
            dish.price = price
            dish.stock = stock
            dish.avaliable = avaliable
            dish.description = description
            dish.likes = 0
            dish.catId = catid
            dish.delete = False
            db.session.add(dish)
            db.session.commit()

            return {
                'message': 'Add a new dish successfully',
                'id': dish.id
            }, 200
        except Exception as e:
            print(e)
            return {'message': 'Internal Server Error'}, 500
Пример #8
0
    def test_customer_order(self):
        u1 = User(username='******')
        u2 = User(username='******')
        d1 = Dish(dish_name='rice')
        d2 = Dish(dish_name='noodles')
        d3 = Dish(dish_name='beef')
        d4 = Dish(dish_name='pork')
        d1.seller = u1
        d2.seller = u1
        d3.seller = u2
        d4.seller = u2
        db.session.add(u1)
        db.session.add(u2)
        db.session.add(d1)
        db.session.add(d2)
        db.session.add(d3)
        db.session.add(d4)
        db.session.commit()

        u3 = User(username='******')
        u4 = User(username='******')
        o1 = Order(dish=d2, buyer=u3)
        o2 = Order(dish=d3, buyer=u3)
        o3 = Order(dish=d3, buyer=u4)
        o4 = Order(dish=d4, buyer=u4)
        db.session.add(u3)
        db.session.add(u4)
        db.session.add(o1)
        db.session.add(o2)
        db.session.add(o3)
        db.session.add(o4)
        db.session.commit()

        self.assertEqual(u3.purchasing_history.all(), [o1, o2])
        self.assertEqual(u4.purchasing_history.all(), [o3, o4])
        self.assertEqual(d1.order_lists.all(), [])
        self.assertEqual(d2.order_lists.all(), [o1])
        self.assertEqual(d3.order_lists.all(), [o2, o3])
        self.assertEqual(d4.order_lists.all(), [o4])
Пример #9
0
from app import app
from app.models import db, Category, Dish

with app.app_context():
    category_entities = []
    with open('delivery_categories.csv') as f:
        reader = csv.reader(f)
        for category_id, title in reader:
            if category_id == 'id':
                continue
            category_entity = Category(title=title)
            db.session.add(category_entity)
            category_entities.append(category_entity)
        db.session.commit()

    with open('delivery_items.csv') as f:
        reader = csv.reader(f)

        for dish_id, title, price, description, picture, category_id in reader:
            if dish_id == 'id':
                continue
            dish_entity = Dish(title=title,
                               price=price,
                               description=description,
                               picture=picture,
                               category=category_entities[int(category_id) -
                                                          1])
            db.session.add(dish_entity)
        db.session.commit()
Пример #10
0
    def test_chef_dish(self):
        u1 = User(username='******')
        u2 = User(username='******')
        d1 = Dish(dish_name='rice')
        d2 = Dish(dish_name='noodles')
        d3 = Dish(dish_name='beef')
        d4 = Dish(dish_name='pork')
        d1.seller = u1
        d2.seller = u1
        d3.seller = u2
        d4.seller = u2
        db.session.add(u1)
        db.session.add(u2)
        db.session.add(d1)
        db.session.add(d2)
        db.session.add(d3)
        db.session.add(d4)
        db.session.commit()

        chef1 = User.query.filter_by(username='******').first()
        chef2 = User.query.filter_by(username='******').first()
        dish1 = Dish.query.filter_by(dish_name='rice').first()
        dish2 = Dish.query.filter_by(dish_name='noodles').first()
        dish3 = Dish.query.filter_by(dish_name='beef').first()
        dish4 = Dish.query.filter_by(dish_name='pork').first()
        self.assertEqual(chef1.sales_history.all(), [dish1, dish2])
        self.assertEqual(chef2.sales_history.all(), [dish3, dish4])
Пример #11
0
def restore(id):
    """Restores a soft deleted dish"""
    Dish.update(isDeleted=False).where(Dish.id == id).execute()
    flash('Dish restored', 'success')
    return redirect(url_for('dishes.edit', id=id))
Пример #12
0
def delete(id):
    """Softdeletes a dish"""
    Dish.update(isDeleted=True).where(Dish.id == id).execute()
    flash('Dish deleted', 'success')
    return redirect(url_for('caterers.index'))
Пример #13
0
def processEdit(id, name, price, caterer):
    """Updates a dish based on POST data"""
    Dish.update(name=name, price=price,
                caterer=Caterer.select().where(Caterer.id == caterer).get()).where(Dish.id == id).execute()
    flash("Dish updated", 'success')
    return redirect(url_for('caterers.index'))
Пример #14
0
def edit(id):
    """Display a dish edit form"""
    dish = Dish.select().where(Dish.id == id).get()
    return render_template('admin/dishes/edit.html', dish=dish,
                           caterers=Caterer.select().where((Caterer.isDeleted == False) |
                                                           (Caterer.id == dish.caterer_id)))
Пример #15
0
def processCreate(name, price, caterer):
    """Create a new dish based on POST data"""
    Dish(name=name, price=price, caterer_id=caterer).save()
    flash("Created new dish %s" % name, 'success')
    return redirect(url_for('caterers.index'))