Ejemplo n.º 1
0
def newPlace():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newPlace = Place(name=request.form['name'],
                         picture=request.form['urlpic'],
                         user_id=login_session['user_id'])
        if request.form['rate']:
            newPlace.rate_id = request.form['rate']
        else:
            newPlace.rate_id = 1
        session.add(newPlace)
        flash('New Place "%s" Successfully Created' % newPlace.name)
        session.commit()
        return redirect(url_for('showPlaces'))
    else:
        return render_template('protected/newPlace.html',
                               username=login_session['username'])
Ejemplo n.º 2
0
def newPlace(city_id):
    if 'username' not in login_session:
        return redirect('/login')
    editedCity = session.query(City).filter_by(id=city_id).one()
    city = session.query(City).filter_by(id=city_id).one()
    if request.method == 'POST':
        newPlace = Place(name=request.form['name'],
                         description=request.form['description'],
                         city_id=city_id,
                         user_id=city.user_id)
        session.add(newPlace)
        session.commit()
        return redirect(url_for('showPlaces', city_id=city_id))
    else:
        return render_template('newPlace.html', city_id=city_id)
Ejemplo n.º 3
0
def HomePage():
    #when uploading a place
    if request.method == 'POST':
        #upload name, description, type of place
        place_name = request.form['name']
        place_description = request.form['description']
        place_type = request.form['type'].lower()

        #upload image
        #check if the POST request has the file part
        # if 'file' not in request.files:
        # 	flash('No file part')
        # 	return redirect(url_for('HomePage'))
        # file = request.files['file']

        # #if user does not select file, browser also submit a empty
        # #part without filename
        # if file.filename == '':
        # 	flash('No selected file')
        # 	return redirect(url_for('HomePage'))

        #if file exist and has an image type
        file = request.files['image']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        place_img_path = 'img/' + filename
        new_place = Place(name=place_name,
                          description=place_description,
                          type=place_type,
                          rate_times=0,
                          total_point=0,
                          rating=0,
                          img_path=place_img_path)

        session.add(new_place)
        session.commit()

        return redirect(url_for('HomePage'))

    else:
        places = session.query(Place).all()
        return render_template('HanoiPlace.html', places=places)
Ejemplo n.º 4
0
def newPlace():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        file = request.files['image']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        else:
            filename = 'placeholder.jpg'
        place = Place(name=request.form['name'],
                      user_id=login_session['user_id'],
                      image=filename)
        session.add(place)
        flash("New place to see stuff: %s" % place.name)
        session.commit()
        return redirect(url_for('showPlaces'))
    else:
        return render_template('places/new.html')
Ejemplo n.º 5
0
def newPlace(category_id):
    ''' Renders page to add new place to specific category,
        take category id for GET '''
    category = session.query(Category).filter_by(id=category_id).one()
    cat_creator_id = category.user_id
    logged_in = False
    if 'username' not in login_session:
        return redirect('/login')
    else:
        logged_in = True
    if (request.method == 'POST' and
       cat_creator_id == login_session['user_id']):
            newPlace = Place(
                name=request.form['name'], user_id=login_session['user_id'],
                description=request.form['description'], category=category,
                city=request.form['city'], country=request.form['country'])
            session.add(newPlace)
            session.commit()
            return redirect(url_for('categoryPage', category_id=category.id))
    elif cat_creator_id != login_session['user_id']:
        return render_template("unauth.html", logged_in=logged_in)
    else:
        return render_template('newplace.html', logged_in=logged_in)
Ejemplo n.º 6
0
def newPlace(placeType_id):
    """Create a route for creating a new place"""
    placeType = session.query(PlaceType).filter_by(id=placeType_id).one()
    if 'username' not in login_session:
        return redirect('/login')
    if placeType.user_id != login_session['user_id']:
        return "<script>function myfunction() {alert('You are not authorized to create a new place for this category. Only the place type creator can do this.');}</script><body onload='myfunction()'>"  # noqa
    if request.method == 'POST':
        rawLink = request.form['link']
        if 'http://' not in rawLink:
            rawLink = 'http://' + rawLink
        newPlaceItem = Place(name=request.form['name'],
                             description=request.form['description'],
                             location=request.form['location'],
                             price=request.form['price'],
                             link=rawLink,
                             placeType_id=placeType_id)
        session.add(newPlaceItem)
        session.commit()
        flash('New place successfully created')
        return redirect(url_for('showPlaces', placeType_id=placeType_id))
    else:
        return render_template('newPlace.html', placeType=placeType)
Ejemplo n.º 7
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Place, MenuItem

engine = create_engine('sqlite:///grub.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

myFirstSpot = Place(name="Pizza Palace")
session.add(myFirstSpot)
session.commit()
allPlaces = session.query(Place).all()

for place in allPlaces:
    print place.name
Ejemplo n.º 8
0
    "http://i32.photobucket.com/albums/d1/beningcampbell/sarah_garcia_zpsfbpue51l.jpg"
)  # NOQA
session.add(User4)
session.commit()

# Create a place type called Restaurants
placeType1 = PlaceType(name="Restaurants", user_id=2)
session.add(placeType1)
session.commit()

