本文整理汇总了Python中models.User.delete方法的典型用法代码示例。如果您正苦于以下问题:Python User.delete方法的具体用法?Python User.delete怎么用?Python User.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestModels
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
class TestModels(unittest.TestCase):
def setUp(self):
User.objects.delete({'email':'[email protected]'})
self.user = User(email='[email protected]', password='test')
self.user.save()
GPSDevice.objects.delete({'imei':'test'})
self.device = GPSDevice(imei='test')
self.device.save()
self.user.devices.append(self.device)
self.user.save()
def tearDown(self):
self.user.delete()
self.device.delete()
# User
def test_user(self):
assert(self.user.check_password('test'))
# GPSDevice
def test_device_user(self):
assert(self.user==self.device.user)
def test_unique_imei(self):
try:
d = GPSDevice(imei='test')
d.save()
except mongoengine.NotUniqueError, e:
pass
assert(mongoengine.NotUniqueError == type(e))
示例2: deleteUser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def deleteUser():
if not current_user.isAdmin():
flash(constants.NOT_ALLOWED, 'danger')
else:
userid = unicode(request.form['userid'])
user = User.get(userid)
User.delete(user)
flash(constants.USER_DELETE_SUCCESS.format(user.username), 'success')
return redirect(url_for('manageUsers'))
示例3: delete_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def delete_user(username):
if username == "admin":
activity.logger.error(
"'{}' user request for delete 'admin' user. Delete 'admin' user event fail.".format(
g.user.username
)
)
return jsonify(status="error", message="Admin can't be deleted"), 403
User.delete(username)
activity.logger.info(
"'{}' user deleted by '{}' user.".format(username, g.user.username)
)
return jsonify(status="success")
示例4: delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def delete(self,id):
if not current_user.is_admin() and current_user.id != id:
abort(401)
if User.count() <= 1:
abort(403)
user = User.get_by_id(id)
try:
if user is None:
raise Exception(gettext('User not found'))
name = user.name
User.delete(user.id)
flash(gettext('The user "%(name)s" was removed', name=name))
except:
flash(gettext('Error while removing the user'), 'error')
if request.method == 'POST':
return redirect(url_for('UsersView:index'))
return jsonify(redirect_to=url_for('UsersView:index'))
示例5: FollowFuncTestCase
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
class FollowFuncTestCase(TestCase):
def setUp(self):
self.u1 = User(
email=forgery_py.internet.email_address(),
username=forgery_py.internet.user_name(),
password=forgery_py.lorem_ipsum.word())
self.u1.save()
self.u2 = User(
email=forgery_py.internet.email_address(),
username=forgery_py.internet.user_name(),
password=forgery_py.lorem_ipsum.word())
self.u2.save()
def tearDown(self):
self.u1.delete()
self.u2.delete()
def test_get_all(self):
self.assertEqual(0, len(self.u1.follower.all()))
self.assertEqual(0, len(self.u2.follower.all()))
self.u1.follow(self.u2)
self.assertEqual(1, len(self.u1.follower.all()))
def test_is_following(self):
self.assertFalse(self.u1.is_following(self.u2))
def test_follow(self):
self.u1.follow(self.u2)
self.assertTrue(self.u1.is_following(self.u2))
def test_is_followed_by(self):
self.u1.follow(self.u2)
self.assertTrue(self.u2.is_followed_by(self.u1))
def test_unfollow(self):
self.assertFalse(self.u1.is_following(self.u2))
self.u1.follow(self.u2)
self.assertTrue(self.u1.is_following(self.u2))
self.assertTrue(self.u2.is_followed_by(self.u1))
self.u1.unfollow(self.u2)
self.assertFalse(self.u1.is_following(self.u2))
self.assertFalse(self.u2.is_followed_by(self.u1))
示例6: test_create_user_no_duplicate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def test_create_user_no_duplicate(self):
"""Makes sure users can't have the same username and email."""
Role.create(role_name='tester')
create_user('Tester', 'test', '0000000000', 'tester', 'ttest', 'testing', '[email protected]')
from peewee import IntegrityError
with self.assertRaises(IntegrityError):
create_user('Tester', 'test', '0000000000', 'tester', 'ttest', 'testing', '[email protected]')
delete_user = User.delete().where(User.username == 'ttest')
delete_user.execute()
delete_role = Role.delete().where(Role.role_name == 'tester')
delete_role.execute()
示例7: delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def delete(user_id):
#delete_form = request.form
current_app.logger.info(request.form)
if user_id == 0:
return
user_obj = User()
result = user_obj.delete(user_id)
if not result:
return
return redirect('/user/index')
示例8: management_handle
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def management_handle():
if request.method == 'POST':
return makepublic._makepublic()#?????????
elif request.method == 'GET':
if request.args.get('Delete',type=str)=='Delete':#删除某个加分项
itemID=request.args.get('itemID',type=int)
Score_items.delete(itemID)
return " "
elif request.args.get('Delete',type=str)=='DeleteStu':#删除学生
campID=request.args.get('campID',type=str)
User.delete(campID)
return " "
elif request.args.get('Edit',type=str)=='Edit':#编辑
id=request.args.get('id',type=str)
name=request.args.get('edit_name',type=unicode)
campID=request.args.get('edit_campID',type=str)
grade=request.args.get('edit_grade',type=unicode)
studentID=request.args.get('edit_studentID',type=str)
return User.edit(id,campID,name,grade,studentID)
elif request.args.get('Add',type=str)=='Add':#添加学生
name=request.args.get('add_name',type=unicode)
campID=request.args.get('add_campID',type=str)
grade=request.args.get('add_grade',type=unicode)
studentID=request.args.get('add_studentID',type=str)
user=User.get_user(campID)
if user:
return u"一卡通号重复"
else :
User.addstudent(campID,name,grade,addstudent)
return u"添加成功"
elif request.args.get('action',type=str)=='resetpw':
campID=request.args.get('campID',type=str)
user=User.get_user(campID)
try:
user.password=user.campID
db.session.commit()
return u"重置成功"
except StandardError,e:
return u"未知错误"
示例9: test_create_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def test_create_user(self):
"""Create an user."""
Role.create(role_name='tester')
create_user('Tester', 'test', '0000000000', 'tester', 'ttest', 'testing', '[email protected]')
user = User.select().where(User.username == 'ttest')
delete_user = User.delete().where(User.username == 'ttest')
delete_user.execute()
delete_role = Role.delete().where(Role.role_name == 'tester')
delete_role.execute()
self.assertEqual(str(user), ("<class 'models.User'> SELECT `t1`.`id`, `t1`.`first_name`,"
" `t1`.`second_name`, `t1`.`phone`, `t1`.`role_id`,"
" `t1`.`username`, `t1`.`password`, `t1`.`email` FROM `user`"
" AS t1 WHERE (`t1`.`username` = %s) ['ttest']"))
示例10: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def get(self):
user_key = self.request.get('user_key')
try:
# Add the new user to the database
user_key = User.delete(user_key)
# Respond with the user key
self.response.set_status(201)
self.response.write(user_key)
except Exception as e:
# Respond with the error
self.response.set_status(406)
self.response.write(str(e))
示例11: users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def users(request):
was_limited = getattr(request, 'limited', False)
if was_limited:
return JsonResponse(
{
'status': 'you hit the rate limit!'
}
)
else:
if request.method == 'GET':
token = request.GET.get('token')
print token
user_id = User.verify_auth_token(token)
if user_id:
all_users = User.objects.all()
data = []
for user in all_users:
item = {
'username': user.username,
'picture': str(user.picture),
'email': user.email
}
data.append(item)
return JsonResponse(
{
'users': data
}
)
else:
return HttpResponseForbidden('invalid token')
elif request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = User.objects.filter(username=username)
if not user:
user = User(username=username, password=password)
user.save()
logger.info('username ' + username + ' created')
return JsonResponse(
{
'status': 'user created successfully',
'object':
{
'username': user.username,
'picture': str(user.picture),
'email': user.email
}
}
)
else:
return JsonResponse(
{
'status': 'user already exist!',
'object':
{
'username': user.username,
'picture': str(user.picture),
'email': user.email
}
}
)
elif request.method == 'PUT':
raw_data = request.body
data = raw_data.json()
token = data['token']
profile_data = data['profile']
user_id_login = User.verify_auth_token(token)
if user_id_login:
user = User.objects.filter(id=user_id_login).first()
if user:
user.username = profile_data['username']
user.picture = profile_data['picture']
user.save()
# logger.info('user ' + user_id_login + ' profile updated successfully!')
return JsonResponse(
{
'status': 'update successfully',
'object':
{
'username': user.username,
'picture': str(user.picture),
'email': user.email
}
}
)
else:
return JsonResponse({'status': 'update operation failed'})
else:
return HttpResponseForbidden('invalid token')
elif request.method == 'DELETE':
raw_data = request.body
data = raw_data.json()
token = data['token']
user_id = User.verify_auth_token(token)
if user_id:
user = User.objects.filter(id=user_id).first()
user.delete()
else:
return HttpResponseForbidden('invalid token')
示例12: m_user_delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def m_user_delete():
uid = request.form.get('uid')
User.delete(uid)
return redirect(request.referrer)
示例13: response_msg
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def response_msg(request):
raw_str = smart_str(request.raw_post_data)
print raw_str
msg = parse_xml(ET.fromstring(raw_str))
msg_type = msg.get('MsgType', '')
from_user_name = msg.get('FromUserName')
to_user_name = msg.get('ToUserName')
content = ''
print('MsgType ' + msg_type)
if msg_type == 'event':
event_type = msg.get('Event', '')
print('new event: ' + event_type)
if event_type == 'subscribe':
content = '欢迎关注要记账\n1.创建账本\n2.增加记录\n3.查询\n4.导出账单\n5.帮助\n6.删除账号并清空数据\n7.反馈'
return get_reply_xml(from_user_name, to_user_name, content)
elif msg_type == 'text':
content = msg.get('Content', '')
print('content: ' + content)
if mc.get(from_user_name + 'del') == '22':
if content == 'c' or content == 'C':
record_stamp = mc.get(from_user_name + 'ds')
u1 = User.objects.get(user=from_user_name)
pb = PayBooks.objects.filter(user=u1, stamp=record_stamp)
pb[0].delete()
content = '撤销成功'
return get_reply_xml(from_user_name, to_user_name, content)
# if op_sql.revoke_insert(from_user_name):
# content = '撤销成功'
# else:
# content = '撤销失败'
# mc.delete(from_user_name + 'del')
# return reply_server(from_user_name, to_user_name, content)
if mc.get(from_user_name) == '1':
print(mc.get(from_user_name) + ' name')
u1 = User.objects.filter(user=from_user_name)
if len(u1) == 0:
print('create user but not exist')
u1 = User(user=from_user_name, pwd=content)
u1.save()
content = '创建成功,此密码可以用来提取账单,如果你不幸忘记密码,请在反馈中联系[要记账]'
mc.delete(from_user_name)
else:
print('create user failed exist')
content = '创建失败,用户已经创建过密码'
mc.delete(from_user_name)
return get_reply_xml(from_user_name, to_user_name, content)
# if op_sql.create(from_user_name, content):
# content = '创建成功,此密码未来可以提取账单到电脑'
# logging.debug(content + ' enter if op_sql')
# mc.delete(from_user_name)
# else:
# content = '创建失败,用户已经创建过密码'
# mc.delete(from_user_name)
elif mc.get(from_user_name) == '2':
print(mc.get(from_user_name) + ' enter 2 content' + content)
#logging.debug('show content : ' + content)
tmp = content.split(' ')
if not is_number(tmp[0]):
content = '输入有误\n!格式不正确\n!金额不能为负数\n!用空格分隔\n请重新输入'
return get_reply_xml(from_user_name, to_user_name, content)
if len(tmp) == 2 and float(tmp[0]) > 0:
user_tmp = User.objects.filter(user=from_user_name)
if len(user_tmp) != 0:
record_time = time.strftime('%m%d%H%M%S')
pb = PayBooks(user=user_tmp[0],
money=tmp[0],
month=time.strftime('%m'),
year=time.strftime('%Y'),
remark=tmp[1],
stamp=record_time
)
pb.save()
content = '数据记录成功\n在3分钟内回复c\n可以撤销刚才数据'
mc.delete(from_user_name)
mc.set(from_user_name + 'ds', record_time, 300)
# if user want to revoke the previous opration
mc.set(from_user_name + 'del', '22', 180)
else:
print('insert error money format')
content = '数据记录失败,格式不对吧?还是没创建账户?'
mc.delete(from_user_name)
# if op_sql.insert(from_user_name, tmp[0], tmp[1]):
# logging.debug('insert enter')
# content = '数据记录成功\n在3分钟内回复c\n可以撤销刚才数据'
# mc.delete(from_user_name)
# # if user want to revoke the previous opration
# mc.set(from_user_name + 'del', '22', 180)
# else:
# logging.debug('insert error money')
# content = '数据记录失败,格式不对吧?还是没创建账户?'
# mc.delete(from_user_name)
else:
content = '输入有误\n!格式不正确\n!金额不能为负数\n!用空格分隔\n请重新输入'
return get_reply_xml(from_user_name, to_user_name, content)
elif mc.get(from_user_name) == '3':
'''高级查询
#.........这里部分代码省略.........
示例14: tg_einladung_new_form
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
def tg_einladung_new_form(request, tg_id):
def return_empty_form():
context = {}
form = TG_Einladung_createForm(tg=tg, user=request.user.user)
context["news"] = get_news_by_request(request)
context["form"] = form
return render(request, 'tippgemeinschaft/einladung_create.html', context)
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse("home"))
try:
tg = Tippgemeinschaft.objects.get(pk = tg_id)
except:
return HttpResponseRedirect(reverse("home"))
if request.method == 'POST':
fuer = request.POST["fuer-autocomplete"]
# 2 cases: valid user, or email address
# case 1, user
if "user_select" in request.POST.keys():
user_select_id = request.POST["user_select"]
# case 2, email:
elif string.count(fuer, '@') == 1:
new_user = User()
new_user.username = fuer
new_user.first_name = string.split(fuer, '@')[0]
new_user.email = fuer
new_user.is_active = False
new_user.save()
user_select_id = new_user.id
else:
messages.warning(request, "User nicht gefunden, oder ungültige eMail-Adresse!")
return return_empty_form()
tg_e = TG_Einladung()
form = TG_Einladung_createForm(request.POST, instance = tg_e, tg=tg, user=request.user.user)
if form.is_valid():
tg_e.key = uuid.uuid4()
tg_e.tg = tg
tg_e.von = request.user.user
tg_e.fuer_id = user_select_id
try:
form.save()
except IntegrityError:
messages.warning(request, "Bereits eine Einladung an diesen User verschickt!")
return return_empty_form()
#mail schicken
von = tg_e.von.first_name if tg_e.von.first_name else tg_e.von.username
fuer = tg_e.fuer.first_name if tg_e.fuer.first_name else tg_e.fuer.username
args = (unicode(fuer), unicode(von), unicode(tg.bezeichner), unicode(tg.beschreibung), "http://"+request.get_host()+reverse("acc_tg_einladung", args=[tg_e.key]), "http://"+request.get_host()+reverse("del_tg_einladung", args=[tg_e.key]), )
try:
mail.send(TGE_SUBJECT % unicode(tg.bezeichner),
tg_e.fuer.email,
TGE_MSG % args,
TGE_MSG_HTML % args)
except SMTPRecipientsRefused:
tg_e.delete()
if new_user:
new_user.delete()
messages.warning(request, "Ungültige eMail-Adresse!")
return return_empty_form()
messages.success(request, "Erfolgreich eingeladen!")
return HttpResponseRedirect(reverse("show_tippgemeinschaft", args=[tg.id]))
else:
return return_empty_form()
示例15: User
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import delete [as 别名]
# -*- coding: utf-8 -*-
__author__ = 'fang'
from models import User, Blog, Comment
from transwarp import db
db.create_engine(user='root', password='password',database='awesome')
u = User(name='Administrato', email='[email protected]', password='1234567890', image='about:blank')
u.insert()
print 'new user:', u
u.delete()
b1 = Blog(user_id='0014347129972910bbdee0a188f412394d92e5e5a299939000', user_name='Administrator',
name = 'FirstBlog', summary='Test', content = 'Test.')
b1.insert()
print 'new blog:', b1
b1.delete()
'''
u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name
u2 = User.find_first('where email=?', '[email protected]')
print 'find user:', u2