def cluster_edit(r_id): cluster = MhCluster.get_by_id(r_id) if not cluster: return render_template('404.html') form = MhClusterForm(obj=cluster) if form.validate_on_submit(): try: cluster.update(name=form.name.data, admin_host=form.admin_host.data, env=form.env.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateMhClusterAdminHostError, DuplicateMhClusterNameError) as e: flash('Error: %s' % e.message, 'failure') else: flash('cluster updated.', 'success') else: flash_errors(form) return render_template('inventory/cluster_form.html', version=app_version, form=form, mode='edit', r_id=cluster.id)
def cluster_edit(r_id): cluster = MhCluster.get_by_id(r_id) if not cluster: return render_template('404.html') form = MhClusterForm(obj=cluster) if form.validate_on_submit(): try: cluster.update( name=form.name.data, admin_host=form.admin_host.data, env=form.env.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateMhClusterAdminHostError, DuplicateMhClusterNameError) as e: flash('Error: %s' % e.message, 'failure') else: flash('cluster updated.', 'success') else: flash_errors(form) return render_template( 'inventory/cluster_form.html', version=app_version, form=form, mode='edit', r_id=cluster.id)
def ca_edit(r_id): """capture agent edit form.""" ca = Ca.get_by_id(r_id) if not ca: return render_template('404.html') form = CaForm(obj=ca) form.vendor_id.choices = get_select_list_for_vendors() if form.validate_on_submit(): try: ca.update( name=form.name.data, address=form.address.data, serial_number=form.serial_number.data) except (InvalidEmptyValueError, MissingVendorError, DuplicateCaptureAgentNameError, DuplicateCaptureAgentAddressError, DuplicateCaptureAgentSerialNumberError) as e: flash('Error: %s' % e.message, 'danger') else: flash('capture agent created.', 'success') else: flash_errors(form) return render_template( 'inventory/capture_agent_form.html', version=app_version, form=form, mode='edit', r_id=ca.id)
def role_create(): form = RoleForm() form.ca_id.choices = get_select_list_for_cas() form.location_id.choices = get_select_list_for_locations() form.cluster_id.choices = get_select_list_for_clusters() if form.validate_on_submit(): ca = Ca.get_by_id(form.ca_id.data) loc = Location.get_by_id(form.location_id.data) cluster = MhCluster.get_by_id(form.cluster_id.data) try: Role.create(name=form.role_name.data, ca=ca, location=loc, cluster=cluster) except (InvalidCaRoleError, AssociationError) as e: flash('Error: %s' % e.message, 'danger') else: flash('role created.', 'success') else: flash_errors(form) return render_template('inventory/role_form.html', version=app_version, form=form, mode='create')
def ca_edit(r_id): """capture agent edit form.""" ca = Ca.get_by_id(r_id) if not ca: return render_template('404.html') form = CaForm(obj=ca) form.vendor_id.choices = get_select_list_for_vendors() if form.validate_on_submit(): try: ca.update(name=form.name.data, address=form.address.data, serial_number=form.serial_number.data) except (InvalidEmptyValueError, MissingVendorError, DuplicateCaptureAgentNameError, DuplicateCaptureAgentAddressError, DuplicateCaptureAgentSerialNumberError) as e: flash('Error: %s' % e.message, 'danger') else: flash('capture agent created.', 'success') else: flash_errors(form) return render_template('inventory/capture_agent_form.html', version=app_version, form=form, mode='edit', r_id=ca.id)
def vendor_create(): form = VendorForm() if form.validate_on_submit(): try: Vendor.create(name=form.name.data, model=form.model.data) except (InvalidOperationError, DuplicateVendorNameModelError) as e: flash('Error: %s' % e.message, 'danger') else: flash('vendor created.', 'success') else: flash_errors(form) return render_template( 'inventory/vendor_form.html', version=app_version, form=form, mode='create')
def vendor_create(): form = VendorForm() if form.validate_on_submit(): try: Vendor.create(name=form.name.data, model=form.model.data) except (InvalidOperationError, DuplicateVendorNameModelError) as e: flash('Error: %s' % e.message, 'danger') else: flash('vendor created.', 'success') else: flash_errors(form) return render_template('inventory/vendor_form.html', version=app_version, form=form, mode='create')
def location_create(): form = LocationForm() if form.validate_on_submit(): try: Location.create(name=form.name.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateLocationNameError) as e: flash('Error: %s' % e.message, 'danger') else: flash('location created.', 'success') else: flash_errors(form) return render_template('inventory/location_form.html', version=app_version, form=form, mode='create')
def location_create(): form = LocationForm() if form.validate_on_submit(): try: Location.create(name=form.name.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateLocationNameError) as e: flash('Error: %s' % e.message, 'danger') else: flash('location created.', 'success') else: flash_errors(form) return render_template( 'inventory/location_form.html', version=app_version, form=form, mode='create')
def home(): """Home page.""" form = LoginForm(request.form) # _always_ get logger in request context logger = logging.getLogger(__name__) logger.info('app: %s env: %s' % (__name__, current_app.config['ENV'])) # Handle logging in if request.method == 'POST': if form.validate_on_submit(): cache.set(form.user.username, form.user, timeout=24 * 3600) login_user(form.user) flash('You are logged in.', 'success') redirect_url = request.args.get('next') or url_for('public.home') return redirect(redirect_url) else: flash_errors(form) return render_template('public/home.html', form=form, version=app_version)
def cluster_create(): form = MhClusterForm() if form.validate_on_submit(): try: MhCluster.create(name=form.name.data, admin_host=form.admin_host.data, env=form.env.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateMhClusterAdminHostError, DuplicateMhClusterNameError) as e: flash('Error: %s' % e.message, 'danger') else: flash('cluster created.', 'success') else: flash_errors(form) return render_template('inventory/cluster_form.html', version=app_version, form=form, mode='create')
def vendor_edit(r_id): vendor = Vendor.get_by_id(r_id) if not vendor: return render_template('404.html') form = VendorForm(obj=vendor) if form.validate_on_submit(): try: vendor.update(name=form.name.data, model=form.model.data) except (InvalidOperationError, DuplicateVendorNameModelError) as e: flash('Error: %s' % e.message, 'danger') else: flash('vendor updated.', 'success') else: flash_errors(form) return render_template( 'inventory/vendor_form.html', version=app_version, form=form, mode='edit', r_id=vendor.id)
def role_delete(r_id): form = RoleDeleteForm() role = Role.query.filter_by(ca_id=r_id).first() if not role: return render_template('404.html') if form.validate_on_submit(): try: role.delete() except (InvalidCaRoleError, AssociationError) as e: flash('Error: %s' % e.message, 'danger') else: flash('role deleted.', 'success') else: flash_errors(form) r_list = Role.query.all() return render_template('inventory/role_list.html', version=app_version, form=form, record_list=r_list)
def cluster_create(): form = MhClusterForm() if form.validate_on_submit(): try: MhCluster.create( name=form.name.data, admin_host=form.admin_host.data, env=form.env.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateMhClusterAdminHostError, DuplicateMhClusterNameError) as e: flash('Error: %s' % e.message, 'danger') else: flash('cluster created.', 'success') else: flash_errors(form) return render_template( 'inventory/cluster_form.html', version=app_version, form=form, mode='create')
def vendor_edit(r_id): vendor = Vendor.get_by_id(r_id) if not vendor: return render_template('404.html') form = VendorForm(obj=vendor) if form.validate_on_submit(): try: vendor.update(name=form.name.data, model=form.model.data) except (InvalidOperationError, DuplicateVendorNameModelError) as e: flash('Error: %s' % e.message, 'danger') else: flash('vendor updated.', 'success') else: flash_errors(form) return render_template('inventory/vendor_form.html', version=app_version, form=form, mode='edit', r_id=vendor.id)
def location_edit(r_id): loc = Location.get_by_id(r_id) if not loc: return render_template('404.html') form = LocationForm(obj=loc) if form.validate_on_submit(): try: loc.update(name=form.name.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateLocationNameError) as e: flash('Error: %s' % e.message, 'danger') else: flash('location updated.', 'success') else: flash_errors(form) return render_template( 'inventory/location_form.html', version=app_version, form=form, mode='edit', r_id=loc.id)
def role_delete(r_id): form = RoleDeleteForm() role = Role.query.filter_by(ca_id=r_id).first() if not role: return render_template('404.html') if form.validate_on_submit(): try: role.delete() except (InvalidCaRoleError, AssociationError) as e: flash('Error: %s' % e.message, 'danger') else: flash('role deleted.', 'success') else: flash_errors(form) r_list = Role.query.all() return render_template( 'inventory/role_list.html', version=app_version, form=form, record_list=r_list)
def location_edit(r_id): loc = Location.get_by_id(r_id) if not loc: return render_template('404.html') form = LocationForm(obj=loc) if form.validate_on_submit(): try: loc.update(name=form.name.data) except (InvalidOperationError, InvalidEmptyValueError, DuplicateLocationNameError) as e: flash('Error: %s' % e.message, 'danger') else: flash('location updated.', 'success') else: flash_errors(form) return render_template('inventory/location_form.html', version=app_version, form=form, mode='edit', r_id=loc.id)
def role_create(): form = RoleForm() form.ca_id.choices = get_select_list_for_cas() form.location_id.choices = get_select_list_for_locations() form.cluster_id.choices = get_select_list_for_clusters() if form.validate_on_submit(): ca = Ca.get_by_id(form.ca_id.data) loc = Location.get_by_id(form.location_id.data) cluster = MhCluster.get_by_id(form.cluster_id.data) try: Role.create( name=form.role_name.data, ca=ca, location=loc, cluster=cluster) except (InvalidCaRoleError, AssociationError) as e: flash('Error: %s' % e.message, 'danger') else: flash('role created.', 'success') else: flash_errors(form) return render_template( 'inventory/role_form.html', version=app_version, form=form, mode='create')