23 lines
578 B
Python
23 lines
578 B
Python
from django.core.cache import cache
|
|
from counter.models import DeviceInfo
|
|
|
|
|
|
class RoleMixin(object):
|
|
def get_role(self):
|
|
user = self.request.user
|
|
user_roles = user.role.split(',')
|
|
|
|
return user_roles
|
|
|
|
|
|
class DeviceListMixin(object):
|
|
@staticmethod
|
|
def get_device_list():
|
|
if cache.has_key('device_list'):
|
|
device_list = cache.get('device_list')
|
|
else:
|
|
device_list = DeviceInfo.objects.get_queryset().order_by('-online')
|
|
cache.set('device_list', device_list, 60 * 60)
|
|
|
|
return device_list
|