示例#1
0
def addUser():
    try:
        name = request.form['name']
        last_name = request.form['last_name']
        email = request.form['email']
        password = request.form['password']

        data = {
            "name": name,
            "last_name": last_name,
            "email": email,
            "password": password
        }
        res = RequestsApi.save_user_api(data)

        rescategory = RequestsApi.get_all_categories_api()
        data2 = rescategory['res']['data']

        if res["res"]["success"] == True:
            if create_session(email, password):
                return render_template('property/add-property.html',
                                       categories=data2)
            else:
                return render_template('user/sign-in.html')
    except:
        return "Error en el servidor"
示例#2
0
def register():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        user = User(email=email, password=password)
        RequestsApi.get_register(user)
        return redirect(url_for('index'))
    elif request.method == 'GET':
        return render_template('/layouts/register.html')
示例#3
0
def index():
    if session_validate() == False:
        return redirect(url_for('login'))

    res = RequestsApi.get_all_api()
    print(res)
    return render_template('index.html', votes=res)
示例#4
0
def addProperty():
    try:
        if session_validate() == False:
            return redirect(url_for('signin'))

        title = request.form['title']
        tp = request.form['type']
        address = request.form['address']
        rooms = request.form['rooms']
        price = request.form['price']
        area = request.form['area']
        image = random_image()
        author = session['userid']

        data = {
            "title": title,
            "type": tp,
            "address": address,
            "rooms": rooms,
            "price": price,
            "area": area,
            "image": image,
            "author": author
        }
        res = RequestsApi.save_property_api(data)

        if res["res"]["success"] == True:
            return redirect(url_for('listpropertiesuser'))
        else:
            return "Ocurrio un problema al tratar de crear una nueva propiedad..."
    except:
        return "Error en el servidor"
示例#5
0
def delete(id):
    if session_validate() == False:
        return redirect(url_for('login'))
    res = RequestsApi.delete_api(id)
    print(res)
    flash('Deleted')
    return redirect(url_for('index'))
示例#6
0
def listed_by_user(user):
    if session_validate() == False:
        redirect(url_for('index'))
    res = RequestsApi.get_by_user(user)
    data = res['res']['data']
    for d in data:
        d['lala'] = random.randint(1, 9)
    return render_template('/layouts/indexuser.html', _data=data)
示例#7
0
def index():
    res = RequestsApi.get_all_country_api()
    count = len(res['data'])
    valInit = 1
    return render_template('layouts/index.html',
                           countries=res['data'],
                           countCountries=count,
                           valInit=valInit)
示例#8
0
def listProperty():
    try:
        res = RequestsApi.get_all_properties_api()

        if res["res"]["success"] == True:
            return render_template('property/list-properties.html',
                                   properties=res)
        else:
            return "Ocurrio un problema al cargar las propiedades..."
    except:
        return "Error en el servidor"
示例#9
0
def login():
    try:
        email = request.form['email']
        password = request.form['password']
        user = User(email=email, password=password)
        res = RequestsApi.get_login(user)
        session['login'] = True
        session['username'] = res['res']['data']['key']
        return redirect(url_for('listed_by_user', user=session['username']))
    except:
        return "Enter a valid username and password"
示例#10
0
def registerproperty():
    try:
        if session_validate() == False:
            return redirect(url_for('signin'))

        res = RequestsApi.get_all_categories_api()
        data = res['res']['data']

        return render_template('property/add-property.html', categories=data)
    except:
        return "Error al cargar categorias..."
示例#11
0
def editProperty():
    try:
        if session_validate() == False:
            return redirect(url_for('signin'))

        id = request.args.get('id')
        res = RequestsApi.get_one_property_api(id)

        rescategory = RequestsApi.get_all_categories_api()
        data2 = rescategory['res']['data']

        if res["res"]["success"] == True:
            data = res["res"]["data"][0]
            return render_template('property/update-property.html',
                                   pro=data,
                                   categories=data2)
        else:
            return "Ocurrio un problema al tratar de actualizar la propiedad..."
    except:
        return "Error en el servidor"
示例#12
0
def create_session(email, password):
    data = {"email": email, "password": password}
    res = RequestsApi.login_api(data)

    if res["res"]["success"] == True:
        session['login'] = True
        session['username'] = res['res']['data'][0]['name']
        session['userid'] = res['res']['data'][0]['_id']

        return True
    else:
        return False
示例#13
0
def search():
    if request.method == 'POST':
        try:
            value_input = request.form['value_input']
            res = RequestsApi.get_coordinate_by_address(value_input)
            point = res['response']['GeoObjectCollection']['featureMember'][0][
                'GeoObject']['Point']['pos']
            name = res['response']['GeoObjectCollection']['featureMember'][0][
                'GeoObject']['name']
            return render_template('view.html', name=name, point=point)
        except:
            return "not saved"
