from django.dispatch import Signal from .models import Device, Wifi, DeviceLog, UserLog, WifiLog from django.contrib.auth.models import User siglog = Signal(providing_args=["id", "user", "action", "oldvalue", "newvalue"]) # Device Signals def sigDevice(device_id, user, action, oldvalue=None, newvalue=None): siglog.send(sender=Device, id=device_id, user=user, action=action, oldvalue=oldvalue, newvalue=newvalue) def sigDeleteDevice(device_id, user): sigDevice(device_id, user, DeviceLog.REMOVE) def sigAddDevice(device_id, user): sigDevice(device_id, user, DeviceLog.ADD) def sigRenameDevice(device_id, user, oldname, newname): sigDevice(device_id, user, DeviceLog.NAME, oldname, newname) def sigNetDevice(device_id, user, oldnet, newnet): sigDevice(device_id, user, DeviceLog.NET, oldnet, newnet) def sigWifiDevice(device_id, user, oldwifis, newwifis): for old in oldwifis: if old not in newwifis: sigDevice(device_id, user, DeviceLog.WIFI, str(old)) for new in newwifis: if new not in oldwifis: sigDevice(device_id, user, DeviceLog.WIFI, None, str(new)) def sigRebootDevice(device_id, user, newstate): sigDevice(device_id, user, DeviceLog.REBOOT, str(not newstate), str(newstate)) def sigUpdateDevice(device_id, user, newstate): sigDevice(device_id, user, DeviceLog.UPDATE, str(not newstate), str(newstate)) def sigOrgaDevice(device_id, user, oldorga, neworga): sigDevice(device_id, user, DeviceLog.ORGA, oldorga, neworga) # User Signals def sigUser(target, source, action, oldvalue=None, newvalue=None): siglog.send(sender=User, id=target, user=source, action=action, oldvalue=oldvalue, newvalue=newvalue) def sigAddUser(newuser, source): sigUser(newuser, source, UserLog.ADD) def sigDeleteUser(target, source): sigUser(target, source, UserLog.REMOVE) def sigRenameUser(target, source, oldname, newname): sigUser(target, source, UserLog.NAME, oldname, newname) def sigMailUser(target, source, oldmail, newmail): sigUser(target, source, UserLog.MAIL, oldmail, newmail) def sigStaffUser(target, source, newstatus): sigUser(target, source, UserLog.STAFF, str(not newstatus), str(newstatus)) def sigSuperUser(target, source, newstatus): sigUser(target, source, UserLog.SUPERUSER, str(not newstatus), str(newstatus)) def sigOrgaUser(target, source, oldorga, neworga): sigUser(target, source, UserLog.ORGA, oldorga, neworga) # WiFi Signals def sigWifi(wifi, user, action, oldvalue=None, newvalue=None): siglog.send(sender=Wifi, id=wifi, user=user, action=action, oldvalue=oldvalue, newvalue=newvalue) def sigAddWifi(wifi, user): sigWifi(wifi, user, WifiLog.ADD) def sigDeleteWifi(wifi, user): sigWifi(wifi, user, WifiLog.REMOVE) def sigRenameWifi(wifi, user, oldname, newname): sigWifi(wifi, user, WifiLog.NAME, oldname, newname) def sigSSIDWifi(wifi, user, oldssid, newssid): sigWifi(wifi, user, WifiLog.SSID, oldssid, newssid) def sigKeyWifi(wifi, user, oldkey, newkey): sigWifi(wifi, user, WifiLog.KEY, oldkey, newkey) def sigOrgaWifi(wifi, user, oldorga, neworga): sigWifi(wifi, user, WifiLog.ORGA, oldorga, neworga)