本文整理汇总了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)
示例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='/')
示例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='/')
示例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()
示例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()
示例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()
示例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/')
示例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()
示例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')