示例#1
0
    def update_dataconnections(connections, direction):
        # Delete any connections that have been removed.
        new_connections = [
            connection['id'] for connection in connections if connection['id']
        ]
        # Watch out for odd behavior in list iteration while deleting.
        if direction is 'given':
            for connection in entity.data_given:
                if connection.id not in new_connections:
                    db.delete(connection)
        elif direction is 'received':
            for connection in entity.data_received:
                if connection.id not in new_connections:
                    db.delete(connection)
        db.commit()

        for connection in connections:
            if connection['id']:
                oldconnection = Dataconnection.query.get(connection['id'])
                if oldconnection.details != connection['details']:
                    oldconnection.details = connection['details']
            elif 'entity_id' in connection:
                otherentity = Entity.query.get(connection['entity_id'])
                newconnection = Dataconnection()
                if connection['details']:
                    newconnection.details = connection['details']
                if direction is 'given':
                    entity.data_given.append(newconnection)
                    otherentity.data_received.append(newconnection)
                elif direction is 'received':
                    entity.data_received.append(newconnection)
                    otherentity.data_given.append(newconnection)
        db.commit()
示例#2
0
def delete_reply(pid,rid):
    feed = db.query(Reply).filter_by(id=rid).first()
    if not feed:
        abort(404)
    db.delete(feed)
    db.commit()
    return redirect(u'/posts/post/'+pid)
示例#3
0
文件: post.py 项目: maxis1314/pyutils
def delete_post(pid):
    feed = db.query(Post).filter_by(id=pid).first()
    if not feed:
        abort(404)
    db.delete(feed)
    db.commit()
    return redirect("/posts/archive")
示例#4
0
    def update_dataconnections(connections, direction):
        # Delete any connections that have been removed.
        new_connections = [connection['id'] for connection in connections if connection['id']]
        # Watch out for odd behavior in list iteration while deleting.
        if direction is 'given':
            for connection in entity.data_given:
                if connection.id not in new_connections:
                    db.delete(connection)
        elif direction is 'received':
            for connection in entity.data_received:
                if connection.id not in new_connections:
                    db.delete(connection)
        db.commit()

        for connection in connections:
            if connection['id']:
                oldconnection = Dataconnection.query.get(connection['id'])
                if oldconnection.details != connection['details']:
                    oldconnection.details = connection['details']
            elif 'entity_id' in connection:
                otherentity = Entity.query.get(connection['entity_id'])
                newconnection = Dataconnection()
                if connection['details']:
                    newconnection.details = connection['details']
                if direction is 'given':
                    entity.data_given.append(newconnection)
                    otherentity.data_received.append(newconnection)
                elif direction is 'received':
                    entity.data_received.append(newconnection)
                    otherentity.data_given.append(newconnection)
        db.commit()
    def test_tuple_throughput(self):
        db = self.db
        db.open('test_tuple_throughput')
        db.delete('tuple')
        result = db.put('tuple', (2,3,4,5,6,))

        self.assertTrue(result)

        result = db.get('tuple')
        expected = (2, 3, 4, 5, 6)
        self.assertTupleEqual(result, expected)

        result = db.append('tuple', 3)
        expected = b'!:A1D!:2, 3, 4, 5, 6'
        self.assertEqual(result, expected)

        result = db.append('tuple', 3)
        expected = b'!:A1D!:2, 3, 4, 5, 6,3'
        self.assertEqual(result, expected)

        result = db.append('tuple', 3)
        expected = b'!:A1D!:2, 3, 4, 5, 6,3,3'
        self.assertEqual(result, expected)

        result = db.append('tuple', 3)
        expected = b'!:A1D!:2, 3, 4, 5, 6,3,3,3'
        self.assertEqual(result, expected)

        result = db.get('tuple')
        expected = (2, 3, 4, 5, 6, 3, 3, 3, 3,)
        self.assertTupleEqual(result, expected)
示例#6
0
def delete_imported():
    """Delete imported candidates, KeywordCandidate where Keyword exists with the same keyword"""
    candidates = db.query(
        KeywordCandidate,
        Keyword).filter(Keyword.keyword == KeywordCandidate.keyword)
    for candidate, _ in candidates:
        db.delete(candidate)
    db.commit()
