def edit_task():
    body = json.loads(request.data)
    task_key = body.get('_key', None)
    task = db.query(Tasks).by_key(task_key)
    if task is None:
        return jsonify({'message':'task not found'})

    name = body.get('name',None)
    description = body.get('description', None)
    task.name = name
    task.description = description
    db.update(task)

    category_key = body.get('category_key', None)
    category = db.query(Categories).by_key(category_key)
    if category is not None:
        # find old category relation and delete it
        old_category_relation = db.query(Category_Relation).filter('_to==@_to',_to=task._id).first()
        db.delete(old_category_relation)

        # add new category relation
        db.add(task_graph.relation(relation_from=category, relation=Category_Relation(), relation_to=task))

    assignee_key = body.get('assignee_key', None)
    assignee = db.query(People).by_key(assignee_key)
    if assignee is not None:
        # find old assignee relation and delete it
        old_assignee_relation = db.query(Assignee_Relation).filter('_from==@_from',_from=task._id).first()
        db.delete(old_assignee_relation)

        # add new assignee relation
        db.add(task_graph.relation(relation_from=task, relation=Assignee_Relation(), relation_to=assignee))

    return jsonify({'result':task._dump()}), 200
예제 #2
0
def delete_clients():
    body = json.loads(request.data)
    key = body.get('_key', None)
    if key is None:
        return jsonify({'error': 'key cannot be null'})

    client = db.query(Clients).by_key(key)
    db.delete(client)
    return jsonify({'result': 'success'})
예제 #3
0
def delete_shop():
    body = json.loads(request.data)
    key = body.get('_key', None)
    if key is None:
        return jsonify({'error': 'key cannot be null'})

    shop = db.query(Shops).by_key(key)
    db.delete(shop)
    return jsonify({'result': 'success'})
def delete_person():
    body = json.loads(request.data)
    key = body.get('_key', None)
    if key is None:
        return jsonify({'error': 'key cannot be null'})

    person = db.query(People).by_key(key)
    db.delete(person)
    return jsonify({'result': 'success'})
def remove_categories():
    body = json.loads(request.data)
    category_key = body.get('_key', None)
    category = db.query(Categories).by_key(category_key)
    if category is not None:
        db.delete(category)
    else:
        return jsonify({'error':'Category not found'}), 200
    return jsonify({'result': 'success'}), 200
def remove_task():
    body = json.loads(request.data)
    task_key = body.get('_key', None)
    task = db.query(Tasks).by_key(task_key)
    if task is None:
        return jsonify({'message': 'task not found'})

    db.delete(task)
    return jsonify(({'message':'success'}))
예제 #7
0
def edit_product():
    body = json.loads(request.data)
    key = body.get('_key', None)
    if key is None:
        return jsonify({'error': 'key cannot be null'})
    product = db.query(Products).by_key(key)
    if product is None:
        return jsonify({'error': 'product not found'})

    # TODO this but programmatically if things change
    name = body.get('name', None)
    if name is not None:
        product.name = name
    description = body.get('description', None)
    if description is not None:
        product.description = description
    imageLocation = body.get('imageLocation', None)
    if imageLocation is not None:
        product.imageLocation = imageLocation
    price = body.get('price', None)
    if price is not None:
        product.price = price
    discount = body.get('discount', None)
    if discount is not None:
        product.discount = discount
    db.update(product)

    #relations
    category_key = body.get('category_key', None)
    category = db.query(Categories).by_key(category_key)
    if category is not None:
        # find old category relation and delete it
        old_category_relation = db.query(Category_Relation).filter(
            '_to==@_to', _to=product._id).first()
        db.delete(old_category_relation)
        # add new category relation
        db.add(
            product_graph.relation(relation_from=category,
                                   relation=Category_Relation(),
                                   relation_to=product))
    shop_key = body.get('shop_key', None)
    shop = db.query(Shops).by_key(shop_key)
    if shop is not None:
        # find old assignee relation and delete it
        old_shop_relation = db.query(Shop_Relation).filter(
            '_from==@_from', _from=product._id).first()
        db.delete(old_shop_relation)
        # add new assignee relation
        db.add(
            product_graph.relation(relation_from=product,
                                   relation=Shop_Relation(),
                                   relation_to=shop))

    return jsonify({'result': product._dump()})
