Exemple #1
0
def save_cells(data):
    for id_ in data["ids"]:
        Table.objects(id=id_).update(set__status=data["value"])
    emit("CHANGE_STATUS", {
        "ids": data["ids"],
        "value": data["value"]
    },
         broadcast=True)
Exemple #2
0
def setup_general():
    """Runs the set-up needed for both local development and production.
       Also sets up first admin user."""
    Player.insert_players()
    properties = [
        Property(price=10, rent=2),
        Property(price=12, rent=3),
        Property(price=50, rent=20),
        Property(price=50, rent=21),
        Property(price=40, rent=15),
        Property(price=100, rent=66),
        Property(price=150, rent=66),
        Property(price=200, rent=90),
        Property(price=200, rent=91),
        Property(price=250, rent=95),
        Property(price=270, rent=100),
        Property(price=300, rent=120),
        Property(price=500, rent=200),
        Property(price=1000, rent=300),
        Property(price=2000, rent=600),
        Property(price=4000, rent=1200),
        Property(price=4100, rent=1250),
        Property(price=4200, rent=1300),
        Property(price=4300, rent=1350),
        Property(price=4400, rent=1400)
    ]
    table = Table(name='default', properties=properties)
    db.session.add(table)
    db.session.commit()
def load_tables(file_name):
    '''
    Load table metadata from CSV file

    :param file_Name: The name of the CSV file to load table metadata from

    .. todo:: Need to test against table and location
    '''

    LOGGER.info("Loading table metadata...")

    with open(file_name, 'rt') as csvfile:
        reader = csv.DictReader(csvfile, delimiter=',')
        for row in reader:
            LOGGER.info("Loading %s.%s", row['location'], row['table'])

            # TODO: Need to test against table and location
            if db.session.query(
                    Table.id).filter_by(name=row['table']).scalar():
                LOGGER.info("Table %s.%s already exists", row['location'],
                            row['table'])
            else:
                l = Location.query.filter_by(name=row['location']).first()

                record = Table(
                    **{
                        'name': row['table'],
                        'description': row['description'],
                        'location': l
                    })
                db.session.add(record)
                db.session.commit()
Exemple #4
0
def index():
    form = BookingForm()  #Variabel för formen som finns i forms.py

    if form.validate_on_submit():

        try:
            if int(form.tableInt.data) <= 47 and int(
                    form.tableInt.data
            ) >= 1:  #Verifierar att användaren inte tar något bordsnummer som inte finns i kartan
                table = Table(
                    tableInt=int(form.tableInt.data),
                    isBooked=True,
                    username=current_user.username
                )  #Den här variabeln ger datan som sedan ska läggas till i databasen
                db.session.add(table)  #Lägg till i databasen
                db.session.commit()  #Uppdatera databasen med ny data
                flash('Du har nu bokat ett bord')  ## Nu funkar allt bra
            else:  ##om användaren skirver in t.ex. 56 kommer den här köras
                flash('Det finns ingen plats som heter så')
        except:  #Om det blir helt fel, t.ex. om användaren skirver in bokstäver i formen, så hamnar man här, därför att formens data konverteras till int
            flash(
                'Bokningen kunde inte slutföras, kolla att du inte tar en upptagen plats!'
            )
        return redirect(url_for('index'))  ##användaren skickas tll hemsidan
    tableInfo = Table.query.order_by(
        Table.tableInt).all()  #variabel som har värderna i modelen Table

    return render_template(
        'index.html', title='Home', form=form, tableInfo=tableInfo
    )  #visar hemsidan och skickar med information som kan användas med jinja2
Exemple #5
0
def updateContent():
    try:
        position, content = [
            request.get_json()[k] for k in ("position", "content")
        ]
        cell = Table(position=position, content=content)
        db.session.merge(cell)
        db.session.commit()
        return jsonify(success=True)
    except:
        return jsonify(success=False)
Exemple #6
0
def set_hash(hash):
    t = Table(hash=hash)
    db.session.add(t)

    try:
        db.session.commit()
        result = True
    except IntegrityError as e:
        app.logger.error(e)
        result = False

    return jsonify(result=result)
