def listDetailView(list_id): ''' View details for a single list ''' thelist, list_owner = get_list_with_permission(list_id, session['user_id']) items = Item.fetch_all(list_id=list_id) rendered_items =\ [render_html('wishlist/item/view.html', item=item, list_owner=list_owner) # noqa for item in items] quick_add_form = render_html( 'wishlist/item/quick_add.html', list_id=list_id ) return render_template( 'list-detail.html', thelist=thelist, items=rendered_items, quick_add_form=quick_add_form, list_owner=list_owner )
def userListsView(): ''' Main view a user goes to to see all of their lists ''' error = None lists = List.fetch_all(user_id=session['user_id']) user_lists = dict_lists(lists) rendered_lists = [] for num, lst in user_lists.iteritems(): rendered_lists.append( render_html('wishlist/list/summary.html', lst=lst) ) return render_template( 'lists_home.html', error=error, user_lists=rendered_lists )
def createItemView(list_id): ''' View for adding a new item to an existing list ''' thelist, list_owner = get_list_with_permission(list_id, session['user_id']) new_item = request.form.to_dict() new_item.update({'list_id': list_id, }) status = None message = None item_result = None item_id = None try: item = Item.create(new_item) status = 'ok' message = 'added item to list' item_id = item.id item_result = render_html( 'wishlist/item/view.html', item=item, list_owner=list_owner ) except Exception, e: status = 'error' message = str(e)
if not list_owner: return flask.abort(403) if request.method == 'POST': try: Item.update(request.form, id=item_id) update_status = True render_item = Item.fetch_one( id=item.id ) except Exception, e: update_status = False error_message = str(e) render_item = dict_to_obj(request.form.to_dict()) else: render_item = item theform = render_html('wishlist/item/create.html', item=render_item) return render_template( 'wishlist/item/edit.html', item=item, theform=theform, update_status=update_status, error_message=error_message ) @app.route('/list/detail/<int:list_id>/items/<int:item_id>/delete/') @login_required def deleteItemView(list_id, item_id): ''' View for deleting an item ''' # just check permissions on the item