def render_search(): create_whoosh_dir() rest_ix = get_restaurant_index() loc_ix = get_location_index() cat_ix = get_category_index() restSearchableFields = ["name","phonenum"] locSearchableFields = ["address","neighborhood", "zipcode"] catSearchableFields = ["name"] restDataList = [] locDataList = [] catDataList = [] if request.method == 'POST': search_query = request.form['search'] restDataList = search_results(rest_ix, search_query, restSearchableFields) locDataList = search_results(loc_ix, search_query, locSearchableFields) catDataList = search_results(cat_ix, search_query, catSearchableFields) constructRelatedModels(restDataList, locDataList, catDataList) return render_template('search_results.html', restDataNames=Restaurant.getDataNames() + ["context"], restDataList=restDataList, locDataNames=Location.getDataNames() + ["context"], locDataList=locDataList, catDataNames=Category.getDataNames() + ["context"], catDataList=catDataList)
def render_location_id(location_id=None): locModel = Location.query.get_or_404(location_id) relatedRestModel = Restaurant.query.filter_by(location_id = location_id).one() catListModels = getDataDictList(relatedRestModel.catlist) return render_template('location.html', locModel = locModel, restModel = relatedRestModel, catAttrs = Category.getDataNames(), catListModels = dumps(catListModels))
def render_category(): tableDataDict = getTableDataDict("Categories","category", Category) catDataDictList = getDataDictList(getModels(Category, tableDataDict['offset'], tableDataDict['sortby'], tableDataDict['direction'])) return render_template('template_db.html', dataNames=Category.getDataNames(), dataList=catDataDictList, **tableDataDict )
def render_restaurant_id(restaurant_id=None): restModel = Restaurant.query.get_or_404(restaurant_id) relatedLocModel = Location.query.get(restModel.location_id) catListModels = getDataDictList(restModel.catlist) return render_template('restaurant.html', restModel = restModel, locModel = relatedLocModel, catAttrs = Category.getDataNames(), catListModels = dumps(catListModels))
def test_get_data_names_2(self): self.assertEqual(Category.getDataNames()[0], "id")
def test_get_data_names_1(self): self.assertEqual(Category.getDataNames(), ["id", "name", "resttotal", "reviewtotal", "ratingavg"])
def test_get_data_names_0(self): self.assertEqual(len(Category.getDataNames()), 5)