本文整理汇总了Python中taiga.base.utils.db.get_typename_for_model_instance函数的典型用法代码示例。如果您正苦于以下问题:Python get_typename_for_model_instance函数的具体用法?Python get_typename_for_model_instance怎么用?Python get_typename_for_model_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_typename_for_model_instance函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: emit_event_for_model
def emit_event_for_model(obj, *, type:str="change", channel:str="events",
content_type:str=None, sessionid:str=None):
"""
Sends a model change event.
"""
assert type in set(["create", "change", "delete"])
assert hasattr(obj, "project_id")
if not content_type:
content_type = get_typename_for_model_instance(obj)
projectid = getattr(obj, "project_id")
pk = getattr(obj, "pk", None)
app_name, model_name = content_type.split(".", 1)
routing_key = "changes.project.{0}.{1}".format(projectid, app_name)
data = {"type": type,
"matches": content_type,
"pk": pk}
return emit_event(routing_key=routing_key,
channel=channel,
sessionid=sessionid,
data=data)
开发者ID:SashaBorandi,项目名称:taiga-back,代码行数:26,代码来源:events.py
示例2: on_delete_any_model
def on_delete_any_model(sender, instance, **kwargs):
# Ignore any object that can not have project_id
content_type = get_typename_for_model_instance(instance)
# Ignore any other changes
if content_type not in events.watched_types:
return
sesionid = mw.get_current_session_id()
events.emit_event_for_model(instance, sessionid=sesionid, type="delete")
开发者ID:FlorianBezagu,项目名称:taiga-back,代码行数:10,代码来源:signal_handlers.py
示例3: _serialize
def _serialize(obj):
content_type = get_typename_for_model_instance(obj)
if content_type == "userstories.userstory":
return UserStorySerializer(obj).data
elif content_type == "issues.issue":
return IssueSerializer(obj).data
elif content_type == "tasks.task":
return TaskSerializer(obj).data
elif content_type == "wiki.wikipage":
return WikiPageSerializer(obj).data
elif content_type == "milestones.milestone":
return MilestoneSerializer(obj).data
elif content_type == "history.historyentry":
return HistoryEntrySerializer(obj).data
开发者ID:david-strejc,项目名称:taiga-back,代码行数:15,代码来源:tasks.py
示例4: on_save_any_model
def on_save_any_model(sender, instance, created, **kwargs):
# Ignore any object that can not have project_id
content_type = get_typename_for_model_instance(instance)
# Ignore any other events
if content_type not in events.watched_types:
return
sesionid = mw.get_current_session_id()
type = "change"
if created:
type = "create"
emit_event = lambda: events.emit_event_for_model(instance, sessionid=sesionid, type=type)
connection.on_commit(emit_event)
开发者ID:SashaBorandi,项目名称:taiga-back,代码行数:16,代码来源:signal_handlers.py
示例5: _get_type
def _get_type(obj):
content_type = get_typename_for_model_instance(obj)
return content_type.split(".")[1]
开发者ID:david-strejc,项目名称:taiga-back,代码行数:3,代码来源:tasks.py
示例6: emit_live_notification_for_model
def emit_live_notification_for_model(obj, user, history, *, type:str="change", channel:str="events",
sessionid:str="not-existing"):
"""
Sends a model live notification to users.
"""
if obj._importing:
return None
content_type = get_typename_for_model_instance(obj)
if content_type == "userstories.userstory":
if history.type == HistoryType.create:
title = _("User story created")
url = resolve("userstory", obj.project.slug, obj.ref)
elif history.type == HistoryType.change:
title = _("User story changed")
url = resolve("userstory", obj.project.slug, obj.ref)
else:
title = _("User story deleted")
url = None
body = _("US #{} - {}").format(obj.ref, obj.subject)
elif content_type == "tasks.task":
if history.type == HistoryType.create:
title = _("Task created")
url = resolve("task", obj.project.slug, obj.ref)
elif history.type == HistoryType.change:
title = _("Task changed")
url = resolve("task", obj.project.slug, obj.ref)
else:
title = _("Task deleted")
url = None
body = _("Task #{} - {}").format(obj.ref, obj.subject)
elif content_type == "issues.issue":
if history.type == HistoryType.create:
title = _("Issue created")
url = resolve("issue", obj.project.slug, obj.ref)
elif history.type == HistoryType.change:
title = _("Issue changed")
url = resolve("issue", obj.project.slug, obj.ref)
else:
title = _("Issue deleted")
url = None
body = _("Issue: #{} - {}").format(obj.ref, obj.subject)
elif content_type == "wiki.wiki_page":
if history.type == HistoryType.create:
title = _("Wiki Page created")
url = resolve("wiki", obj.project.slug, obj.slug)
elif history.type == HistoryType.change:
title = _("Wiki Page changed")
url = resolve("wiki", obj.project.slug, obj.slug)
else:
title = _("Wiki Page deleted")
url = None
body = _("Wiki Page: {}").format(obj.slug)
elif content_type == "milestones.milestone":
if history.type == HistoryType.create:
title = _("Sprint created")
url = resolve("taskboard", obj.project.slug, obj.slug)
elif history.type == HistoryType.change:
title = _("Sprint changed")
url = resolve("taskboard", obj.project.slug, obj.slug)
else:
title = _("Sprint deleted")
url = None
body = _("Sprint: {}").format(obj.name)
else:
return None
return emit_event(
{
"title": title,
"body": "Project: {}\n{}".format(obj.project.name, body),
"url": url,
"timeout": 10000,
"id": history.id
},
"live_notifications.{}".format(user.id),
sessionid=sessionid
)
开发者ID:taigaio,项目名称:taiga-back,代码行数:79,代码来源:events.py
注:本文中的taiga.base.utils.db.get_typename_for_model_instance函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论