コード例 #1
0
ファイル: files.py プロジェクト: Acidburn0zzz/pontoon
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
0
def _save_entity(project, original, comment="", key="", source=""):
    """Admin interface: save new or update existing entity in DB."""

    try:  # Update existing entity
        if key is "":
            e = Entity.objects.get(project=project, string=original)
        else:
            e = Entity.objects.get(project=project, key=key, source=source)
            e.string = original
    except Entity.DoesNotExist:  # Add new entity
        e = Entity(project=project, string=original, key=key, source=source)

    if len(comment) > 0:
        e.comment = comment
    e.save()