@@ -0,0 +1,1991 @@
+from pycroft.lib.logging import log_room_event, log_event%0Afrom pycroft.model.host import SwitchPort, Host, Switch%0Afrom pycroft.model.port import PatchPort%0Afrom pycroft.model.session import with_transaction, session%0Afrom pycroft.model.user import User%0A%0A%0A@with_transaction%0Adef edit_port_relation(switchport, patchport, switchport_name, patchport_name, room, processor):%0A    if patchport.room != room:%0A        log_room_event(%22Changed room of SP %7B%7D %E2%86%92 PP %7B%7D from %7B%7D to %7B%7D.%22%5C%0A                       .format(switchport.name, patchport.name, patchport.room.short_name, room.short_name),%0A                       processor, switchport.switch.host.room)%0A%0A        patchport.room = room%0A%0A    if switchport.name != switchport_name or patchport.name != patchport_name:%0A        log_room_event(%22Changed relation SP %7B%7D %E2%86%92 PP %7B%7D to %7B%7D %E2%86%92 %7B%7D on %7B%7D.%22.format(switchport.name, patchport.name,%0A                                                                                 switchport_name, patchport_name,%0A                                                                                 switchport.switch.name),%0A                       processor, switchport.switch.host.room)%0A%0A        switchport.name = switchport_name%0A        patchport.name = patchport_name%0A%0A%0A@with_transaction%0Adef create_port_relation(switch, switchport_name, patchport_name, room, processor):%0A    switchport = SwitchPort(name=switchport_name, switch=switch)%0A    patchport = PatchPort(name=patchport_name, room=room, switch_port=switchport)%0A%0A    log_room_event(%22Created relation SP %7B%7D %E2%86%92 PP %7B%7D on %7B%7D.%22.format(switchport.name, patchport.name, switchport.switch.name),%0A                   processor, switchport.switch.host.room)%0A%0A%0A@with_transaction%0Adef delete_port_relation(switchport, patchport, processor):%0A    log_room_event(%0A        %22Deleted relation SP %7B%7D %E2%86%92 PP %7B%7D on %7B%7D.%22.format(switchport.name, patchport.name, switchport.switch.name),%0A        processor, switchport.switch.host.room)%0A%0A    session.delete(patchport)%0A    session.delete(switchport)%0A

Add lib functions to add/edit/delete port relations