示例#7
0
文件: items.py 项目: dpitkin/cecilia
 def get(self):
   user = database.users.get_current_user()
   if user and database.get_current_li().is_admin and database.get_current_li().verify_xsrf_token(self):
     item_feedback = db.get(db.Key.from_path('LoginInformation', int(cgi.escape(self.request.get('created_by'))), 'ItemFeedback', int(cgi.escape(self.request.get('feedback_id')))))
     db.delete(item_feedback)
     self.redirect(self.request.referer)
   else:
     self.redirect('/')
示例#8
0
文件: items.py 项目: dpitkin/cecilia
 def get(self):
   user = database.users.get_current_user()
   current_li = database.get_current_li()
   collection = db.get(db.Key.from_path('ItemCollection', int(cgi.escape(self.request.get('collection_id')))))
   if user and current_li and (collection.created_by_id == user.user_id() or current_li.is_admin):
     db.delete(collection)
     self.redirect(self.request.referer)
   else:
     self.redirect('/')
示例#9
0
文件: users.py 项目: dpitkin/cecilia
 def get(self):
   user = database.users.get_current_user()
   if user and database.get_current_li().is_admin and database.get_current_li().verify_xsrf_token(self):
     feedback_id = cgi.escape(self.request.get('feedback_id'))
     f = db.get(db.Key.from_path('UserFeedback', int(feedback_id)))
     db.delete(f)
     self.redirect(self.request.referer)
   else:
     self.redirect('/')
示例#10
0
async def dispose(request):

    try:
        req_id = request.args["id"].split("P")[0]
        db.delete(req_id)

    except:

        return json({"error": "failed to dispose"}, status=500)

    return json(status=200)
示例#11
0
文件: items.py 项目: dpitkin/cecilia
 def get(self):
   user = database.users.get_current_user()
   current_li = database.get_current_li()
   collection = db.get(db.Key.from_path('ItemCollection', int(cgi.escape(self.request.get('collection_id')))))
   if user and current_li and collection.created_by_id == user.user_id():
     if len(collection.get_items()) > 0:
       database.render_template(self, '/items/view_collection.html', {'items': collection.get_items()})
     else:
       db.delete(collection)
       self.redirect(self.request.referer)
   else:
     self.redirect('/')
示例#12
0
 def get(self, whom_name):
     who = self.current_user
     whom = db.query(User).filter(User.name == whom_name).first()
     if not whom:
         raise tornado.web.HTTPError(404)
     follower = db.query(Follower).filter(
         sa.and_(Follower.who_id == who.id,
                 Follower.whom_id == whom.id)).first()
     db.delete(follower)
     db.commit()
     self.redirect(self.next_url)
     return
示例#13
0
文件: items.py 项目: dpitkin/cecilia
 def get(self):
   user = database.users.get_current_user()
   if user and database.get_current_li().verify_xsrf_token(self):
     item = db.get(db.Key.from_path('Item', int(cgi.escape(self.request.get('item_id')))))
     feedback = db.GqlQuery("SELECT * FROM ItemFeedback WHERE item_id = :1", str(item.key().id()))
     #make sure the person owns this item or they're an admin
     if (item.created_by_id == user.user_id()) or (database.get_current_li().is_admin):
       database.logging.info("Deleting item with id %s by user_id %s", item.key().id(), user.user_id())
       database.db.delete(item)
       for f in feedback:
         db.delete(f)
     self.redirect(self.request.referer)
   else:
     self.redirect('/')
示例#14
0
 def get(self, post_id):
     post_id = int(post_id)
     user = self.current_user
     post = db.query(Post).get(post_id)
     if post and post.user_id != user.id:
         favorite = db.query(Favorite).filter(sa.and_(Favorite.user_id ==\
             user.id, Favorite.post_id == post.id)).first()
         if favorite:
             db.delete(favorite)
         else:
             favorite = Favorite(user_id=user.id, post_id=post.id)
             db.add(favorite)
         db.commit()
     else:
         self.redirect(self.next_url)
     return
    def test_tuple_put_append_get(self):
        db = self.db
        db.open('test_tuples')

        key = 'poppy'
        ta = (10,11,12,)
        tb = (1,2,3)
        db.delete(key)

        db.put(key, ta)
        db.append(key, tb)
        c_list = db.collect(key, convert=False)
        self.assertEqual(len(c_list), 1)

        result = db.get(key)
        expected = ta + tb
        self.assertTupleEqual(result, expected)
