Yet more LOCs

This commit is contained in:
Kumi 2019-04-21 08:52:07 +00:00
parent c41cd90a3e
commit 41f872fad5

View file

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