Ejemplo n.º 1
0
def login(username, password):
    connection = get_connection('default')
    cursor = connection.cursor()
    token = generate_token(username, password)
    user_id = cursor.callfunc('login', cx_Oracle.NUMBER, [username, password, token])
    cursor.close()
    return user_id, token
Ejemplo n.º 2
0
def create_rent_contract(rent_contract_id, area_id, tenant_id, landlord_id, form_data):
    data = [
        rent_contract_id,
        tenant_id,
        landlord_id,
        area_id,
        form_data.get('code'),
        form_data.get('start_date'),
        form_data.get('end_date'),
        form_data.get('price'),
        form_data.get('additional_payment'),
        form_data.get('discount'),
        form_data.get('checking_account'),
        form_data.get('requirements'),
    ]
    connection = get_connection('landlords')
    cursor = connection.cursor()
    try:
        cursor.callfunc('meow.create_or_update_contract', cx_Oracle.NUMBER, data)
        cursor.close()
        connection.commit()
        return True
    except cx_Oracle.DatabaseError as e:
        print e
        return False
Ejemplo n.º 3
0
def register_landlord(data):
    fields = [
        None,
        None,
        data.get('username', None),
        data.get('password', None),
        data.get('first_name', None),
        data.get('middle_name', None),
        data.get('last_name', None),
        data.get('email', None),
        data.get('phone', None),
        data.get('organization_name', None),
        data.get('description', None),
    ]

    connection = get_connection('default')
    cursor = connection.cursor()
    try:
        cursor.callfunc('create_or_update_landlord', cx_Oracle.NUMBER, fields)
        cursor.close()
        return True
    except cx_Oracle.DatabaseError as e:
        return False
    finally:
        connection.commit()
Ejemplo n.º 4
0
def get_shopping_malls():
    connection = get_connection('default')
    cursor = connection.cursor()
    data = cursor.callfunc('get_shopping_malls', cx_Oracle.CURSOR, [])
    data = [list(obj[:5]) + get_location(obj[5]) for obj in data]
    print list(data)
    cursor.close()
    return list(data)
Ejemplo n.º 5
0
def get_rent_contract(landlord_id, contract_id):
    connection = get_connection('landlords')
    cursor = connection.cursor()
    data = list(cursor.callfunc('meow.get_rent_contract', cx_Oracle.CURSOR, [landlord_id, contract_id]))
    cursor.close()
    if len(data) == 0:
        return None
    else:
        return data[0]
Ejemplo n.º 6
0
def get_shopping_area(area_id):
    connection = get_connection('default')
    cursor = connection.cursor()
    data = list(
        cursor.callfunc('get_shopping_area', cx_Oracle.CURSOR, [area_id]))
    if len(data) == 0:
        return None
    cursor.close()
    return list(data)[0]
Ejemplo n.º 7
0
def create_rent_request(tenant_id, area_id, description=''):
    connection = get_connection('tenants')
    cursor = connection.cursor()
    try:
        cursor.callproc('meow.create_rent_request', [tenant_id, area_id, description])
        cursor.close()
        connection.commit()
        return True
    except cx_Oracle.DatabaseError:
        return False
Ejemplo n.º 8
0
def get_shopping_mall(mall_id):
    connection = get_connection('default')
    cursor = connection.cursor()
    data = list(
        cursor.callfunc('get_shopping_mall', cx_Oracle.CURSOR, [mall_id]))
    if len(data) == 0:
        return None
    data = list(data[0][:5]) + get_location(data[0][5])
    cursor.close()
    return data
Ejemplo n.º 9
0
def get_shopping_areas(mall_id):
    connection = get_connection('default')
    cursor = connection.cursor()
    data = cursor.callfunc('get_shopping_areas', cx_Oracle.CURSOR, [mall_id])
    data = [
        list(obj[:4]) + [get_landlord(obj[4])] + [get_price(obj[5])]
        for obj in data
    ]
    cursor.close()
    return list(data)
Ejemplo n.º 10
0
 def _get_user_group_name(self):
     token = self.request.COOKIES.get('token', None)
     connection = get_connection('default')
     cursor = connection.cursor()
     group_id = cursor.callfunc('authenticate', cx_Oracle.NUMBER, [token])
     print group_id
     if group_id < 0:
         group_name = None
     else:
         group_name = cursor.callfunc('get_group_name', cx_Oracle.STRING, [group_id])
     cursor.close()
     return group_name
