# 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 time
import lib.utils as utils
import netifaces as ni
from datetime import datetime, time, timedelta
from socket import AF_INET
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import render
from django.template import loader
from django.template.defaultfilters import date as _localdate
from django.utils.timezone import now as django_now
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_http_methods, require_POST
from lib import jobs
from www.templatetags.base_extras import get_device_name
from . import jobs as devicejobs
from .models import DeviceEntry
# -*- coding: utf-8 -*-
from __future__ import unicode_literals




# Get an instance of a logger
logger = logging.getLogger('uprilogger')


def get_entries():
    gateway = None
    try:
        gateway = ni.gateways()['default'][AF_INET][0]
    except KeyError:
        pass

    return sorted(

# 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/views.py
import json
import logging
import time
import lib.utils as utils
import netifaces as ni
from datetime import datetime, time, timedelta
from socket import AF_INET
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import render
from django.template import loader
from django.template.defaultfilters import date as _localdate
from django.utils.timezone import now as django_now
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_http_methods, require_POST
from lib import jobs
from www.templatetags.base_extras import get_device_name
from . import jobs as devicejobs
from .models import DeviceEntry

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




# Get an instance of a logger
logger = logging.getLogger('uprilogger')


def get_entries():
    gateway = None
    try:
        gateway = ni.gateways()['default'][AF_INET][0]
    except KeyError:
        pass

    return sorted(

        DeviceEntry.objects.filter(last_seen__gte=datetime.now() - timedelta(weeks=1), mac__regex=r'([0-9a-f]:?){12}')