Example #1
0
def delete_all_items(author, category_name):
    """Delete all items of specified author and category

    When delete an item, all comments belonging to as well as vote result
    would be delete automatically
    :param author the specified author
    :param category_name the specified category name
    """
    ancestor_key = get_ancestor_key(author, category_name)
    item_query = rankdata.Item.all().ancestor(ancestor_key)
    for item in item_query.run():
        comment.delete_all_comments('{author}/{category}'.format(author=author, category=category_name), item.name)
        db.delete(item)
Example #2
0
def delete_items(author, category_name, item_names=[]):
    """Delete items of specified author, category and item name

    When delete an item, all comments belonging to as well as vote result
    would be delete automatically
    :param author the specified author
    :param category_name the specified category name
    "param item_names the specified item name list
    """
    for item_name in item_names:
        key = db.Key.from_path('Item',
                               '{author}/{category}/{item}'.format(author=author, category=category_name, item=item_name),
                               parent=get_ancestor_key(author, category_name))
        comment.delete_all_comments('{author}/{category}'.format(author=author, category=category_name), db.get(key).name)
        db.delete(key)
Example #3
0
def update_item(author, category_name, new_item_name, old_item_name):
    """Update item of specified author, category name, new item name, and
       old item name

    When update the item name, all comments belonging to the old item as
    well as the vote result would be delete automatically.
    :param author the specified author
    :param category_name the specified category name
    :param new_item_name the specified new item name
    :param old_item_name the specified old item name
    """
    old_item = get_item(author=author, category_name=category_name, item_name=old_item_name)
    comment.delete_all_comments(category_key='{author}/{category}'.format(author=author, category=category_name), item_name=old_item_name)
    db.delete(old_item)

    new_item = rankdata.Item(key_name='{author}/{category}/{item}'.format(author=author, category=category_name, item=new_item_name),
                             parent=get_ancestor_key(author, category_name),
                             name=new_item_name,
                             number_of_win=0, number_of_lose=0, percentage=-1.0)
    new_item.put()