def update_tokens(request): """ We need to record these updates to token states and provide a way to view this in the Gateway Interface. """ session = DBSession() data = simplejson.loads(request.body) if not 'device_id' in data: return Response('You must provide an device_id') device = session.query(Device)\ .filter_by(device_id=data['device_id']).first() if device: for i in data['tokens']: token = session.query(Token)\ .filter_by(token=i['token_id']).first() if token: circuit = session.query(Circuit)\ .filter_by(pin=i['account_id']).first() if circuit: job = AddCredit(token.value, circuit, token) session.add(job) token.state = 5 session.merge(token) session.flush() return Response('Ok') else: return Response('You must provide a valid device_id')
def edit_user(request): """ Allows a user to edit the profile. This should be limited... """ session = DBSession() user = get_object_or_404(User, request.matchdict.get('user')) form = EditUserForm(request.POST, obj=user) form.group.query = session.query(Group).all() if request.method == 'POST' and form.validate(): group = session.query(Group).get(form.group_id.data) user.name = form.name.data user.email = form.email.data user.group = group session.merge(user) return HTTPFound(location=request.route_url('admin-users')) else: return {'user': user, 'form': form}