本文整理汇总了Python中core.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.User
的用法示例。
在下文中一共展示了User.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def authenticate(self, saml_authentication=None):
if not saml_authentication: # Using another authentication method
return None
if saml_authentication.is_authenticated():
attributes = saml_authentication.get_attributes()
user_changed = False
try:
user = User.objects.get(username=saml_authentication.get_attributes()['uid'][0])
except User.DoesNotExist:
user = User(username=saml_authentication.get_attributes()['uid'][0])
user.set_unusable_password()
user.username = attributes['uid'][0]
map_fields = {
'realname': 'cn',
'email': 'mail'
}
# ensure realname for users from webid don't contain unverified note
if 'cn' in attributes:
attributes['cn'][0] = attributes['cn'][0].replace(' (unverified)', '')
for field, samlfield in map_fields.items():
if getattr(user, field) != attributes[samlfield][0]:
setattr(user, field, attributes[samlfield][0])
user_changed = True
if user_changed:
user.save()
return user
return None
示例2: ajax_sale_add
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def ajax_sale_add(request):
r_client = request.POST.get('client')
r_task = request.POST.get('task')
r_email = request.POST.get('email')
r_password = request.POST.get('password')
client = Client.objects.get(pk=int(r_client))
task = Task.objects.get(pk=int(r_task))
try:
User.objects.get(email=r_email)
except User.DoesNotExist:
user = User(email=r_email, password=r_password, type=User.UserType.client)
user.set_password(r_password)
user.save()
sale = Sale(
user=user,
city=client.city,
manager=client.manager,
moderator=client.moderator,
legal_name=client.name,
actual_name=client.name,
legal_address=client.actual_address,
password=r_password
)
sale.save()
task.status = 1
task.save()
return HttpResponseRedirect(reverse('sale:update', args=(sale.id, )))
return_url = reverse('client:task-list') + '?error=1'
return HttpResponseRedirect(return_url)
示例3: test_helper_no_profile
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def test_helper_no_profile(self):
u = User()
u.first_name = "John"
u.last_name = "Smith"
u.save()
self.assertEquals(False, helpers.user_has_profile(u))
p = Person()
p.user = u
p.save()
self.assertEquals(True, helpers.user_has_profile(u))
示例4: add_user
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def add_user(auth, fields):
user = authenticate(username=auth.get('username'),
password=auth.get('password'))
auth['tenant'] = user.site.login_base
sites = _get_sites(fields.get('site'))
if sites: fields['site'] = sites[0]
user = User(**fields)
user.os_manager = OpenStackManager(auth=auth, caller = user)
user.save()
return user
示例5: UserRegHandler
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def UserRegHandler(request):
NewAccount = Account()
NewAccount.username = request.POST['username'].encode('utf-8')
NewAccount.password = request.POST['password'].encode('utf-8')
NewAccount.urtype = request.POST['urtype'].encode('utf-8')
NewAccount.created = datetime.now()
NewUser = User()
NewUser.name = request.POST['name'].encode('utf-8')
NewUser.mobile = request.POST['mobile'].encode('utf-8')
# NewUser.address = request.POST['address'].encode('utf-8')
NewUser.save()
NewAccount.urid = NewUser.id
NewAccount.save()
return HttpResponse(NewAccount.id)
示例6: create
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def create(self):
xos_args = self.get_xos_args()
if not xos_args.get("site",None):
raise Exception("Site name must be specified when creating user")
if ("firstname" not in xos_args) or ("lastname" not in xos_args):
raise Exception("firstname and lastname must be specified when creating user")
user = User(**xos_args)
user.save()
self.postprocess(user)
self.info("Created User '%s'" % (str(user), ))
示例7: create
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def create(self):
nodetemplate = self.nodetemplate
xos_args = self.get_xos_args()
if not xos_args.get("site",None):
raise Exception("Site name must be specified when creating user")
user = User(**xos_args)
user.save()
self.postprocess(user)
self.info("Created User '%s'" % (str(user), ))
示例8: facebook_connect
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def facebook_connect(user_data):
try:
# Logging in with Facebook
user = User.objects.get(facebook_id=user_data['id'])
user.tz_offset = user_data['timezone']
user.save()
except User.DoesNotExist:
# Creating new account with Facebook
user = User()
user.email = user_data['email']
user.facebook_id = user_data['id']
user.tz_offset = user_data['timezone']
user.set_password(random_string())
user.save()
return user
示例9: test_call_register_channel
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def test_call_register_channel(self):
'''
Test registration to a channel
'''
u = User()
u.username = "sample_post"
u.first_name = "sample_post"
u.email = "[email protected]"
u.set_password("123")
u.save()
ch1 = Channel()
ch1.owner = u
ch1.name = "PostSub"
ch1.image = 'http://www.google.com'
ch1.description = "A channel description"
ch1.kind = PUBLIC
ch1.hidden = False
ch1.subscriptions = 0
ch1.save()
sub1 = Subscriber()
sub1.sub_type = 'type2'
sub1.token = 'token2'
sub1.device_id = 'devid5'
sub1.save()
resp = ask_subscribe_channel(ch1, sub1.device_id)
self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
self.client.login(username='test_user', password='password')
data = {
'channel' : ch1.name,
'token' : sub1.token,
'browser' : 'chrome',
'device_id' : sub1.device_id
}
response = self.client.post(reverse('browser-registration'), json.dumps(data), sub1.token)
self.assertTrue(response.status_code, 200)
示例10: test_call_delete
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def test_call_delete(self):
'''
Test deleting of a registration of a device from a channel
'''
u = User()
u.username = "sample_del"
u.first_name = "sample_del"
u.email = "[email protected]"
u.set_password("123")
u.save()
ch1 = Channel()
ch1.owner = u
ch1.name = "DelSub"
ch1.image = 'http://www.google.com'
ch1.description = "A channel description"
ch1.kind = PUBLIC
ch1.hidden = False
ch1.subscriptions = 0
ch1.save()
sub1 = Subscriber()
sub1.sub_type = 'type2'
sub1.token = 'token2'
sub1.device_id = 'devid6'
sub1.save()
resp = ask_subscribe_channel(ch1, sub1.device_id)
self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
self.client.login(username='test_user', password='password')
response = self.client.delete(reverse('browser-get-registration', kwargs={'device_id': sub1.device_id,
'channel_name' : ch1.name}))
self.assertEqual(response.status_code, 200)
channels = SubscriberManager().get_device_subscriptions(sub1.device_id)
sub_channel = next((x for x in channels if x == ch1.name.lower()), None)
self.assertIsNone(sub_channel)
示例11: get_all_users
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def get_all_users(request):
response_auth = requests.post('http://oll.tv/ispAPI/auth2/', data={
'login': 'mtel',
'password': 'x_g~-5~(;ZY'
})
response_content = response_auth.json()
#print response_content
response_get_user_list = requests.post('http://oll.tv/ispAPI/getUserList/', data={
'offset': '',
'hash': response_content['hash']
})
get_user_list_json = response_get_user_list.json()
get_user_list = get_user_list_json['data']
num = 0
for i in get_user_list:
num = num + 1
u = User(email=i['email'], account=i['account'], birth_date=i['birth_date'], gender=i['gender'], firstname=i['firstname'], lastname=i['lastname'], phone=i['phone'], region=i['region'], receive_news=i['receive_news'], index=['index'], status=i['active'], registration_date=i['reg_date'], oll_id=i['ID'])
u.save()
return render(request, 'olltv/get_all_users.html', locals())
示例12: api_user_register
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def api_user_register(request):
benchmark_start = time.time()
response = prepare_response(request)
status = 200
form = UserRegisterForm(request.POST)
errors = get_validation_errors(form)
if form.is_valid():
data = form.cleaned_data
new_user = User(email=data['email'])
new_user.set_password(data['password'])
new_user.save()
response['new_user_id'] = new_user.id
status = 201
else:
response['errors'] = errors
status = 400
response['meta']['status'] = status
benchmark_end = time.time()
response['meta']['execution_time'] = benchmark_end - benchmark_start
return build_response(response, status=status)
示例13: post
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def post(self):
login = self.get_argument("login")
password = self.get_argument("password")
password_confirm = self.get_argument("password_confirm")
if len(password) >= 4 and (password == password_confirm):
users = yield User.find(login=login)
if len(users):
self.write_error(500, "Already exist")
return
user = User(login=login)
user.set_password(new_password=password)
user.save()
self.set_secure_cookie("user", login)
self.get_user_from_cookies = lambda : login
session = self.project_session
session['current_user'] = user
session.save()
self.redirect("/")
else:
self.write_error(500, 'Incorrect password')
示例14: test_call_get
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
def test_call_get(self):
'''
Test check if a device is registered to a channel
'''
u = User()
u.username = "sample_un"
u.first_name = "Sample_un"
u.email = "[email protected]"
u.set_password("123")
u.save()
ch1 = Channel()
ch1.owner = u
ch1.name = "GetSub"
ch1.image = 'http://www.google.com'
ch1.description = "A channel description"
ch1.kind = PUBLIC
ch1.hidden = False
ch1.subscriptions = 0
ch1.save()
sub1 = Subscriber()
sub1.sub_type = 'type2'
sub1.token = 'token2'
sub1.device_id = 'devid4'
sub1.save()
resp = ask_subscribe_channel(ch1, 'devid4')
self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
self.client.login(username='test_user', password='password')
response = self.client.get(reverse('browser-get-registration', kwargs={'device_id': 'devid4', 'channel_name' : 'GetSub'}) )
self.assertTrue(response.status_code, 200)
示例15: UserModelTest
# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save [as 别名]
class UserModelTest(TestCase):
def setUp(self):
self.user = User(
name='Michael',
email='[email protected]',
password='123'
)
def test_user_creation(self):
"""
user creation
"""
self.user.save()
self.assertEqual(1, self.user.pk)
def test_user_unicode(self):
"""
unicode
"""
self.user.save()
self.assertEqual(self.user.__unicode__(), 'Michael - [email protected]')