本文整理汇总了Python中pontoon.base.models.Entity.save方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.save方法的具体用法?Python Entity.save怎么用?Python Entity.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pontoon.base.models.Entity
的用法示例。
在下文中一共展示了Entity.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_entity
# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import save [as 别名]
def save_entity(resource, string, string_plural="", comment="",
key="", source=""):
"""Admin interface: save new or update existing entity in DB."""
# Update existing entity
try:
if key is "":
e = Entity.objects.get(
resource=resource, string=string,
string_plural=string_plural)
else:
e = Entity.objects.get(resource=resource, key=key)
e.string = string
e.string_plural = string_plural
e.source = source
# Set obsolete attribute for all updated entities to False
e.obsolete = False
# Add new entity
except Entity.DoesNotExist:
e = Entity(resource=resource, string=string,
string_plural=string_plural, key=key, source=source)
if len(comment) > 0:
e.comment = comment
e.save()
示例2: execute_create_db
# 需要导入模块: from pontoon.base.models import Entity [as 别名]
# 或者: from pontoon.base.models.Entity import save [as 别名]
def execute_create_db(self):
for vcs_entity in self.changes['create_db']:
entity = Entity(**self.get_entity_updates(vcs_entity))
entity.save() # We can't use bulk_create since we need a PK
for locale_code, vcs_translation in vcs_entity.translations.items():
for plural_form, string in vcs_translation.strings.items():
self.translations_to_create.append(Translation(
entity=entity,
locale=self.locales[locale_code],
string=string,
plural_form=plural_form,
approved=not vcs_translation.fuzzy,
approved_date=self.now if not vcs_translation.fuzzy else None,
fuzzy=vcs_translation.fuzzy
))