2021-08-24 06:20:54 +00:00
|
|
|
import importlib
|
|
|
|
|
2021-05-31 09:20:38 +00:00
|
|
|
from django.db import models
|
2024-03-22 10:05:43 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-05-31 09:20:38 +00:00
|
|
|
|
2021-08-24 06:20:54 +00:00
|
|
|
client_name_mapper = {}
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BACKEND(models.TextChoices):
|
|
|
|
EMAIL = 'email', _('Email')
|
|
|
|
WECOM = 'wecom', _('WeCom')
|
|
|
|
DINGTALK = 'dingtalk', _('DingTalk')
|
|
|
|
SITE_MSG = 'site_msg', _('Site message')
|
2021-08-12 08:44:06 +00:00
|
|
|
FEISHU = 'feishu', _('FeiShu')
|
2024-03-22 10:05:43 +00:00
|
|
|
LARK = 'lark', 'Lark'
|
2023-11-29 09:45:44 +00:00
|
|
|
SLACK = 'slack', _('Slack')
|
2024-03-22 10:05:43 +00:00
|
|
|
|
2021-09-13 03:03:06 +00:00
|
|
|
# SMS = 'sms', _('SMS')
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def client(self):
|
2021-08-24 06:20:54 +00:00
|
|
|
return client_name_mapper[self]
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
def get_account(self, user):
|
|
|
|
return self.client.get_account(user)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_enable(self):
|
|
|
|
return self.client.is_enable()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def filter_enable_backends(cls, backends):
|
|
|
|
enable_backends = [b for b in backends if cls(b).is_enable]
|
|
|
|
return enable_backends
|
2021-08-24 06:20:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
for b in BACKEND:
|
|
|
|
m = importlib.import_module(f'.{b}', __package__)
|
|
|
|
client_name_mapper[b] = m.backend
|