Exemple #7
0
def save_cell(data):
    value = data["value"]
    if "title" in value.keys():
        Table.objects(id=data["id"]).update(set__title=value["title"])
        emit("CHANGE_TITLE", {
            "id": data["id"],
            "value": value["title"]
        },
             broadcast=True)
    elif "date" in value.keys():
        Table.objects(id=data["id"]).update(set__date=value["date"])
        emit("CHANGE_DATE", {
            "id": data["id"],
            "value": value["date"]
        },
             broadcast=True)
    elif "number" in value.keys():
        if value["number"] == "":
            value["number"] = 0
        Table.objects(id=data["id"]).update(set__number=value["number"])
        emit("CHANGE_NUMBER", {
            "id": data["id"],
            "value": value["number"]
        },
             broadcast=True)
Exemple #8
0
    def post(self):
        """
        Create new table

        :return: New table key phrase
        :rtype:  dict/json
        """

        # Login of authorized user stores in Flask g object
        user = User.query.filter_by(username=g.user.username).first()

        # Create table and add to database
        key = self.newPhraseIfAlreadyExists()
        table = Table(table_key=key, table_date=datetime.utcnow())

        # TODO: Delete try-except or stop recursive key generation after X tries
        try:
            db.session.add(table)
            db.session.flush()
        except IntegrityError:
            db.session.rollback()
            abort(409, message="Table '{}' already exist".format(key))

        # Create user-table dependency
        user_table = UserTable(user_id=user.id, table_id=table.id)

        try:
            db.session.add(user_table)
            db.session.commit()
            # Return JSON using template
            return table, 201
        except IntegrityError:
            db.session.rollback()
            abort(406,
                  message="Username '{}' already connected with table".format(
                      user.username))
def push(code):
    table = Table(code)
    db.session.add(table)
    db.session.commit()
    return "success!"
Exemple #10
0
def tables(id):
    #""" Get All Tables for a Restaurant. """
    if request.method == 'GET':
        restaurant = Restaurant.query.get(id)
        if restaurant is None:
            return bad_request('Restaurant id is not correct.')

        res_tables = Table.query.filter_by(owner=restaurant).all()

        if res_tables is None or res_tables == []:
            return bad_request('Table id is not correct.')
        else:
            response = jsonify({
                'tables': [res_table.to_dict() for res_table in res_tables],
                '_link':
                url_for('api.tables', id=restaurant.id)
            })
            response.headers['Location'] = url_for('api.tables',
                                                   id=restaurant.id)
            return response

    #""" Create a Table for a restaurant. """
    elif request.method == 'POST':
        data = request.get_json() or {}

        if 'name' not in data:
            return bad_request('Restaurant name was missing from the request.')
        else:
            restaurant = Restaurant.query.filter_by(name=data['name']).first()
            if restaurant is None:
                return bad_request('Restaurant id is not correct.')

        if 'number' not in data:
            return bad_request('Table number was missing from the request.')
        if 'capacity' not in data:
            return bad_request(
                'Capacity for Table was missing from the request.')
        if Table.query.filter_by(owner=restaurant,
                                 number=data['number']).first():
            return bad_request(
                'This Table is already created for this restuarant.')

        res_table = Table()
        res_table.from_dict(data)

        if res_table.restaurant_id == 0:
            return bad_request('Restaurant Id is not correct.')

        db.session.add(res_table)
        db.session.commit()
        response = jsonify(res_table.to_dict())
        response.status_code = 201
        response.headers['Location'] = url_for('api.table',
                                               id=res_table.owner.id,
                                               table_id=res_table.id)
        return response

    #""" PUT method not allowed on this endpoint. """
    elif request.method == 'PUT':
        return bad_request(
            "You cannot update a table on this end point. Use this for a PUT request with a table_id: "
            + url_for('api.restaurant', id=id) + "/tables/<table_id>")

    #""" DELETE method not allowed on this endpoint. """
    elif request.method == 'DELETE':
        return bad_request(
            "You cannot delete a table on this end point. Use this for a DELETE request with a table_id: "
            + url_for('api.restaurant', id=id) + "/tables/<table_id>")

    else:
        return bad_request("That's a bad request.")
Exemple #11
0
from dotenv import load_dotenv
load_dotenv()
from app.models import db
from app import app
from app.models import Employee, Menu, MenuItem, MenuItemType, Table

