# Path: upribox_interface/devices/models.py
# class DeviceEntry(models.Model):
#     ip = models.CharField(max_length=20, unique=False)
#     mac = models.CharField(max_length=20, null=False, unique=True)
#     dhcp_fingerprint = models.CharField(max_length=256, null=True)
#     dhcp_vendor = models.CharField(max_length=256, null=True)
#     user_agent = models.ManyToManyField(UserAgent)
#     hostname = models.CharField(max_length=256, null=True)
#     MODES = (
#         ('SL', "Silent"),
#         ('NJ', "Ninja"),
#         ('NO', "No Mode")
#     )
#     mode = models.CharField(max_length=2, choices=MODES, default='SL')
#     chosen_name = models.CharField(max_length=256, null=True)
#     slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id, always_update=False, null=True)
#     changing = models.NullBooleanField(null=True, default=False)
#     last_seen = models.DateTimeField(default=timezone.now)
# 
#     objects = DeviceManager()


import json
import logging
import sqlite3
import lib.jobs as jobs
import lib.utils as utils
from django.utils.translation import ugettext as _
from .models import DeviceEntry
# -*- coding: utf-8 -*-
from __future__ import unicode_literals




logger = logging.getLogger('uprilogger')


def toggle_device_mode(mode, device):
    dbfile = None
    try:

# Path: upribox_interface/devices/models.py
# class DeviceEntry(models.Model):
#     ip = models.CharField(max_length=20, unique=False)
#     mac = models.CharField(max_length=20, null=False, unique=True)
#     dhcp_fingerprint = models.CharField(max_length=256, null=True)
#     dhcp_vendor = models.CharField(max_length=256, null=True)
#     user_agent = models.ManyToManyField(UserAgent)
#     hostname = models.CharField(max_length=256, null=True)
#     MODES = (
#         ('SL', "Silent"),
#         ('NJ', "Ninja"),
#         ('NO', "No Mode")
#     )
#     mode = models.CharField(max_length=2, choices=MODES, default='SL')
#     chosen_name = models.CharField(max_length=256, null=True)
#     slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id, always_update=False, null=True)
#     changing = models.NullBooleanField(null=True, default=False)
#     last_seen = models.DateTimeField(default=timezone.now)
# 
#     objects = DeviceManager()


# Path: upribox_interface/devices/jobs.py
import json
import logging
import sqlite3
import lib.jobs as jobs
import lib.utils as utils
from django.utils.translation import ugettext as _
from .models import DeviceEntry

# -*- coding: utf-8 -*-
from __future__ import unicode_literals




logger = logging.getLogger('uprilogger')


def toggle_device_mode(mode, device):
    dbfile = None
    try:

        if mode in [entry[0] for entry in DeviceEntry.MODES]: