2018-03-23 11:46:46 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2022-11-25 10:06:22 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.utils import timezone
|
2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2018-03-23 11:46:46 +00:00
|
|
|
|
2023-01-16 11:02:09 +00:00
|
|
|
from assets.const import Connectivity
|
2019-03-18 02:15:33 +00:00
|
|
|
from common.utils import (
|
2023-01-16 11:02:09 +00:00
|
|
|
get_logger
|
2019-03-18 02:15:33 +00:00
|
|
|
)
|
2018-03-23 11:46:46 +00:00
|
|
|
|
2019-03-18 02:15:33 +00:00
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
2018-03-23 11:46:46 +00:00
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
class AbsConnectivity(models.Model):
|
|
|
|
connectivity = models.CharField(
|
2022-11-08 09:54:51 +00:00
|
|
|
choices=Connectivity.choices, default=Connectivity.UNKNOWN,
|
2021-07-08 06:23:18 +00:00
|
|
|
max_length=16, verbose_name=_('Connectivity')
|
|
|
|
)
|
2021-07-12 12:38:01 +00:00
|
|
|
date_verified = models.DateTimeField(null=True, verbose_name=_("Date verified"))
|
2019-06-21 12:57:51 +00:00
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
def set_connectivity(self, val):
|
|
|
|
self.connectivity = val
|
|
|
|
self.date_verified = timezone.now()
|
|
|
|
self.save(update_fields=['connectivity', 'date_verified'])
|
2019-06-21 12:57:51 +00:00
|
|
|
|
2022-12-02 12:28:49 +00:00
|
|
|
@property
|
|
|
|
def is_connective(self):
|
|
|
|
if self.connectivity == Connectivity.OK:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
@classmethod
|
2021-07-08 06:23:18 +00:00
|
|
|
def bulk_set_connectivity(cls, queryset_or_id, connectivity):
|
2022-12-02 09:36:55 +00:00
|
|
|
if not isinstance(queryset_or_id, models.QuerySet):
|
2021-07-08 06:23:18 +00:00
|
|
|
queryset = cls.objects.filter(id__in=queryset_or_id)
|
|
|
|
else:
|
|
|
|
queryset = queryset_or_id
|
|
|
|
queryset.update(connectivity=connectivity, date_verified=timezone.now())
|
2019-07-04 13:17:39 +00:00
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|