예제 #8
0
파일: manager.py 프로젝트: 7flying/takonosu
def delete_node(id):
	"""
	Deletes a node from the db as well as all the sensors related to the node.
	"""
	debug(CODE, "DELETE NODE: (id): " + str(id))
	id = str(id)
	sensors = set(db.smembers(KEY_LIST_SENSORS_IN_NODE + id))
	for id_sensor in sensors:
		delete_sensor_from_node(id, id_sensor)
	db.delete(KEY_LIST_SENSORS_IN_NODE + id)
	db.delete(KEY_NODES + id)
예제 #9
0
파일: manager.py 프로젝트: 7flying/yil-pil
def delete_user(username): #OK -> DELETE ALL HIS/HER POSTS and stuff
    """ Deletes a user. """
    if _is_user_created(username):
        # Delete tags
        user_tags = get_user_tags(username)
        for tag in user_tags:
            delete_tag_user_tags(username, tag)
        # Delete voting records
        db.delete(username + APPEND_KEY_HAS_VOTED)
        # Delete favourites
        db.delete(username + APPEND_KEY_FAVS)
        # Delete posts
        user_posts = _get_posts(username)
        for post in user_posts:
            delete_post(post, username)
        return db.delete(username + APPEND_KEY_USER) > 0
    return False
예제 #10
0
파일: manager.py 프로젝트: 7flying/yil-pil
def delete_post(post_id, username):
    """
    Deletes a post (as well as its related set of tags).
    """
    debug("DELETE POST. username:"******",post:" + str(post_id))
    post_id = str(post_id)
    if _is_post_created(post_id):
        # Delete each of the tags (to decrement the score in the ranking)
        for temp_tag in get_post_tags(post_id):
            delete_tag_from_post(post_id, temp_tag)
        # Delete the set of tags that the post has
        tags_id = db.hget(post_id + APPEND_KEY_POSTS, KEY_TAGS)
        db.delete(tags_id + APPEND_KEY_TAG)
        # Delete the counter of votes that the post has
        votes_id = db.hget(post_id + APPEND_KEY_POSTS, KEY_VOTES)
        db.delete(votes_id + APPEND_KEY_VOTE)
        # Delete the post from the sorted set of posts by date
        db.zrem(username + APPEND_SEARCH_POST_TIMEDATE, post_id)
        # Delete the post id from the user's post list
        # (1 is the number of items to be removed)
        db.lrem(username + APPEND_KEY_POSTS, 1, post_id)
        # Delete the post from the last updates
        _delete_post_last_updates(post_id)
        # Delete the post from the global ranking
        db.zrem(POPULAR_TOP_POSTS, post_id)
        # Delete the hash of the post
        db.delete(post_id + APPEND_KEY_POSTS)
        """
        db.hdel(post_id  + APPEND_KEY_POSTS, KEY_TAGS)
        db.hdel(post_id + APPEND_KEY_POSTS, KEY_TITLE)
        db.hdel(post_id + APPEND_KEY_POSTS, KEY_DATE)
        db.hdel(post_id + APPEND_KEY_POSTS, KEY_CONTENTS)
        """
        return True
    else:
        return False
예제 #11
0
파일: manager.py 프로젝트: 7flying/takonosu
def delete_sensor_from_node(node_id, sensor_id):
	""" Deletes a sensor from the node."""
	db.srem(KEY_LIST_SENSORS_IN_NODE + str(node_id), str(sensor_id))
	db.delete(KEY_SENSORS + str(sensor_id))
예제 #12
0
파일: manager.py 프로젝트: 7flying/yil-pil
def _remove_post_tag_name(post_id, tag_name):
    """ Removes a post-id form the set of tag-name -- post-ids. """
    db.srem(tag_name + APPEND_TAG_NAME_POSTS, str(post_id))
    if db.scard(tag_name + APPEND_TAG_NAME_POSTS) == 0:
        db.delete(tag_name + APPEND_TAG_NAME_POSTS)