示例#14
0
def detailproperty(id):
    try:
        res = RequestsApi.get_one_property_api(id)

        if res["res"]["success"] == True:
            data = res["res"]["data"][0]
            return render_template('property/detail-property.html',
                                   property=data)
        else:
            return "Ocurrio un problema al tratar de mostrar el detalle de la propiedad..."
    except:
        return "Error en el servidor"
示例#15
0
def deleteproperty(id):
    try:
        if session_validate() == False:
            return redirect(url_for('signin'))

        res = RequestsApi.delete_property_api(id)

        if res["res"]["success"] == True:
            return redirect(url_for('listpropertiesuser'))
        else:
            return "Ocurrio un problema al tratar de eliminar la propiedad..."
    except:
        return "Error en el servidor"
def save():
    if request.method == 'POST':
        try:
            imglist = ['1d0', 'cvr', 'ar9', 'djk', '1nk', '9bf']
            img = random.choice(imglist)

            value_input = request.form['value_input']

            vote = Vote(value=int(value_input), image_id=img)
            res = RequestsApi.save_api(vote)
            return redirect(url_for('index'))
        except:
            return "not saved"
示例#17
0
def update(id):
    if session_validate() == False:
        redirect(url_for('index'))
    if request.method == 'POST':
        titleInput = request.form['titleInput']
        typeInput = request.form['typeInput']
        addressInput = request.form['addressInput']
        roomInput = request.form['roomInput']
        priceInput = request.form['priceInput']
        areaInput = request.form['areaInput']
        owner = session['username']
        estate = Estate(title=titleInput,
                        type_=typeInput,
                        address=addressInput,
                        rooms=int(roomInput),
                        price=int(priceInput),
                        area=areaInput,
                        owner=owner)
        RequestsApi.update_api(id, estate)
        return redirect(url_for('listed_by_user', user=session['username']))
    elif request.method == 'GET':
        res = RequestsApi.single_update(id)
        return render_template('/layouts/edit.html', data=res['res']['data'])
示例#18
0
def save():
    if session_validate() == False:
        return redirect(url_for('login'))
    if request.method == 'POST':
        try:
            imglist = [
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593216688/cegcpmalngmemqt25sby.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593291537/photo-1471623600634-4d04cfc56a27_wt7kjk.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593291536/photo-1523217582562-09d0def993a6_boe3nh.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593291536/photo-1517541866997-ea18e32ea9e9_wk02og.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593291535/photo-1521783593447-5702b9bfd267_izgbpo.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593291537/photo-1433961395396-def499303f0e_jpbawv.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593216738/agzuueg36frzvoixsp1m.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593122049/fdajojm463cm5u7ogk2c.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593046564/qdjlbt7vo4x7m1vwubls.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290025/395_Detroit_St.25_forprintuse.0_uwdgng.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290025/large_gwnob5.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290024/5_brown_hiuse_o5yssv.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290023/entrance_x0rh1c.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290021/217300328_jcb2wk.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290019/960x0_hd384b.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290019/960x0_hd384b.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290017/180464031_y4vcot.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290017/habitacion-2-compartida_yvqvtn.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290017/14101752736419_ev4lcs.jpg',
                'https://res.cloudinary.com/dta3svuvn/image/upload/v1593290016/c038d04e3cd4a63d2fa054be9e64518e_utfchs.jpg'
            ]
            #imglist = ['2k0', '8st', 'aaf', '306', 'abv', 'a3s']
            img = random.choice(imglist)
            title_input = request.form['title_input']
            type_input = request.form['type_input']
            address_input = request.form['address_input']
            rooms_input = request.form['rooms_input']
            price_input = request.form['price_input']
            area_input = request.form['area_input']
            #picture_input = request.form['picture_input']
            propierty = Propierty(title=(title_input),
                                  type_=(type_input),
                                  address=(address_input),
                                  rooms=int(rooms_input),
                                  price=int(price_input),
                                  area=int(area_input),
                                  picture=img)
            res = RequestsApi.save_api(propierty)
            flash('Propierty saved')
            print(res)
            return redirect(url_for('index'))
        except:
            flash('Not saved')
示例#19
0
def save():
    if session_validate() == False:
        redirect(url_for('index'))
    if request.method == 'POST':
        try:
            titleInput = request.form['titleInput']
            typeInput = request.form['typeInput']
            addressInput = request.form['addressInput']
            roomInput = request.form['roomInput']
            priceInput = request.form['priceInput']
            areaInput = request.form['areaInput']
            owner = session['username']
            estate = Estate(title=titleInput,
                            type_=typeInput,
                            address=addressInput,
                            rooms=int(roomInput),
                            price=int(priceInput),
                            area=areaInput,
                            owner=owner)
            RequestsApi.get_save(estate)
            return redirect(url_for('listed_by_user',
                                    user=session['username']))
        except:
            return "Not Saved"