restaurant1 = Place(
    name="El Pinto",
    description="El Pinto started serving New Mexican food in 1962 and is \
    one of the most popular New Mexican restaurants in Albuquerque. \
    Located on a 12-acre piece of property in Albuquerque's North Valley, \
    El Pinto has five dining patios. Make sure to pick up a jar (or two) \
    of El Pinto salsa on your way out. 10500 4th St. NW, Albuquerque.",
    location="Albuquerque area",
    price="$$",
    link="https://www.elpinto.com",
    placeType=placeType1)
session.add(restaurant1)
session.commit()

restaurant2 = Place(
    name="The Shed",
    description="Located a block away from Santa Fe's Plaza, The Shed \
    serves some of the best New Mexican food in the state. Expect long \
    lines and lots of tourists, but the food is worth it. Their red chile \
    is especially good. Dinner is by reservation only. 113.5 East Palace \
    Avenue, Santa Fe.",
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
db_session = DBSession()

# Adding entries to database
new_place = Place(name='Home', lat=37.402365, lng=-121.9275, description=':-)')
db_session.add(new_place)
db_session.commit()

new_place = Place(name='Scenery 2',
                  lat=37.905449,
                  lng=-122.573073,
                  description='Park with care, do not drive off the cliff! ;)')
db_session.add(new_place)
db_session.commit()

new_place = Place(name='Philz Coffee',
                  lat=37.377366,
                  lng=-122.031270,
                  description='The best coffee in Bay Area')
db_session.add(new_place)
Ejemplo n.º 10
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Place, Base

engine = create_engine('sqlite:///places.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

p1 = Place(name='Ho Guom',
           description='Good place to walk, eat ice cream and watch butt',
           rate_times=0,
           total_point=0,
           img_path='img/6 (2).jpg',
           type='lake',
           rating=0)
p2 = Place(
    name='Thanh Nien Road',
    description=
    'Also have good ice scream, kick duck boat is a good try, very luxury restaurant on the lake but I don\'t care, "the more curve, the more danger" is suitable for this road',
    rate_times=0,
    total_point=0,
    img_path='img/Hanoi.jpg',
    type='road',
    rating=0)
p3 = Place(
    name='Ho Tay',
    description=
    'Large, running a round the lake per day is the good warm up, suitable for many activities from exercise, fishing, "kicking tone" for couples and try new grass or herbal for young man.',
    rate_times=0,
    total_point=0,
Ejemplo n.º 11
0
session.commit()

user2 = User(email='*****@*****.**', name='Sample user')
user2.hash_password('foobar')
session.add(user2)
session.commit()

for i in range(6):
    rating1 = Rate(rate=i)
    session.add(rating1)
    session.commit()

# Place
pic = 'http://4.bp.blogspot.com/-Os9gOHAXiJQ/Uf9KLEQicyI/'
pic += 'AAAAAAAAL3A/VHL2jhL7w2c/IMG_3469.JPG'
place1 = Place(user_id=1, name="Metro Balderas 1", picture=pic, rate_id=2)

session.add(place1)
session.commit()

# MeatType
meatType1 = MeatType(user_id=1, name="Pork", description="None veggie")
session.add(meatType1)
session.commit()
meatType2 = MeatType(user_id=1, name="Beef", description="None veggie")
session.add(meatType2)
session.commit()
meatType3 = MeatType(user_id=1, name="Chicken", description="None veggie")
session.add(meatType3)
session.commit()
meatType4 = MeatType(user_id=1, name="Veggie", description="Veggie")
Ejemplo n.º 12
0
# Create dummy user
user1 = User(name="Jhon Doe",
             email="*****@*****.**",
             picture='https://imgplaceholder.com/150x150')
session.add(user1)
session.commit()

city1 = City(name="Mecca", user=user1)

session.add(city1)
session.commit()

place1 = Place(
    name="Grand Mosque (Haram)",
    description=
    "The grand mosque of Makkah commonly known as Masjid al-Haram is the largest mosque in the world surrounded by the holiest places of Islam. Muslims around the world pray in the direction of Grand Mosque, 5 times a day",
    city=city1,
    user=user1)

session.add(place1)
session.commit()

city2 = City(name="Cairo", user=user1)

session.add(city2)
session.commit()

place21 = Place(
    name="Al-Azhar Mosque",
    description=
    "Al-Azhar Mosque is the finest building of Cairo's Fatimid era and one of the city's earliest surviving mosques, completed in AD 972.",
Ejemplo n.º 13
0
    picture=
    'https://pixabay.com/get/e837b00b2df7073ed1584d05fb0938c9bd22ffd41db6174593f9c671a2/robot-1214536_1280.png'
)
session.add(User1)
session.commit()

# Water Parks category
category1 = Category(user_id=1, name="Water Parks")

session.add(category1)
session.commit()

place1 = Place(
    user_id=1,
    name="Aquatica",
    description=
    "One enormous wave pool obviously wasn't enough for the team behind Aquatica, so they built two, side by side. - CNN.com",
    city="Orlando, Florida",
    country="USA",
    category=category1)

session.add(place1)
session.commit()

place2 = Place(
    user_id=1,
    name="Aquaventure Waterpark",
    description=
    "As of 2013, this Middle East water park is home to the world's widest water slide, the Middle East's longest river ride (2.3 kilometers in length) and the Middle East's longest zip line. - CNN.com",
    city="Dubai",
    country="UAE",
    category=category1)