当前位置: 首页>>代码示例>>Python>>正文


Python Session.delete方法代码示例

本文整理汇总了Python中models.Session.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Session.delete方法的具体用法?Python Session.delete怎么用?Python Session.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Session的用法示例。


在下文中一共展示了Session.delete方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: signin

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
def signin():
    if 'username' not in request.form or 'secret' not in request.form or 'openport' not in request.form:
        return "\"POST request must contain 'openport', 'username' and 'secret' fields\""
    session = Session()
    username = request.form['username']
    secret = request.form['secret']
    openport = int(request.form['openport'])
    users = session.query(User).filter(User.id == username).all()
    if (len(users) == 0):
        now = datetime.datetime.now()
        user = User(id=username, secret = secret, lastping = now, lastip=request.remote_addr, lastport = openport)
        session.add(user)
        session.commit()
        session.close()
        return json.dumps("True")
    else:
        if users[0].secret == secret:
            users[0].lastip = request.remote_addr
            users[0].lastport = openport
            users[0].lastping = datetime.datetime.now()
            session.add(users[0])
            for ownership in session.query(Owner).filter(Owner.owner == username).all():
                session.delete(ownership)
            session.commit()
            session.close()
            return json.dumps(True)
        else:
            return json.dumps(False)
开发者ID:ndm25,项目名称:sp2p,代码行数:30,代码来源:privclient.py

示例2: makefriend

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
def makefriend(request):
	login = authenticated_userid(request)		
	if(login!= None):
		parsed = urlparse.urlparse(request.referer)
		friendid = int(urlparse.parse_qs(parsed.query)['id'][0])
		
		DBSession = Session(bind=engine)
		user = DBSession.query(User).filter(User.login == login).one()

		friendrequest = DBSession.query(Friendrequest).filter(and_(Friendrequest.user_to_id == user.id,Friendrequest.user_from_id == friendid)).all()
			
		#принимаем заявку в друзья
		if (len(friendrequest) > 0):							

			messageFile = "{0}-{1}.txt".format(user.id, friendid)
			messageLocPath =  "socialnetwork/static/" +messageFile
			with open(messageLocPath,'w') as f:
				f.write('')
			
			friendship = Friendship(user_from_id = friendid, user_to_id = user.id, dialogLocPath = messageLocPath)
			DBSession.add(friendship)				
			DBSession.delete(friendrequest[0])
			DBSession.commit()			
		
		else:	
			#запрос от текущего аккаунта выбранному пользователю			
			friendrequest = DBSession.query(Friendrequest).filter(and_(Friendrequest.user_to_id == friendid,Friendrequest.user_from_id == user.id)).all()				
			#добавление, если нет еще запроса
			if (len(friendrequest) == 0 ):
				friendrequest = Friendrequest(user_from_id = user.id, user_to_id = friendid)
				DBSession.add(friendrequest)	
				DBSession.commit()
		
		return HTTPFound(location=request.referer)
    	return HTTPFound(location='/')
开发者ID:Dizrax,项目名称:SocialNetwork,代码行数:37,代码来源:views.py

示例3: removefriend

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
def removefriend(request):
    	login = authenticated_userid(request)		
	if(login!= None):		
		parsed = urlparse.urlparse(request.referer)
		friendId = int(urlparse.parse_qs(parsed.query)['id'][0])
		DBSession = Session(bind=engine)
		user = DBSession.query(User).filter(User.login == login).one()
		friendship = DBSession.query(Friendship).filter(or_(and_(Friendship.user_to_id==user.id, Friendship.user_from_id==friendId),and_(Friendship.user_to_id==friendId, Friendship.user_from_id==user.id))).one()
		DBSession.delete(friendship)
		DBSession.commit()	
		return HTTPFound(location=request.referer)
    	return HTTPFound(location='/')
开发者ID:Dizrax,项目名称:SocialNetwork,代码行数:14,代码来源:views.py

示例4: signout

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
def signout():
    sid = request.get_cookie('sid', None)

    if sid:
        response.delete_cookie('sid')
        response.delete_cookie('username')
        query = Session.delete().where(Session.sid == sid)
        query.execute()
开发者ID:kmasaya,项目名称:lopet,代码行数:10,代码来源:views.py

示例5: signout

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
    def signout():
        site_id = request.get_cookie('site_id', None)

        response.delete_cookie('site_id')
        response.delete_cookie('username')

        if site_id is not None:
            query = SessionModel.delete().where(SessionModel.site_id == site_id)
            query.execute()
开发者ID:kmasaya,项目名称:bottle.peewee.template,代码行数:11,代码来源:Session.py

示例6: delete_session

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
def delete_session(sid):
    Session.delete().where(Session.key==sid).execute()
开发者ID:passiomatic,项目名称:coldsweat,代码行数:4,代码来源:session.py

示例7: response

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
 def response(self):
     dbsession = Session()
     dbsession.delete(self.article)
     dbsession.commit()
     dbsession.close()
     return Response(status=302, location='/blog/')
开发者ID:IYism,项目名称:lectures.www,代码行数:8,代码来源:views.py

示例8: __init__

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
class GenericService:
    """
    Service générique permettant de manipuler
    les modèles en base plus simplement.
    """
    __modelClass__ = None

    def __init__(self):
        """
        Constructeur
        :return:
        """
        self.session = None

    def newSession(self):
        """
        Renouvelle la session du service
        :return:
        """
        if self.session is not None:
            self.session.close()
        else:
            self.session = Session()

    def all(self):
        """
        Récupère tous les enregitrements
        :return: list
        """
        self.newSession()
        return self.session.query(self.__modelClass__).all()

    def find(self, id):
        """
        Récupère un enregistrement
        :param id: id de l'enregistrement
        :return: object
        """
        self.newSession()
        return self.session.query(self.__modelClass__).get(id)

    def delete(self, id):
        """
        Supprime un enregistrement en base
        :param id: id de l'enregistrement
        :return: void
        """
        self.newSession()
        obj = self.session.query(self.__modelClass__).get(id)
        self.session.delete(obj)
        self.session.commit()
        self.session.flush()

    def save(self, obj):
        """
        Crée ou met à jour un enregistrement en base
        :param obj: l'objet à sauvegarder
        :return: void
        """
        self.newSession()
        self.session.add(obj)
        self.session.commit()
        self.session.flush()

    def __del__(self):
        """
        Ferme la session à la destruction de la classe
        :return:
        """
        self.session.close()
开发者ID:MarvinDurot,项目名称:travel_manager,代码行数:72,代码来源:services.py

示例9: removeHandler

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import delete [as 别名]
 def removeHandler(self):
     user = self.context
     Session.delete(user)
     self.message("User has been removed.")
     raise HTTPFound(location='../index.html')
开发者ID:nerdfiles,项目名称:ploud-prod,代码行数:7,代码来源:manage.py


注:本文中的models.Session.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。