Ejemplo n.º 11
0
def delete_shopping_mall(group_name, mall_id):
    connection = get_connection(group_name)
    if connection is None:
        return False

    cursor = connection.cursor()
    try:
        cursor.callproc('meow.delete_shopping_mall', [mall_id])
        cursor.close()
        connection.commit()
        return True
    except cx_Oracle.DatabaseError:
        return False
Ejemplo n.º 12
0
def create_shopping_mall(group_name, mall_id, data):
    data = [
        mall_id,
        data.get('location_id'),
        data.get('name'),
        data.get('description'),
        data.get('floors_number'),
        data.get('parking_size'),
    ]
    connection = get_connection(group_name)
    cursor = connection.cursor()
    try:
        cursor.callfunc('meow.create_or_update_shopping_mall',
                        cx_Oracle.NUMBER, data)
        cursor.close()
        connection.commit()
        return True
    except cx_Oracle.DatabaseError:
        return False
Ejemplo n.º 13
0
def create_shopping_area(group_name, area_id, mall_id, data):
    data = [
        area_id,
        data.get('landlord_id'),
        mall_id,
        data.get('price_id'),
        data.get('area'),
        data.get('description'),
    ]
    connection = get_connection(group_name)
    cursor = connection.cursor()
    try:
        cursor.callfunc('meow.create_or_update_shopping_area',
                        cx_Oracle.NUMBER, data)
        cursor.close()
        connection.commit()
        return True
    except cx_Oracle.DatabaseError as e:
        return False
Ejemplo n.º 14
0
def logout(token):
    connection = get_connection('default')
    cursor = connection.cursor()
    cursor.callproc('logout', [token])
    cursor.close()
Ejemplo n.º 15
0
def get_tenant_rent_contracts(tenant_id):
    connection = get_connection('tenants')
    cursor = connection.cursor()
    data = list(cursor.callfunc('meow.get_tenant_rent_contracts', cx_Oracle.CURSOR, [tenant_id]))
    cursor.close()
    return data
Ejemplo n.º 16
0
def get_price(price_id):
    connection = get_connection('default')
    cursor = connection.cursor()
    data = cursor.callfunc('get_price', cx_Oracle.CURSOR, [price_id])
    cursor.close()
    return list(data)[0]
Ejemplo n.º 17
0
def get_landlord_rent_contracts(landlord_id):
    connection = get_connection('landlords')
    cursor = connection.cursor()
    data = list(cursor.callfunc('meow.get_landlord_rent_contracts', cx_Oracle.CURSOR, [landlord_id]))
    cursor.close()
    return data
Ejemplo n.º 18
0
def get_location(location_id):
    connection = get_connection('default')
    cursor = connection.cursor()
    data = cursor.callfunc('get_location', cx_Oracle.CURSOR, [location_id])
    cursor.close()
    return list(data)
Ejemplo n.º 19
0
def delete_rent_contract(landlord_id, contract_id):
    connection = get_connection('landlords')
    cursor = connection.cursor()
    result = cursor.callfunc('meow.delete_rent_contract', cx_Oracle.NUMBER, [landlord_id, contract_id])
    cursor.close()
    return result
Ejemplo n.º 20
0
def get_landlords():
    connection = get_connection('default')
    cursor = connection.cursor()
    data = cursor.callfunc('get_landlords', cx_Oracle.CURSOR, [])
    cursor.close()
    return list(data)
Ejemplo n.º 21
0
def delete_rent_request(tenant_id, area_id):
    connection = get_connection('landlords')
    cursor = connection.cursor()
    result = cursor.callfunc('meow.delete_rent_request', cx_Oracle.NUMBER, [tenant_id, area_id])
    cursor.close()
    return result
Ejemplo n.º 22
0
def get_landlord_id(token):
    connection = get_connection('default')
    cursor = connection.cursor()
    id = cursor.callfunc('get_landlord_id', cx_Oracle.NUMBER, [token])
    cursor.close()
    return id
Ejemplo n.º 23
0
def is_active_rent_contract(contract_id):
    connection = get_connection('landlords')
    cursor = connection.cursor()
    result = cursor.callfunc('meow.is_active_rent_contract', cx_Oracle.BOOLEAN, [contract_id])
    cursor.close()
    return result