def regenerate(city):
    if 'username' not in session or 'password' not in session:
        return redirect(url_for('signin'))

    old = session['current_view_itinerary']
    try:
        preferences = dict()
        preferences['time_spent'] = request.form.get('days')
        if int(preferences['time_spent']) > DAY_LIMIT:
            preferences['time_spent'] = DAY_LIMIT
        preferences['max_price'] = request.form.get('price')
        itinerary = Itinerary(city, preferences=preferences)

        if 'db_id' in session['current_view_itinerary']:
            new_db_id = ExploriumDbApi.save_itinerary(session['username'], itinerary)
            itinerary.db_id = new_db_id
            query = ExploriumDbApi.COMMENTS.update().where(ExploriumDbApi.COMMENTS.c.itinerary_id == session['current_view_itinerary']['db_id']).values(itinerary_id=new_db_id)
            ExploriumDbApi.conn.execute(query)
            ExploriumDbApi.delete_itinerary(session['current_view_itinerary']['db_id'])
            session['current_view_itinerary'] = itinerary.to_dict()
            return redirect(url_for('get_itinerary_by_id', db_id=session['current_view_itinerary']['db_id']))
        return render_template('show_itinerary.html', this_username=session['username'], city=session['current_view_itinerary']['city'], itinerary=itinerary.to_dict(), error="")
    except Exception as e:
        #print e
        session['current_view_itinerary'] = old
        if 'username' not in session or 'password' not in session:
            return redirect(url_for('signin'))
        return render_template('show_itinerary.html', this_username=session['username'], city=session['current_view_itinerary']['city'], itinerary=session['current_view_itinerary'], error="")
Beispiel #2
0
 def test_itinerary_to_dict(self):
     it = Itinerary('New York', None)
     self.assertNotEqual(it, None)
     self.assertNotEqual(it.touristSpots, None)
     self.assertGreater(len(it.touristSpots), 0)
     dict = it.to_dict()
     self.assertEqual(dict['city'], 'New York')
     self.assertEqual(dict['db_id'], it.db_id)
Beispiel #3
0
 def test_init_itinerary_dict(self):
     it1 = Itinerary('New York', None)
     it2 = Itinerary('New York', itinerary=it1.to_dict())
     self.assertNotEqual(it2, None)
     self.assertEqual(len(it1.touristSpots), len(it2.touristSpots))
     for i in range(len(it1.touristSpots)):
         self.assertEqual(len(it1.touristSpots[i]), len(it2.touristSpots[i]))
         for j in range(len(it1.touristSpots[i])):
             self.assertEqual(it1.touristSpots[i][j].destinationID, it2.touristSpots[i][j].destinationID)
def get_itinerary_by_id(db_id):
    if 'username' not in session or 'password' not in session:
        return redirect(url_for('signin'))

    query = ExploriumDbApi.ITINERARY_TABLE.select().where(ExploriumDbApi.ITINERARY_TABLE.c.itinerary_id == db_id)
    result = ExploriumDbApi.conn.execute(query).fetchone()

    if result:
        itinerary = Itinerary(result['city'], db_id=db_id)
        session['current_view_itinerary'] = itinerary.to_dict()
        return render_template('show_itinerary.html', this_username=session['username'], itinerary=session['current_view_itinerary'], error="")
    return redirect(url_for('view_itineraries'))
def save():
    if 'username' not in session or 'password' not in session:
        return redirect(url_for('signin'))
    
    if 'current_view_itinerary' in session and session['current_view_itinerary']['db_id'] is None:
        itinerary = session['current_view_itinerary']
        cur_itinerary = Itinerary(itinerary['city'], itinerary=itinerary)
        db_id = ExploriumDbApi.save_itinerary(session['username'], cur_itinerary)
        cur_itinerary.db_id = db_id
        session['current_view_itinerary'] = cur_itinerary.to_dict()
        return redirect(url_for('get_itinerary_by_id', db_id=session['current_view_itinerary']['db_id']))
        #return render_template('show_itinerary.html', this_username=session['username'], city=cur_itinerary.city, itinerary=session['current_view_itinerary'], error="")
    return render_template('show_itinerary.html', this_username=session['username'], itinerary=session['current_view_itinerary'], error="")
def delete_tourist_spot(t_id):
    if 'username' not in session or 'password' not in session:
        return redirect(url_for('signin'))

    if 'current_view_itinerary' in session:
        if session['current_view_itinerary']['db_id'] is not None:
            cur_itinerary = Itinerary(session['current_view_itinerary']['city'], db_id =session['current_view_itinerary']['db_id'])
            cur_itinerary.del_spot(ExploriumDbApi.load_tourist_spot(ts_id=t_id))
            new_db_id = ExploriumDbApi.save_itinerary(session['username'], cur_itinerary)
            query = ExploriumDbApi.COMMENTS.update().where(ExploriumDbApi.COMMENTS.c.itinerary_id == session['current_view_itinerary']['db_id']).values(itinerary_id=new_db_id)
            ExploriumDbApi.conn.execute(query)
            cur_itinerary.db_id = new_db_id
            ExploriumDbApi.delete_itinerary(session['current_view_itinerary']['db_id'])
            session['current_view_itinerary'] = cur_itinerary.to_dict() 
        return render_template('show_itinerary.html', this_username=session['username'], city=session['current_view_itinerary']['city'], itinerary=session['current_view_itinerary'], error="")
    return render_template('index.html', this_username=session['username'], show_what="Welcome!", result_info_list='')
def route():
    if 'username' not in session or 'password' not in session:
        return redirect(url_for('signin'))
    if request.method == 'GET':
        return render_template('route.html', this_username=session['username'], error="")
    else:
        try:
            preferences = dict()
            preferences['time_spent'] = request.form.get('rangeInput')
            if int(preferences['time_spent']) > DAY_LIMIT:
                preferences['time_spent'] = DAY_LIMIT 
            preferences['max_price'] = request.form.get('price')
            city = request.form.get('city')
            preferences['types'] = request.form.getlist('t_spot')
            itinerary = Itinerary(city, preferences=preferences)
            session['current_view_itinerary'] = itinerary.to_dict()

            return render_template('show_itinerary.html', this_username=session['username'], itinerary=session['current_view_itinerary'], error="")
        except Exception as e:
            #print e
            if 'username' not in session or 'password' not in session:
                return redirect(url_for('signin'))
            return render_template('index.html', this_username=session['username'], show_what="Welcome!",
                                   result_info_list='')