Example #1
0
def editItem(category_id, item_id):
    if 'email' in login_session.keys():
        edit_item = models.item_get(item_id)
        user_id = models.getUserID(login_session['email'])
        if edit_item.user_id == user_id:
            form = forms.itemForm(request.form)
            user = models.getUserInfo(user_id)
            category = models.category_get(category_id)
            if request.method == 'POST' and form.validate():
                edit_item.name = form.name.data
                edit_item.image = form.image.data
                edit_item.description = form.description.data
                models.item_edit(edit_item)
                items = models.items_get_by_category(category_id)
                return render_template('categories/show.html',
                                       category=category,
                                       items=items, user=user)
            else:
                return render_template('items/edit.html', category=category,
                                       item=edit_item, form=form, user=user)
        else:
            flash("You aren't the owner for that.")
            return redirect(url_for('showCategory', category_id=category_id))
    else:
        return redirect(url_for('showCategory', category_id=category_id))
Example #2
0
def categoryXML(category_id):
    category = models.category_get(category_id)
    items = models.items_get_by_category(category_id)
    # For XML we will need a dictionary instead of a list.
    page = {'CatalogItems': [i.serialize for i in items]}
    # Convert that dictionary using the dicttoxml library.
    xml = dicttoxml(page)
    # Use Python's parseString to build a DOM for us.
    dom = parseString(xml)
    # Return that DOM making sure to tell the server our response is going
    # to be XML instead of HTML and while we're at it let's make that XML
    # look pretty and easy to read.
    return Response(dom.toprettyxml(), mimetype='text/xml')
Example #3
0
def showCategory(category_id):
    # Get the selected category from the DB.
    category = models.category_get(category_id)
    # Get the items for that category out of the DB.
    items = models.items_get_by_category(category_id)
    # Show the information on the shetlers show page.
    if 'email' in login_session.keys():
        user_id = models.getUserID(login_session['email'])
        user = models.getUserInfo(user_id)
        return render_template('categories/show.html', category=category,
                               items=items, user=user)
    else:
        state = ''.join(random.choice(string.ascii_uppercase + string.digits)
                        for x in xrange(32))
        login_session['state'] = state
        return render_template('categories/public.html',
                               category=category, items=items, STATE=state)
Example #4
0
def newItem(category_id):
    if 'email' in login_session.keys():
        form = forms.itemForm(request.form)
        user_id = models.getUserID(login_session['email'])
        user = models.getUserInfo(user_id)
        category = models.category_get(category_id)
        if request.method == 'POST' and form.validate():
            new_item = {
                "name": form.name.data,
                "image": form.image.data,
                "description": form.description.data,
                "user_id": models.getUserID(login_session['email']),
                "category_id": category_id
            }
            models.item_new(category_id, new_item)
            items = models.items_get_by_category(category_id)
            return render_template('categories/show.html', category=category,
                                   items=items, user=user)
        else:
            return render_template('items/new.html', category=category,
                                   form=form, user=user)
    else:
        return redirect(url_for('showCategory', category_id=category_id))
Example #5
0
def categoryJSON(category_id):
    # Get the selected category from the DB.
    category = models.category_get(category_id)
    # Get the items for that category out of the DB.
    items = models.items_get_by_category(category_id)
    return jsonify(CatalogItems=[i.serialize for i in items])