本文整理汇总了Python中quizsmith.app.models.DBSession.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.delete方法的具体用法?Python DBSession.delete怎么用?Python DBSession.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quizsmith.app.models.DBSession
的用法示例。
在下文中一共展示了DBSession.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import delete [as 别名]
def tearDown(self):
user = Users.by({'email':'[email protected]'}).first()
DBSession.delete(user)
DBSession.flush()
DBSession.execute("ALTER TABLE users AUTO_INCREMENT = " + str(self.auto_increment_reset) + ";")
transaction.commit()
super(NoGroupPermissionTests,self).tearDown()
示例2: edit_delete
# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import delete [as 别名]
def edit_delete(self):
id = self.request.matchdict['id']
classname = str(self.request.matchdict['type'])
back = self.request.params.get('back',None)
if back == None or not back.startswith(self.request.application_url):
return HTTPFound(location=self.request.application_url)
type = Import('quizsmith.app.models',str(classname))
obj = DBSession.query(type).filter(type.id==id).first()
if obj:
DBSession.delete(obj)
DBSession.flush()
transaction.commit() # make it so number one
return HTTPFound(location=self.request.params['back'])
示例3: edit_groups
# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import delete [as 别名]
def edit_groups(self):
self.response['email'] = self.request.params.get('edit.find.user','')
self.response['user'] = Users.by({'email':self.response['email']}).first()
self.response['editing_group'] = None
# add/remove users from groups
if 'edit.user.group.add.submit' in self.request.params:
id = self.request.params.get('edit.user.group.add','')
group = Groups.by(id).first()
self.response['user'].groups.append(Groups.by(id).first())
transaction.commit()
self.response['message'] = "Added user to group"
self.response['message_class'] = "info"
self.response['editing_group'] = Groups.by(id).first()
self.response['user'] = Users.by({'email':self.response['email']}).first()
if 'edit.user.group.remove.submit' in self.request.params:
id = self.request.params.get('edit.user.group.remove','')
self.response['user'].groups.remove(Groups.by(id).first())
transaction.commit()
self.response['message'] = "Removed user from group"
self.response['message_class'] = "info"
self.response['user'] = Users.by({'email':self.response['email']}).first()
if 'edit.group.find.submit' in self.request.params:
id = self.request.params.get('edit.group.find','')
self.response['editing_group'] = Groups.by(id).first()
if 'edit.group.edit.submit' in self.request.params:
id = self.request.params.get('edit.group.edit.id','')
group = Groups.by(id).first()
group.name = self.request.params.get('edit.group.edit.name','No name')
group.description = self.request.params.get('edit.group.edit.description','No Description')
group.play = Validate.bool(self.request.params.get('edit.group.edit.play', False))
group.edit = Validate.bool(self.request.params.get('edit.group.edit.edit', False))
group.review = Validate.bool(self.request.params.get('edit.group.edit.review', False))
cats = []
for cid in self.request.params.getall('edit.group.edit.categories'):
cats.append(Categories.by(int(cid)).first())
group.categories = cats
transaction.commit()
self.response['editing_group'] = Groups.by(id).first()
self.response['message'] = "Edit successful"
self.response['message_class'] = "info"
if 'edit.group.new.submit' in self.request.params:
i = Groups.newest().id + 1
DBSession.add(Groups(name='New Group' + str(i)))
transaction.commit()
self.response['editing_group'] = Groups.newest()
self.response['message'] = "Added new group"
self.response['message_class'] = "info"
if 'edit.group.delete.submit' in self.request.params:
id = int(self.request.params.get('edit.group.find','0'))
if id not in [1,2,3]:
try:
group = Groups.by(id).first()
DBSession.delete(group)
transaction.commit()
self.response['message'] = "Deleted group"
self.response['message_class'] = "info"
except exc.SQLAlchemyError:
self.response['message'] = "You can't delete this group. It has user and category dependencies."
else:
self.response['message'] = "You can't delete this permanent group"
self.response['groups'] = Groups.all()
self.response['categories'] = Categories.all()
return self.template('/edit-groups.pt', theme='AdminPanel')
示例4: edit_groups
# 需要导入模块: from quizsmith.app.models import DBSession [as 别名]
# 或者: from quizsmith.app.models.DBSession import delete [as 别名]
def edit_groups(self):
lookup = self.request.params.get('edit.user.find','')
self.response['email'] = self.request.params.get('edit.user.find.email','')
self.response['user'] = Users.by({'email':self.response['email']}).first()
if self.response['user'] and lookup:
self.notify('User found')
if self.response['email'] and not self.response['user'] and lookup:
self.notify('No user found',warn=True)
self.response['editing_group'] = None
# add/remove users from groups
if 'edit.user.group.add.submit' in self.request.params:
id = self.request.params.get('edit.user.group.add','')
group = Groups.by(id).first()
self.response['user'].groups.append(Groups.by(id).first())
transaction.commit()
self.notify('Added user to group')
self.response['editing_group'] = Groups.by(id).first()
self.response['user'] = Users.by({'email':self.response['email']}).first()
if 'edit.user.group.remove.submit' in self.request.params:
id = self.request.params.get('edit.user.group.remove','')
self.response['user'].groups.remove(Groups.by(id).first())
transaction.commit()
self.notify('Removed user from group')
self.response['user'] = Users.by({'email':self.response['email']}).first()
if 'edit.group.find.submit' in self.request.params:
id = self.request.params.get('edit.group.find','')
self.response['editing_group'] = Groups.by(id).first()
if 'edit.group.edit.submit' in self.request.params:
id = self.request.params.get('edit.group.edit.id','')
group = Groups.by(id).first()
group.name = self.request.params.get('edit.group.edit.name','No name')
group.description = self.request.params.get('edit.group.edit.description','No Description')
group.play = Validate.bool(self.request.params.get('edit.group.edit.play', False))
group.edit = Validate.bool(self.request.params.get('edit.group.edit.edit', False))
group.review = Validate.bool(self.request.params.get('edit.group.edit.review', False))
cats = []
for cid in self.request.params.getall('edit.group.edit.categories'):
cats.append(Categories.by(int(cid)).first())
group.categories = cats
transaction.commit()
self.response['editing_group'] = Groups.by(id).first()
self.notify('Changes saved!')
if 'edit.group.new.submit' in self.request.params:
i = Groups.newest().id + 1
DBSession.add(Groups(name='New Group' + str(i)))
transaction.commit()
self.response['editing_group'] = Groups.newest()
self.notify('Added group!')
if 'edit.group.delete.submit' in self.request.params:
id = int(self.request.params.get('edit.group.find','0'))
if id not in [1,2,3]:
try:
group = Groups.by(id).first()
DBSession.delete(group)
transaction.commit()
self.notify('Removed group!')
except exc.SQLAlchemyError:
self.notify("You can't delete this group. It has user and category dependencies.",warn=True)
else:
self.notify("Can't remove permanent group!",warn=True)
self.response['groups'] = Groups.all()
self.response['categories'] = Categories.all()
return self.template('/edit-groups.pt', theme='AdminPanel')