mirror of
https://github.com/veops/cmdb.git
synced 2025-08-08 22:55:00 +08:00
feat: notice_config access messenger (#190)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
from api.extensions import cache
|
||||
from api.models.common_setting import CompanyInfo
|
||||
|
||||
|
||||
@@ -11,14 +11,34 @@ class CompanyInfoCRUD(object):
|
||||
|
||||
@staticmethod
|
||||
def create(**kwargs):
|
||||
return CompanyInfo.create(**kwargs)
|
||||
res = CompanyInfo.create(**kwargs)
|
||||
CompanyInfoCache.refresh(res.info)
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def update(_id, **kwargs):
|
||||
kwargs.pop('id', None)
|
||||
existed = CompanyInfo.get_by_id(_id)
|
||||
if not existed:
|
||||
return CompanyInfoCRUD.create(**kwargs)
|
||||
existed = CompanyInfoCRUD.create(**kwargs)
|
||||
else:
|
||||
existed = existed.update(**kwargs)
|
||||
return existed
|
||||
CompanyInfoCache.refresh(existed.info)
|
||||
return existed
|
||||
|
||||
|
||||
class CompanyInfoCache(object):
|
||||
key = 'CompanyInfoCache::'
|
||||
|
||||
@classmethod
|
||||
def get(cls):
|
||||
info = cache.get(cls.key)
|
||||
if not info:
|
||||
res = CompanyInfo.get_by(first=True) or {}
|
||||
info = res.get('info', {})
|
||||
cache.set(cls.key, info)
|
||||
return info
|
||||
|
||||
@classmethod
|
||||
def refresh(cls, info):
|
||||
cache.set(cls.key, info)
|
Reference in New Issue
Block a user