Beispiel #1
0
def editItem(category_id=None, item_id=None):
    if not is_logged_in():
        flash("You must be logged in to perform that action.")
        return redirect(url_for('getCatalog'))

    item = get_item(item_id)
    if not is_authorized(item.user_id):
        flash("You may only edit items you have created.")
        return redirect(url_for('getCategory', category_id=category_id))

    if request.method == 'POST':
        item.update_item(name=request.form['name'],
                         description=request.form['description'],
                         url=request.form['url'],
                         category_id=request.form['category_id'])
        return redirect(
            url_for('getCategoryItem',
                    category_id=item.category_id,
                    item_id=item.id))
    else:
        categories = get_category(category_id=None)
        if item:
            return render_template(
                'edit.html',
                categories=categories,
                item=item,
            )
Beispiel #2
0
def populate_items():
    """Create minimum sample data for the item table."""

    user_id = get_user_id(ADMIN_EMAIL)
    categories = get_category(category_id=None)
    items = [{
        'name': '1name',
        'description': '1description',
        'url': '1url',
        'category_id': categories[0].id,
        'user_id': user_id
    }, {
        'name': '1name1',
        'description': '1description1',
        'url': '1url1',
        'category_id': categories[0].id,
        'user_id': user_id
    }, {
        'name': '2name',
        'description': '2description',
        'url': '2url',
        'category_id': categories[1].id,
        'user_id': user_id
    }, {
        'name': '2name1',
        'description': '2description1',
        'url': '2url1',
        'category_id': categories[1].id,
        'user_id': user_id
    }, {
        'name': '3name',
        'description': '3description',
        'url': '3url',
        'category_id': categories[2].id,
        'user_id': user_id
    }, {
        'name': '3name1',
        'description': '3description1',
        'url': '3url1',
        'category_id': categories[2].id,
        'user_id': user_id
    }, {
        'name': '4name',
        'description': '4description',
        'url': '4url',
        'category_id': categories[3].id,
        'user_id': user_id
    }, {
        'name': '4name1',
        'description': '4description1',
        'url': '4url1',
        'category_id': categories[3].id,
        'user_id': user_id
    }]
    for item in items:
        add_item(name=item['name'],
                 description=item['description'],
                 url=item['url'],
                 category_id=item['category_id'],
                 user_id=item['user_id'])
Beispiel #3
0
def getCatalog(json):
    # Get a list of all categories for display in sidebar
    categories = get_category(category_id=None)
    # Shows all items in descending order of creation date
    items = get_category_items(category_id=None)

    if json == '.json':
        return jsonify(
            Categories=[category.serialize for category in categories])

    return render_template('index.html', categories=categories, items=items)
Beispiel #4
0
def random():
    week = [
        "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
        "Sunday"
    ]
    city = get_city()
    date = week[datetime.today().weekday()]

    now = datetime.now()
    min = now.minute
    if min < 10:
        min = "0" + str(min)
    appt = "{}:{}".format(now.hour, min)

    graph = Graph("bolt://*****:*****@localhost:8000")
    c = get_category(graph)

    food = 'Restaurants'
    user_details = {'city': city, 'cuisine': food, 'date': date, 'appt': appt}
    print(user_details)
    user = site_user(user_details['city'], user_details['cuisine'],
                     user_details['date'], user_details['appt'])
    restaurant = get_restaurant(graph, user)

    if restaurant != "No results found":
        bus, review_count = restaurant
        mainres = bus
        review = get_review(graph, bus['id'])
        bus_from_friend_stars = []

        if review != "No results found":
            reviewer_name, reviewer_id, review_stars = review
            business_from_friend = suggestion_from_friend(
                graph, reviewer_id, user_details['cuisine'], bus['id'])

            if business_from_friend != "No results found":
                for b in business_from_friend:
                    business.append(b['b'])
                    bus_from_friend_stars.append(b['review_stars'])

    else:
        return redirect('/non_found')

    return render_template('res.html',
                           srch=user,
                           mainbus=mainres,
                           businesses=business,
                           friend_stars=bus_from_friend_stars,
                           category=c,
                           zip=zip)
Beispiel #5
0
def getCategoryItem(category_id=None, item_id=None, json=None):

    # Get a list of all categories for display in sidebar
    categories = get_category(category_id=None)

    # Shows items for selected category
    items = get_category_items(category_id)

    if json == '.json':
        return jsonify(
            Item=[item.serialize for item in items if item.id == item_id])
    return render_template('index.html',
                           categories=categories,
                           items=items,
                           category_id=items[0].category_id,
                           category_name=items[0].category.name,
                           item_id=item_id)
Beispiel #6
0
def getCategory(category_id=None, json=None):

    # Get a list of all categories for display in sidebar
    categories = get_category(category_id=None)
    # Shows all items for selected category alphabeticcally
    items = get_category_items(category_id)

    if json == '.json':
        return jsonify(Categories=[
            category.serialize for category in categories
            if category.id == category_id
        ])

    return render_template('index.html',
                           categories=categories,
                           items=items,
                           category_id=items[0].category_id,
                           category_name=items[0].category.name)
Beispiel #7
0
def addItem():
    if not is_logged_in():
        flash("You must be logged in to perform that action.")
        return redirect(url_for('getCatalog'))

    if request.method == 'POST':
        item = add_item(name=request.form['name'],
                        description=request.form['description'],
                        url=request.form['url'],
                        category_id=request.form['category_id'])
        return redirect(
            url_for('getCategoryItem',
                    category_id=item.category_id,
                    item_id=item.id))
    else:
        categories = get_category(category_id=None)
        return render_template(
            'add.html',
            categories=categories,
        )
Beispiel #8
0
def result():
    if request.method == 'POST':
        graph = Graph("bolt://*****:*****@localhost:8000")
        c = get_category(graph)
        user_details = request.form
        city_split = user_details['city'].split(' ')
        newstr = ""
        for str in city_split:
            newstr += str.capitalize()
        user = site_user(newstr.strip(), user_details['cuisine'],
                         user_details['date'], user_details['appt'])
        restaurant = get_restaurant(graph, user)

        if restaurant != "No results found":
            bus, review_count = restaurant
            mainres = bus
            review = get_review(graph, bus['id'])
            bus_from_friend_stars = []

            if review != "No results found":
                reviewer_name, reviewer_id, review_stars = review
                business_from_friend = suggestion_from_friend(
                    graph, reviewer_id, user_details['cuisine'], bus['id'])

                if business_from_friend != "No results found":
                    for b in business_from_friend:
                        business.append(b['b'])
                        bus_from_friend_stars.append(b['review_stars'])

        else:
            return redirect('/non_found')

        return render_template('res.html',
                               srch=user,
                               mainbus=mainres,
                               businesses=business,
                               friend_stars=bus_from_friend_stars,
                               category=c,
                               zip=zip)
Beispiel #9
0
def api_get_category():
    return get_category(current_user)
Beispiel #10
0
def home():
    graph = Graph("bolt://*****:*****@localhost:8000")
    c = get_category(graph)
    return render_template('search.html', category=c)
Beispiel #11
0
def non_found():
    graph = Graph("bolt://*****:*****@localhost:8000")
    c = get_category(graph)
    return render_template("no_result.html", category=c)