当前位置: 首页>>代码示例>>Python>>正文


Python db.get_typename_for_model_class函数代码示例

本文整理汇总了Python中taiga.base.utils.db.get_typename_for_model_class函数的典型用法代码示例。如果您正苦于以下问题:Python get_typename_for_model_class函数的具体用法?Python get_typename_for_model_class怎么用?Python get_typename_for_model_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_typename_for_model_class函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: freeze_model_instance

def freeze_model_instance(obj:object) -> FrozenObj:
    """
    Creates a new frozen object from model instance.

    The freeze process consists on converting model
    instances to hashable plain python objects and
    wrapped into FrozenObj.
    """

    model_cls = obj.__class__

    # Additional query for test if object is really exists
    # on the database or it is removed.
    try:
        obj = model_cls.objects.get(pk=obj.pk)
    except model_cls.DoesNotExist:
        return None

    typename = get_typename_for_model_class(model_cls)
    if typename not in _freeze_impl_map:
        raise RuntimeError("No implementation found for {}".format(typename))

    key = make_key_from_model_object(obj)
    impl_fn = _freeze_impl_map[typename]
    snapshot = impl_fn(obj)
    assert isinstance(snapshot, dict), "freeze handlers should return always a dict"

    return FrozenObj(key, snapshot)
开发者ID:SashaBorandi,项目名称:taiga-back,代码行数:28,代码来源:services.py

示例2: take_snapshot

def take_snapshot(obj:object, *, comment:str="", user=None, delete:bool=False):
    """
    Given any model instance with registred content type,
    create new history entry of "change" type.

    This raises exception in case of object wasn't
    previously freezed.
    """

    key = make_key_from_model_object(obj)
    typename = get_typename_for_model_class(obj.__class__)

    new_fobj = freeze_model_instance(obj)
    old_fobj, need_real_snapshot = get_last_snapshot_for_key(key)

    entry_model = apps.get_model("history", "HistoryEntry")
    user_id = None if user is None else user.id
    user_name = "" if user is None else user.get_full_name()

    # Determine history type
    if delete:
        entry_type = HistoryType.delete
    elif new_fobj and not old_fobj:
        entry_type = HistoryType.create
    elif new_fobj and old_fobj:
        entry_type = HistoryType.change
    else:
        raise RuntimeError("Unexpected condition")

    fdiff = make_diff(old_fobj, new_fobj)

    # If diff and comment are empty, do
    # not create empty history entry
    if (not fdiff.diff and not comment
        and old_fobj is not None
        and entry_type != HistoryType.delete):

        return None

    fvals = make_diff_values(typename, fdiff)

    if len(comment) > 0:
        is_hidden = False
    else:
        is_hidden = is_hidden_snapshot(fdiff)

    kwargs = {
        "user": {"pk": user_id, "name": user_name},
        "key": key,
        "type": entry_type,
        "snapshot": fdiff.snapshot if need_real_snapshot else None,
        "diff": fdiff.diff,
        "values": fvals,
        "comment": comment,
        "comment_html": mdrender(obj.project, comment),
        "is_hidden": is_hidden,
        "is_snapshot": need_real_snapshot,
    }

    return entry_model.objects.create(**kwargs)
开发者ID:AVert,项目名称:taiga-back,代码行数:60,代码来源:services.py

示例3: decorator

    def decorator(self, *args, **kwargs):
        from taiga.base.utils.db import get_typename_for_model_class
        pk = self.kwargs.get(self.pk_url_kwarg, None)
        tn = get_typename_for_model_class(self.get_queryset().model)
        key = "{0}:{1}".format(tn, pk)

        with advisory_lock(key):
            return func(self, *args, **kwargs)
开发者ID:shreeshreee,项目名称:taiga-back,代码行数:8,代码来源:decorators.py

示例4: make_key_from_model_object

def make_key_from_model_object(obj:object) -> str:
    """
    Create unique key from model instance.
    """
    tn = get_typename_for_model_class(obj.__class__)
    return "{0}:{1}".format(tn, obj.pk)
开发者ID:SashaBorandi,项目名称:taiga-back,代码行数:6,代码来源:services.py

示例5: _get_impl_key_from_model

def _get_impl_key_from_model(model:Model, event_type:str):
    if issubclass(model, Model):
        typename = get_typename_for_model_class(model)
        return _get_impl_key_from_typename(typename, event_type)
    raise Exception("Not valid model parameter")
开发者ID:ndjido,项目名称:taiga-back,代码行数:5,代码来源:service.py


注:本文中的taiga.base.utils.db.get_typename_for_model_class函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。