def deleteDorm(): """Delete a existing dormitory from the list""" dormitories = session.query(Dormitory).all() if not len(dormitories): print "no dormitories" return for i in range(len(dormitories)): print i print dormitories[i] while True: try: delete = int(raw_input("(you have to confirm) delete No. : ")) break except ValueError: print "you have to type a number" if not delete >= 0 or not delete < len(dormitories): print "{} is not a dormitory".format(delete) return print dormitories[delete] confirm = raw_input("do you want to delete this dormitory? (y/n): ") if confirm == "y": try: session.delete(dormitories[delete]) session.commit() print "deleted" return except: session.rollback()
def host_delete(host, processor): message = deferred_gettext("Deleted host '{}'.".format(host.name)) log_user_event(author=processor, user=host.owner, message=message.to_json()) session.delete(host)\
def delete_switch_port(switch_port, processor): log_room_event( "Deleted switch-port {} on {}.".format(switch_port.name, switch_port.switch.host.name), processor, switch_port.switch.host.room) session.delete(switch_port)
def interface_delete(interface, processor): message = deferred_gettext(u"Deleted interface {} of host {}.".format( interface.mac, interface.host.name)) log_user_event(author=processor, user=interface.host.owner, message=message.to_json()) session.delete(interface)
def interface_edit(interface, name, mac, ips, processor): message = u"Edited interface ({}, {}) of host '{}'." \ .format(interface.mac, ', '.join(str(ip.address) for ip in interface.ips), interface.host.name) if interface.name != name: interface.name = name message += " New name: '{}'.".format(interface.name) if interface.mac != mac: interface.mac = mac message += " New MAC: {}.".format(interface.mac) ips_changed = False current_ips = list(ip.address for ip in interface.ips) subnets = get_subnets_for_room(interface.host.room) new_ips = set(current_ips) # IP removed for ip in current_ips: if ip not in ips: session.delete(IP.q.filter_by(address=ip).first()) ips_changed = True new_ips.remove(ip) # IP added for ip in ips: if ip not in current_ips: subnet = next( iter([subnet for subnet in subnets if (ip in subnet.address)]), None) if subnet is not None: session.add(IP(interface=interface, address=ip, subnet=subnet)) ips_changed = True new_ips.add(str(ip)) if ips_changed: message += " New IPs: {}.".format(', '.join(str(ip) for ip in new_ips)) log_user_event(author=processor, user=interface.host.owner, message=deferred_gettext(message).to_json())
def fix_import_error(error_id): error = MT940Error.q.get(error_id) form = FixMT940Form() (transactions, old_transactions, doubtful_transactions) = ([], [], []) new_exception = None if request.method != 'POST': form.mt940.data = error.mt940 if form.validate_on_submit(): statement = [] try: statement += mt940_to_array(form.mt940.data) except Exception as e: new_exception = str(e) if new_exception is None: flash('MT940 ist jetzt valide.', 'success') (transactions, old_transactions, doubtful_transactions) = finance.process_transactions( error.bank_account, statement) if form.do_import.data is True: # save transactions to database session.add_all(transactions) session.delete(error) session.commit() flash(u'Bankkontobewegungen wurden importiert.') return redirect(url_for(".bank_accounts_import_errors")) else: flash('Es existieren weiterhin Fehler.', 'error') return render_template('finance/bank_accounts_error_fix.html', error_id=error_id, exception=error.exception, new_exception=new_exception, form=form, transactions=transactions, old_transactions=old_transactions, doubtful_transactions=doubtful_transactions)
def delete_patch_port(patch_port, processor): log_room_event("Deleted patch-port {}.".format(patch_port.name), processor, patch_port.switch_room) session.delete(patch_port)
def delete_switch(switch, processor): log_room_event("Deleted switch {}.".format(switch.host.name), processor, switch.host.room) session.delete(switch) session.delete(switch.host)
def delete_patch_port(patch_port, processor): message = deferred_gettext("Deleted patch-port {}.").format(patch_port.name) log_room_event(message.to_json(), processor, patch_port.switch_room) session.delete(patch_port)
def delete_switch(switch, processor): log_room_event(f"Deleted switch {switch.host.name}.", processor, switch.host.room) session.delete(switch) session.delete(switch.host)
def delete_switch_port(switch_port, processor): message = deferred_gettext("Deleted switch-port {port} on {host}.")\ .format(port=switch_port.name, host=switch_port.switch.host.name) log_room_event(message.to_json(), processor, switch_port.switch.host.room) session.delete(switch_port)