from django.core.cache import cache from counter.models import DeviceInfo from mosquito.models import WeatherStationInfo 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.get('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 class WeatherStationListMixin(object): @staticmethod def get_weather_station_list(): if cache.get('device_list'): device_list = cache.get('device_list') else: device_list = WeatherStationInfo.objects.get_queryset().order_by('-device_id') cache.set('device_list', device_list, 60 * 60) return device_list