示例#16
0
    def update_connections(connections, ctype):
        # Delete any connections that have been removed.
        new_connections = [
            connection['id'] for connection in connections if connection['id']
        ]
        # Watch out for odd behavior in list iteration while deleting.
        if ctype is 'collaborations':
            for connection in entity.collaborations:
                if connection.id not in new_connections:
                    db.delete(connection)
        elif ctype is 'employments':
            for connection in entity.employments:
                if connection.id not in new_connections:
                    db.delete(connection)
        # elif ctype is 'relations':
        #     for connection in entity.relations:
        #         if connection.id not in new_connections:
        #             db.delete(connection)
        db.commit()

        for connection in connections:
            if connection['id']:
                # Connection exists, update details.
                oldconnection = Connection.query.get(connection['id'])
                if oldconnection.details != connection['details']:
                    oldconnection.details = connection['details']
                    app.logger.debug('UPDATING CONNECTION DETAILS',
                                     oldconnection.details)
            elif 'entity_id' in connection:
                otherentity = Entity.query.get(connection['entity_id'])
                if ctype is 'collaborations':
                    collaboration = Collaboration(entity, otherentity,
                                                  connection['details'])
                    app.logger.debug('CREATED NEW COLLABORATION ',
                                     collaboration.details)
                elif ctype is 'employments':
                    employment = Employment(entity, otherentity,
                                            connection['details'])
                    app.logger.debug('CREATED NEW EMPLOYMENT ',
                                     employment.details)
                elif ctype is 'relations':
                    relation = Relation(entity, otherentity,
                                        connection['details'])
                    app.logger.debug('CREATED NEW RELATION ', relation.details)
        db.commit()
示例#17
0
    def update_fundingconnections(connections, ftype, direction):
        # Delete and connections that have been removed.
        new_connections = [connection['id'] for connection in connections if connection['id']]
        # TODO: See if you can make this generic to handle any set of connections for simplicity.
        # TODO: Maybe list comprehensions in stead depending on how cascade='delete-orphan' works.
        if ftype is 'investment':
            if direction is 'given':
                for connection in entity.investments_made:
                    if connection.id not in new_connections:
                        db.delete(connection)
            elif direction is 'received':
                for connection in entity.investments_received:
                    if connection.id not in new_connections:
                        db.delete(connection)
        elif ftype is 'grant':
            if direction is 'given':
                for connection in entity.grants_given:
                    if connection.id not in new_connections:
                        db.delete(connection)
            elif direction is 'received':
                for connection in entity.grants_received:
                    if connection.id not in new_connections:
                        db.delete(connection)
        db.commit()

        for connection in connections:
            if connection['id']:
                # Connection exists, update amount and year.
                oldconnection = Fundingconnection.query.get(connection['id'])
                if oldconnection.amount != connection['amount']:
                    oldconnection.amount = connection['amount']
                    app.logger.debug('UPDATING ' + ftype + ' AMOUNT: ' + str(oldconnection.amount))
                if oldconnection.year != connection['year']:
                    oldconnection.year = connection['year']
                    app.logger.debug('UPDATING ' + ftype + ' YEAR: ' + str(oldconnection.year))
            elif 'entity_id' in connection:
                # Connection doesn't exist, create it connect entities.
                otherentity = Entity.query.get(connection['entity_id'])
                if ftype is 'investment':
                    newconnection = Investment(connection['amount'], connection['year'])
                    if direction is 'given':
                        entity.investments_made.append(newconnection)
                        otherentity.investments_received.append(newconnection)
                    elif direction is 'received':
                        entity.investments_received.append(newconnection)
                        otherentity.investments_made.append(newconnection)
                elif ftype is 'grant':
                    newconnection = Grant(connection['amount'], connection['year'])
                    if direction is 'given':
                        entity.grants_given.append(newconnection)
                        otherentity.grants_received.append(newconnection)
                    elif direction is 'received':
                        entity.grants_received.append(newconnection)
                        otherentity.grants_given.append(newconnection)
        db.commit()
