def create_switch(name, management_ip, room, processor): switch = Switch(management_ip=management_ip, host=Host(room=room, owner=User.get(0), name=name)) session.add(switch) message = deferred_gettext("Created switch '{}' with management IP {}.")\ .format(switch.host.name, switch.management_ip) log_room_event(message.to_json(), processor, switch.host.room) return switch
def get(self): parser = reqparse.RequestParser() parser.add_argument('user_id', required=True, type=int) args = parser.parse_args() user = User.get(args.user_id) if user is None: abort(404, message='User not found') send_confirmation_email(user) session.session.commit() return jsonify({'success': True})
def host_create(): user = get_user_or_404(request.args.get('user_id', None)) form = HostForm(owner_id=user.id) def default_response(): form_args = { 'form': form, 'cancel_to': url_for('user.user_show', user_id=user.id) } return render_template('generic_form.html', page_title="Host erstellen", form_args=form_args, form=form) if not form.is_submitted(): refill_room_data(form, user.room) if not form.validate_on_submit(): return default_response() room = Room.q.filter_by(number=form.room_number.data, level=form.level.data, building=form.building.data).one() owner = User.get(form.owner_id.data) try: with handle_errors(session.session): host = lib_host.host_create(owner, room, form.name.data, processor=current_user) session.session.commit() except PycroftException: return default_response() return redirect( url_for('.interface_create', user_id=host.owner_id, host_id=host.id, _anchor='hosts'))
def get_user_or_404(user_id: int) -> User | NoReturn: user = User.get(user_id) if user is None: flash(f"Nutzer mit ID {user_id} existiert nicht!", 'error') abort(404) return user
def get_user_or_404(user_id): user = User.get(user_id) if user is None: abort(404, message=f"User {user_id} does not exist") return user
def load_user(userid): return User.get(userid)
def _fetch_normal(uid: int) -> User | None: return User.get(uid)
return render_template('generic_form.html', page_title="Host editieren", form_args=form_args, form=form) if not form.is_submitted(): refill_room_data(form, host.room) return default_response() if not form.validate(): return default_response() room = Room.q.filter_by(number=form.room_number.data, level=form.level.data, building=form.building.data).one() owner = User.get(form.owner_id.data) try: with handle_errors(session.session): lib_host.host_edit(host, owner, room, form.name.data, processor=current_user) session.session.commit() except PycroftException: return default_response() flash("Host erfolgreich bearbeitet.", 'success') return redirect( url_for('user.user_show', user_id=owner.id, _anchor='hosts'))