示例#20
0
def listpropertiesuser():
    try:
        if session_validate() == False:
            return redirect(url_for('signin'))

        id = session['userid']
        res = RequestsApi.get_all_properties_user_api(id)

        if res["res"]["success"] == True:
            return render_template('property/list-properties-user.html',
                                   properties=res)
        else:
            return "Ocurrio un problema al cargar las propiedades..."
    except:
        return "Error en el servidor"
示例#21
0
def addcategory():
    try:
        if session_validate() == False:
            return redirect(url_for('signin'))

        name_category = request.form['name_category']

        data = {"name_category": name_category}
        res = RequestsApi.save_category_api(data)

        if res["res"]["success"] == True:
            return redirect(url_for('registerproperty'))
        else:
            return "Error al crear la categoria..."
    except:
        return "Error en el servidor"
示例#22
0
def save():
    if session_validate() == False:
        return redirect(url_for('login'))
    if request.method == 'POST':
        try:
            imglist = ['1d0', 'cvr', 'ar9', '1nk', '9bf']
            img = random.choice(imglist)

            value_input = request.form['value_input']

            vote = Vote(value=int(value_input), image_id=img)
            res = RequestsApi.save_api(vote)
            print(res)
            flash('Vote saved')
            return redirect(url_for('index'))
        except:
            flash('Not saved')
示例#23
0
def viewData(city, state, country):
    res = RequestsApi.get_all_data_api(city, state, country)
    Datetime = res['data']['current']['weather']['ts']
    Temperature = res['data']['current']['weather']['tp']
    Atmospheric = res['data']['current']['weather']['pr']
    Humidity = res['data']['current']['weather']['hu']
    WindS = res['data']['current']['weather']['ws']
    WindD = res['data']['current']['weather']['wd']
    return render_template('layouts/data.html',
                           datos=res['data'],
                           city=city,
                           state=state,
                           country=country,
                           coodinates=str(
                               res['data']['location']['coordinates']),
                           Datetime=Datetime,
                           Temperature=Temperature,
                           Atmospheric=Atmospheric,
                           Humidity=Humidity,
                           WindS=WindS,
                           WindD=WindD,
                           pollution=res['data']['current']['pollution'])
示例#24
0
def updateproperty():
    try:
        if session_validate() == False:
            return redirect(url_for('signin'))

        id = request.form['id']
        title = request.form['title']
        tp = request.form['type']
        address = request.form['address']
        rooms = request.form['rooms']
        price = request.form['price']
        area = request.form['area']
        image = request.form['image']
        date = request.form['date']
        author = request.form['author']

        data = {
            "id": id,
            "title": title,
            "type": tp,
            "address": address,
            "rooms": rooms,
            "price": price,
            "area": area,
            "image": image,
            "date": date,
            "author": author
        }
        res = RequestsApi.update_property_api(data)

        if res["res"]["success"] == True:
            return redirect(url_for('listpropertiesuser'))
        else:
            return "Ocurrio un problema al tratar de actualizar la propiedad..."
    except:
        return "Error en el servidor"
示例#25
0
def view(id):
    if session_validate() == False:
        return redirect(url_for('login'))
    res = RequestsApi.get_one_api(id)
    print(res)
    return render_template('view.html', vote=res)
示例#26
0
from graph import graph
import threading

def clean_sector(request, sector, current_graph = False):
	if not current_graph:
		current_graph = graph.make_graph(request, sector)
	print sector
	while current_graph.edges_size > 0:
		path = current_graph.search_path()
		request.send_trajectory(sector, path) 
		current_graph.update(request)
	print "Ending thread %d" % sector

threads = []

sectors = range(2, 11)
request = RequestsApi()

current_graph = graph.make_graph(request, 1)
t = threading.Thread(target=clean_sector, args=(request, 1, current_graph,))
threads.append(t)
t.start()

for sector in sectors:
	t = threading.Thread(target=clean_sector, args=(request, sector,))
	threads.append(t)
	t.start()

for thread in threads:
	thread.join()
示例#27
0
def delete(id):
    if session_validate() == False:
        redirect(url_for('index'))
    RequestsApi.delete_api(id)
    return redirect(url_for('listed_by_user', user=session['username']))
def delete(id):
    res = RequestsApi.delete_api(id)
    return redirect(url_for('index'))
示例#29
0
def listed():
    res = RequestsApi.get_all()
    data = res['res']['data']
    for d in data:
        d['lala'] = random.randint(1, 9)
    return render_template('/index.html', _data=data)
示例#30
0
def view(id):
    res = RequestsApi.get_single(id)
    return render_template('/layouts/view.html', data=res['res']['data'])