with app.app_context():
    # db.drop_all()
    # db.create_all()

    user = Employee(name="Margot", employee_number=1234, password="******")

    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")

    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    tea = MenuItem(name="Lingonberry Tea", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya", price=21.98, type=entrees, menu=dinner)
    parm = MenuItem(name="Eggplant Parmesan", price=21.98, type=entrees, menu=dinner)

    for index in range(1, 11):
        db.session.add(Table(capacity=index, number=index))

    db.session.add(dinner)
    db.session.add(user)
    db.session.commit()
Exemple #12
0
def add_row(data):
    newRow = Table(number=0, title='Default title', date=data,
                   status="New").save()
    json_row = newRow.to_json()
    emit("ADD_ROW", json_row, broadcast=True)
Exemple #13
0
load_dotenv()

from app import app, db
from app.models import Employee, Menu, MenuItem, MenuItemType, Table

with app.app_context():
    db.drop_all()
    db.create_all()

    employee = Employee(name="Margot",
                        employee_number=1234,
                        password="******")
    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")
    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya",
                         price=21.98,
                         type=entrees,
                         menu=dinner)

    for num in range(1, 11):
        db.session.add(Table(number=num, capacity=num))

    db.session.add(employee)
    db.session.add(dinner)
    db.session.commit()
print("%s contains %s links" % (t.term, t.links.count()))

l1 = Link.query.filter_by(id=2).first()
print(l1.text)
t.links.append(l1)

l2 = Link.query.filter_by(id=4).first()
t.links.append(l2)
db.session.commit()

# Create Table and Columns

l = Location(name='PROD_DB', description='/data/prod/risk_mart');

t = Table(name='ACCOUNT_HISTORY', location=l)

c1 = Column(name='DATE_KEY', type='NUM', length='8', format='DATE9.', table=t)
c2 = Column(name='ACCOUNT_ID', type='NUM', length='8', format='21.', table=t)
c3 = Column(name='APPLICATION_ID', type='NUM', length='8', format='3.', table=t)
c4 = Column(name='BALANCE_AMT', type='NUM', length='8', format='20.', table=t)

db.session.add(l)
db.session.add(t)
db.session.add(c1)
db.session.add(c2)
db.session.add(c3)
db.session.add(c4)

# Create Business Rule
Exemple #15
0
    db.session.add(employee1)
    db.session.add(employee2)

    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")

    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya", price=21.98, type=entrees, menu=dinner)

    db.session.add(dinner)

    table1 = Table(number=1, capacity=1)
    table2 = Table(number=2, capacity=2)
    table3 = Table(number=3, capacity=3)
    table4 = Table(number=4, capacity=4)
    table5 = Table(number=5, capacity=5)
    table6 = Table(number=6, capacity=6)
    table7 = Table(number=7, capacity=7)
    table8 = Table(number=8, capacity=8)
    table9 = Table(number=9, capacity=9)
    table10 = Table(number=10, capacity=10)
    db.session.add(table1)
    db.session.add(table2)
    db.session.add(table3)

    order1 = Order(employee_id=1, table_id=1, finished=False)
    db.session.add(order1)
Exemple #16
0
                        password="******")

    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")

    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya",
                         price=21.98,
                         type=entrees,
                         menu=dinner)

    table_1 = Table(number=1, capacity=2)
    table_2 = Table(number=2, capacity=2)
    table_3 = Table(number=3, capacity=2)
    table_4 = Table(number=4, capacity=5)
    table_5 = Table(number=5, capacity=5)
    table_6 = Table(number=6, capacity=4)
    table_7 = Table(number=7, capacity=4)
    table_8 = Table(number=8, capacity=8)
    table_9 = Table(number=9, capacity=5)
    table_10 = Table(number=10, capacity=8)

    order_1 = Order(employee=employee,
                    table=table_2,
                    finished=False,
                    details=[fries])
Exemple #17
0
for o in users:
    user = User(authority=o['authority'],
                first_name=o['first_name'],
                family_name=o['family_name'],
                username=o['username'],
                password=o['password'],
                email=o['email'],
                phone=o['phone'])
    user.set_password(o['password'])
    db.session.add(user)
    db.session.commit()

for obj in tables:
    print(obj)
    table = Table(id=obj['id'], name=obj['name'])
    db.session.add(table)

for obj in provinces:
    print(obj)
    province = Province(id=obj['id'],
                        name=obj['name'],
                        created_at=datetime.datetime.today(),
                        updated_at=datetime.datetime.today())
    db.session.add(province)