示例#18
0
    def update_fundingconnections(connections, ftype, direction):
        # Delete and connections that have been removed.
        new_connections = [connection['id'] for connection in connections if connection['id']]
        # TODO: See if you can make this generic to handle any set of connections for simplicity.
        # TODO: Maybe list comprehensions in stead depending on how cascade='delete-orphan' works.
        if ftype is 'investment':
            if direction is 'given':
                for connection in entity.investments_made:
                    if connection.id not in new_connections:
                        db.delete(connection)
            elif direction is 'received':
                for connection in entity.investments_received:
                    if connection.id not in new_connections:
                        db.delete(connection)
        elif ftype is 'grant':
            if direction is 'given':
                for connection in entity.grants_given:
                    if connection.id not in new_connections:
                        db.delete(connection)
            elif direction is 'received':
                for connection in entity.grants_received:
                    if connection.id not in new_connections:
                        db.delete(connection)
        db.commit()

        for connection in connections:
            if connection['id']:
                # Connection exists, update amount and year.
                oldconnection = Fundingconnection.query.get(connection['id'])
                if oldconnection.amount != connection['amount']:
                    oldconnection.amount = connection['amount']
                    app.logger.debug('UPDATING ' + ftype + ' AMOUNT: ' + str(oldconnection.amount))
                if oldconnection.year != connection['year']:
                    oldconnection.year = connection['year']
                    app.logger.debug('UPDATING ' + ftype + ' YEAR: ' + str(oldconnection.year))
            elif 'entity_id' in connection:
                # Connection doesn't exist, create it connect entities.
                otherentity = Entity.query.get(connection['entity_id'])
                if ftype is 'investment':
                    newconnection = Investment(connection['amount'], connection['year'])
                    if direction is 'given':
                        entity.investments_made.append(newconnection)
                        otherentity.investments_received.append(newconnection)
                    elif direction is 'received':
                        entity.investments_received.append(newconnection)
                        otherentity.investments_made.append(newconnection)
                elif ftype is 'grant':
                    newconnection = Grant(connection['amount'], connection['year'])
                    if direction is 'given':
                        entity.grants_given.append(newconnection)
                        otherentity.grants_received.append(newconnection)
                    elif direction is 'received':
                        entity.grants_received.append(newconnection)
                        otherentity.grants_given.append(newconnection)
        db.commit()
def delete_list(id_list):
    if request.method == "DELETE":
        # query for check list
        query_db = db.read("lists", "id", id_list)
        list_user = query_db[0] if len(query_db) == 1 else None
        if list_user == None:
            return jsonify(error(404, "List not exists"))

        else:
            if db.delete("lists", id_list):

                # delete all tasks
                tasks = db.read("tasks", "id_list", id_list)
                if len(tasks) > 0:
                    for task in tasks:
                        db.delete("tasks", task["id"])

                return jsonify(error(200, "Removed"))

            else:
                return jsonify(error(400, "Not removed"))
def delete_favorite_place(username, id_place):
    result, code = db.get_one(FavoritePlace, id_place)

    if code == 200:
        favorite_place = get_row_dict(result)

        if favorite_place['user'] != username:
            return "O usuário não tem permissão para deletar esse local favorito", 401

        result, code = db.delete(FavoritePlace, id_place)

    return result, code
示例#21
0
 def get(self, post_id):
     post_id = int(post_id)
     user = self.current_user
     post = db.query(Post).get(post_id)
     if post and post.type != 2 and post.user_id != user.id:
         re_post = db.query(Post).filter(
             sa.and_(Post.type == 2, Post.user_id == user.id,
                     Post.post_id == post_id)).first()
         if re_post:
             db.delete(re_post)
         else:
             re_post = Post(user_id=user.id,
                            content='',
                            origin_content='',
                            type=2,
                            post_id=post.id)
             db.add(re_post)
         db.commit()
     else:
         self.redirect(self.next_url)
     return
    def test_delete(self):
        db = self.db
        db.open('test_delete')
        db.wipe()
        db.put('a', 'b')
        db.put('a', 'e')
        db.put('b', 'c')
        db.put('c', 'd')
        db.put('c', 'e')
        db.put('d', 'f')

        keys = tuple(db.iter())
        expected = (
                ('a', 'b'),
                ('a', 'e'),
                ('b', 'c'),
                ('c', 'd'),
                ('c', 'e'),
                ('d', 'f')
                )
        self.assertTupleEqual(keys, expected)
        result = db.delete('a')
        self.assertTrue(result)
        keys = tuple(db.iter())
        expected = (
                ('b', 'c'),
                ('c', 'd'),
                ('c', 'e'),
                ('d', 'f')
                )
        self.assertTupleEqual(keys, expected)

        result = db.delete('c', value='d')
        keys = tuple(db.iter())
        expected = (
                ('b', 'c'),
                ('c', 'e'),
                ('d', 'f')
                )
        self.assertTupleEqual(keys, expected)
