Ejemplo n.º 1
0
def get_named_value_raw(name):
    """
    Returns the NamedValue-Object with the given name.
    """

    try:
        return _global_keys[name].get()
    except KeyError:
        named_value = NamedValue.query(NamedValue.name == name).get()
        if named_value is not None:
            _global_keys[name] = named_value.key
            return named_value
Ejemplo n.º 2
0
def set_value(name, value):
    """
    Sets the value with the given name.
    """

    # Get existing named value
    named_value = get_named_value_raw(name)

    if named_value is None:
        # Create new named value
        named_value = NamedValue()
        named_value.name = name

    # Edit value
    named_value.value = value

    # Save
    named_value.put()

    # Finished
    return named_value
Ejemplo n.º 3
0
def decrement(name):
    """
    Decrements the value with the given name, if it is an integer.
    """

    # Get existing named value
    named_value = get_named_value_raw(name)

    if named_value is None:
        # Create new named value
        named_value = NamedValue()
        named_value.name = name
        named_value.value = 1

    # Edit value
    named_value.value -= 1

    # Save
    named_value.put()

    # Finished
    return named_value