db.session.commit()

for obj in districts:
    print(obj)
    district = District(id=obj['id'],
Exemple #18
0
 def test_table(self):
     t = Table(id=1, hash="abc")
     db.session.add(t)
     db.session.commit()
     t = Table.query.filter_by(id=1).scalar()
     self.assertEqual(t.hash, "abc")
Exemple #19
0
                         password="******")

    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")

    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya",
                         price=21.98,
                         type=entrees,
                         menu=dinner)

    table1 = Table(number=2, capacity=5)
    table2 = Table(number=3, capacity=5)
    table3 = Table(number=4, capacity=5)
    table4 = Table(number=5, capacity=5)
    table5 = Table(number=6, capacity=5)
    table6 = Table(number=7, capacity=5)
    table7 = Table(number=8, capacity=5)
    table8 = Table(number=9, capacity=5)
    table9 = Table(number=10, capacity=5)
    table10 = Table(number=11, capacity=5)
    table11 = Table(number=12, capacity=5)

    db.session.add(table1)
    db.session.add(table2)
    db.session.add(table3)
    db.session.add(table4)
Exemple #20
0
def delete_rows(ids):
    for id_ in ids:
        Table.objects(id=id_).delete()
    emit("DELETE_ROWS", ids, broadcast=True)
Exemple #21
0
def push():
    code = json.loads(request.get_data())
    table = Table(code["code"])
    db.session.add(table)
    db.session.commit()
    return "success!"
with app.app_context():
    db.drop_all()
    db.create_all()

    employee = Employee(name="Margot",
                        employee_number=1234,
                        password="******")

    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")

    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya",
                         price=21.98,
                         type=entrees,
                         menu=dinner)

    i = 1
    while i < 11:
        db.session.add(Table(number=i, capacity=randint(1, 20)))
        i += 1

    db.session.add(dinner)
    db.session.add(employee)
    db.session.commit()
    employee = Employee(
        name="Margot",
        employee_number=1234,
        password="******",
    )

    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")

    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya",
                         price=21.98,
                         type=entrees,
                         menu=dinner)

    tables = [Table(number=n, capacity=4) for n in range(1, 11)]

    sample_order = Order(employee_id=1, table_id=1, finished=False)

    db.session.add(employee)
    db.session.add(dinner)
    for table in tables:
        db.session.add(table)
    db.session.add(sample_order)

    db.session.commit()
Exemple #24
0
                         type=entrees,
                         menus=dinner)

    table1 = 1
    table2 = 2
    table3 = 3
    table4 = 4
    table5 = 5
    table6 = 6
    table7 = 7
    table8 = 8
    table9 = 9
    table10 = 10
    tables = [
        table1, table2, table3, table4, table5, table6, table7, table8, table9,
        table10
    ]
    for table in tables:
        table = Table(number=table, capacity=4)
        db.session.add(table)

    db.session.add(employee)
    db.session.add(dinner)
    db.session.add(beverages)
    db.session.add(entrees)
    db.session.add(sides)
    db.session.add(fries)
    db.session.add(drp)
    db.session.add(jambalaya)
    db.session.commit()
with app.app_context():
    db.drop_all()
    db.create_all()

    employee = Employee(name="Margot",
                        employee_number=1234,
                        password="******")
    beverages = MenuItemType(name="Beverages")
    entrees = MenuItemType(name="Entrees")
    sides = MenuItemType(name="Sides")

    dinner = Menu(name="Dinner")
    tables = []
    for i in range(1, 11):
        tables.append(Table(number=i, capacity=10))

    order = Order(employee_id=1, table_id=1, finished=True)
    # order2 = Order(employee_id = 1, table_id = 2, finished=True)

    order_details = OrderDetail(order_id=1, menu_item_id=1)
    # order_details1 = OrderDetail(order_id = 1, menu_item_id = 1)
    # order_details2 = OrderDetail(order_id = 2, menu_item_id = 1)

    fries = MenuItem(name="French fries", price=3.50, type=sides, menu=dinner)
    drp = MenuItem(name="Dr. Pepper", price=1.0, type=beverages, menu=dinner)
    jambalaya = MenuItem(name="Jambalaya",
                         price=21.98,
                         type=entrees,
                         menu=dinner)
    # db.session.add_all(tables)