示例#23
0
    def update_connections(connections, ctype):
        # Delete any connections that have been removed.
        new_connections = [connection['id'] for connection in connections if connection['id']]
        # Watch out for odd behavior in list iteration while deleting.
        if ctype is 'collaborations':
            for connection in entity.collaborations:
                if connection.id not in new_connections:
                    db.delete(connection)
        elif ctype is 'employments':
            for connection in entity.employments:
                if connection.id not in new_connections:
                    db.delete(connection)
        # elif ctype is 'relations':
        #     for connection in entity.relations:
        #         if connection.id not in new_connections:
        #             db.delete(connection)
        db.commit()

        for connection in connections:
            if connection['id']:
                # Connection exists, update details.
                oldconnection = Connection.query.get(connection['id'])
                if oldconnection.details != connection['details']:
                    oldconnection.details = connection['details']
                    # app.logger.debug('UPDATING CONNECTION DETAILS', oldconnection.details)
            elif 'entity_id' in connection:
                otherentity = Entity.query.get(connection['entity_id'])
                if ctype is 'collaborations':
                    collaboration = Collaboration(entity, otherentity, connection['details'])
                    # app.logger.debug('CREATED NEW COLLABORATION ', collaboration.details)
                elif ctype is 'employments':
                    employment = Employment(entity, otherentity, connection['details'])
                    # app.logger.debug('CREATED NEW EMPLOYMENT ', employment.details)
                elif ctype is 'relations':
                    relation = Relation(entity, otherentity, connection['details'])
                    # app.logger.debug('CREATED NEW RELATION ', relation.details)
        db.commit()
def delete_task(id_task):
    if request.method == "DELETE":
        # query for check task
        query_db = db.read("tasks", "id", id_task)
        task = query_db[0] if len(query_db) == 1 else None
        if task == None:
            return jsonify(error(404, "Task not exists"))

        else:
            if db.delete("tasks", id_task):

                return jsonify(error(200, "Removed"))

            else:
                return jsonify(error(400, "Not removed"))
示例#25
0
文件: post.py 项目: yetone/orange
 def get(self, post_id):
     post_id = int(post_id)
     user = self.current_user
     post = db.query(Post).get(post_id)
     if post and post.user_id == user.id:
         comments = post.get_comments()
         retweets = post.get_retweets()
         if comments != []:
             for comment in comments:
                 db.delete(comment)
         if retweets != []:
             for retweet in retweets:
                 db.delete(retweet)
         db.delete(post)
         db.commit()
     else:
         self.redirect(self.next_url)
     return
示例#26
0
 def test_delete(self):
     db.delete('1')
     uid = db.getuserid('1', '1')
     self.assertEqual(uid, -1)
示例#27
0
def delete_champ(champ_id: int):
    champ = db.query(Champ).get(champ_id)
    db.delete(champ)
    db.commit()
def delete_occurrence(id_occurrence, username=None):
    result, code = db.delete(Occurrence, id_occurrence, username)

    return result, code
示例#29
0
def delete_rating(rating_id, username=None):
    result, code = db.delete(Rating, rating_id, username)

    return result, code
示例#30
0
 def remove(channel_id: int):
     db.delete(db.get(LogExclude, channel_id))
def delete_neighborhood(neighborhood_id):
    result, code = db.delete(Neighborhood, neighborhood_id)

    return result, code
示例#32
0
def delete_user(username):
    result, code = db.delete(User, username)

    return result, code