예제 #1
0
def checklist_page(checklist):
	cl_obj = CheckList(checklist)
	if request.method == 'POST':
		if 'delete' in request.form:
			try:
				image = int(request.form['delete']) - 1
			except ValueError:
				pass
			else:
				cl_obj.delete_image(request.form['item'], image)
		else:
			cl_obj.save_image(request.form['item'], request.files['file'])
		return redirect(request.url)
	else:
		return render_template('checklist.html', checklist=cl_obj)
예제 #2
0
def add_to_list():
    """Reads items from database. Adds items to list table"""

    all_data = json.loads(request.data)
    trip_code = all_data['tripCode']

    print "list trip code is %s" % trip_code

    data = json.loads(all_data['data'])

    new_data = json.loads(all_data['newdata'])

    print data
    print new_data

    for key in data:
        # We check to see if key is in database table and rewrite the values
        user_id = key["userid"]
        list_item = key["description"]
        completed = key["completed"]
        item_id = key['list_id']

        # query list for the list id
        query_list = CheckList.query.get(item_id)

        query_list.user_id = user_id
        query_list.description = list_item
        query_list.completed = completed
        db.session.commit()

    for key in new_data:
        # We write new items to database
        user_id = key["userid"]
        list_item = key["description"]
        completed = key["completed"]

        if list_item != "" and user_id != "":

            my_list = CheckList(trip_code=trip_code, user_id=user_id, description=list_item,
                        completed=completed)

            db.session.add(my_list)
            db.session.commit()

    session['changes'] = session.get('changes', '') + trip_code + ','

    query_data = CheckList.query.filter_by(trip_code=trip_code).all()

    my_json = {}
    my_json['items'] = []

    for item in query_data:
        my_json['items'].append({'item_id': item.item_id,
                                 'trip_code': item.trip_code,
                                 'userid': item.user_id,
                                 'description': item.description,
                                 'selected': item.completed})

    return json.dumps(my_json)
예제 #3
0
def cl_list():
	return render_template('cl_list.html', checklists=CheckList.get_lists())