コード例 #1
0
def api_edit():
	if (not has_permission(current_user.role, 'write')):
		return 'no permission'
	else:
		field_to_set = request.values.get('field-to-set')
		new_value = request.values.get('new-value')
		ids_to_apply_to = request.values.get('ids-to-apply-to')

		ids_parsed = ids_to_apply_to.split(',')

		print (ids_parsed)
		if (field_to_set == 'remove' and new_value == 'remove'):
			for id in ids_parsed:
				db_session.query(Camper).filter_by(id=id).delete()
		else:
			for id in ids_parsed:
				camper = db_session.query(Camper).get(id)
				#print(id);
				if   (field_to_set == 'location'):
					from app.data.get_time import get_time
					camper.location = new_value + " ({})".format(get_time())
				elif (field_to_set == 'firstname'):
					camper.firstname= new_value
				elif (field_to_set == 'lastname'):
					camper.lastname = new_value
				elif (field_to_set == 'nickname'):
					camper.nickname = new_value
				elif (field_to_set == 'note'):
					camper.note     = new_value
				else:
					return "Error: Unknown Field"

		db_session.commit()
		return 'success'
コード例 #2
0
def auto_redirect():
    url = '/login'
    if current_user.is_authenticated:
        if has_permission(current_user.role, 'write'):
            url = '/readwrite'
        else:
            url = '/readonly'
    return redirect(url, code=302)
コード例 #3
0
def backup_db_route():
	if (not has_permission(current_user.role, 'administrate')):
		return render_template('denied.html')

	global db_path
	from shutil import copy2
	from app.data.database import db_path, db_directory
	from app.data.get_time import get_timedate

	copy2 (db_path, db_directory + get_timedate())

	return 'Backed up as \"{}\"'.format(get_timedate())
コード例 #4
0
def api_add():
	if (not has_permission(current_user.role, 'write')):
		return render_template('denied.html')

	s = request.values.get('new-campers')
	x = json.loads(s, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))

	i = 0
	for c in x:
		add_camper(offset = i, commit=False, firstname=c.firstname, lastname=c.lastname, nickname=c.nickname, location=c.location, note=c.note)
		i += 1
	db_session.commit()
	return 'success'
コード例 #5
0
def curname_route():
	if (has_permission(current_user.role, 'administrate')):
		from app.data.database import db_path
		return db_path
	else:
		return render_template('denied.html')