本文整理汇总了Python中registration.users.UserModel类的典型用法代码示例。如果您正苦于以下问题:Python UserModel类的具体用法?Python UserModel怎么用?Python UserModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_email
def clean_email(self):
existing = UserModel().objects.filter(email__iexact=self.cleaned_data['email'])
if existing.exists():
raise forms.ValidationError(_("A user with that email already exists."))
else:
return self.cleaned_data['email']
示例2: create_inactive_user
def create_inactive_user(self, username, email, password,
site, send_email=True, request=None):
"""
Create a new, inactive ``User``, generate a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.
By default, an activation email will be sent to the new
user. To disable this, pass ``send_email=False``.
Additionally, if email is sent and ``request`` is supplied,
it will be passed to the email template.
"""
new_user = UserModel().objects.create_user(username, email, password)
new_user.is_active = False
new_user.save()
registration_profile = self.create_profile(new_user)
#send_email = False
if send_email:
registration_profile.send_activation_email(site, request)
return new_user
示例3: test_approval
def test_approval(self):
"""
Approval of an account functions properly.
"""
resp = self.client.post(reverse('registration_register'),
data={'username': 'bob',
'email': '[email protected]',
'password1': 'secret',
'password2': 'secret'})
profile = self.registration_profile.objects.get(user__username='bob')
resp = self.client.get(
reverse('registration_activate',
args=(),
kwargs={'activation_key': profile.activation_key}))
admin_user = UserModel().objects.create_superuser('admin', '[email protected]', 'admin')
self.client.login(username=admin_user.get_username(), password=admin_user)
resp = self.client.get(
reverse('registration_admin_approve',
args=(),
kwargs={'profile_id': profile.id}))
user = profile.user
# fail if the user is active (this should not happen yet)
self.failIf(not user.is_active)
self.assertRedirects(resp, reverse('registration_approve_complete'))
示例4: test_registration
def test_registration(self):
"""
Registration creates a new inactive account and a new profile
with activation key, populates the correct account data and
sends an activation email.
"""
resp = self.client.post(
reverse("registration_register"),
data={"username": "bob", "email": "[email protected]", "password1": "secret", "password2": "secret"},
)
self.assertRedirects(resp, reverse("registration_complete"))
new_user = UserModel().objects.get(username="bob")
self.failUnless(new_user.check_password("secret"))
self.assertEqual(new_user.email, "[email protected]")
# New user must not be active.
self.failIf(new_user.is_active)
# A registration profile was created, and an activation email
# was sent.
self.assertEqual(RegistrationProfile.objects.count(), 1)
self.assertEqual(len(mail.outbox), 1)
示例5: test_registration_no_sites
def test_registration_no_sites(self):
"""
Registration still functions properly when
``django.contrib.sites`` is not installed; the fallback will
be a ``RequestSite`` instance.
"""
Site._meta.installed = False
resp = self.client.post(reverse('registration_register'),
data={'username': 'bob',
'email': '[email protected]',
'password1': 'secret',
'password2': 'secret'})
self.assertEqual(302, resp.status_code)
new_user = UserModel().objects.get(username='bob')
self.failUnless(new_user.check_password('secret'))
self.assertEqual(new_user.email, '[email protected]')
self.failIf(new_user.is_active)
self.assertEqual(RegistrationProfile.objects.count(), 1)
self.assertEqual(len(mail.outbox), 1)
Site._meta.installed = True
示例6: test_registration
def test_registration(self):
"""
Registration creates a new inactive account and a new profile
with activation key, populates the correct account data and
sends an activation email.
"""
resp = self.client.post(reverse('registration_register'),
data={'username': 'bob',
'email': '[email protected]',
'password1': 'secret',
'password2': 'secret'})
self.assertRedirects(resp, reverse('registration_complete'))
new_user = UserModel().objects.get(username='bob')
self.failUnless(new_user.check_password('secret'))
self.assertEqual(new_user.email, '[email protected]')
# New user must not be active.
self.failIf(new_user.is_active)
# A registration profile was created, and an activation email
# was sent.
self.assertEqual(RegistrationProfile.objects.count(), 1)
self.assertEqual(len(mail.outbox), 1)
示例7: test_profile_retrieval
def test_profile_retrieval(self):
# Testing User Information Retrieval for Login
new_user = UserModel().objects.create_user(**self.user_info)
existing_user = UserModel().objects.get(username='docemployee')
self.failUnless(existing_user.check_password('letstravel'))
self.assertEqual(existing_user.email, '[email protected]')
self.failUnless(existing_user.is_active)
示例8: setUp
def setUp(self):
self.client = Client()
admin_user = UserModel().objects.create_superuser(
'admin', '[email protected]', 'admin')
self.client.login(username=admin_user.get_username(), password=admin_user)
self.user_info = {'username': 'alice',
'password': 'swordfish',
'email': '[email protected]'}
示例9: test_users_can_fill_out_registration_form_and_create_profile
def test_users_can_fill_out_registration_form_and_create_profile(self):
# Tired of Twitter, Facebook, and Instagram Brad has luckily heard
# about the new social network on the block so he visits the website in
# his browser
self.browser.get(self.live_server_url + reverse('home'))
# He notices that the title mentions TSN (so much cooler than Twitter
# or Facebook) AND the page welcomes him to the site
self.assertIn('TSN', self.browser.title)
header_text = self.browser.find_element_by_tag_name('h1').text
self.assertIn('Welcome', header_text)
# He sees a link telling him to Register and he clicks it
self.browser.find_element_by_id('register').click()
# He winds up on a brand new page
register_url = self.browser.current_url
self.assertIn('/accounts/register', register_url)
# Brad fills out the form on this page to create an account with TSN
# and presses enter
for name, value in [('first_name', 'Brad'),
('last_name', 'Pitt'),
('username', 'brad'),
('email', '[email protected]'),
('password1', 'bradiscool'),
('password2', 'bradiscool\t\n')]:
self.browser.find_element_by_name(name).send_keys(value)
# He finds himself on another page telling him to activate his account
p_text = self.browser.find_element_by_tag_name('p').text
self.assertEquals('Please check your email to complete the registration process.', p_text)
# After activating, he goes to the login page and logs in
brad = UserModel().objects.get(username='brad')
brad.is_active = True
brad.save()
self.browser.get(self.live_server_url + reverse('auth_login'))
self.browser.find_element_by_name('username').send_keys('brad')
self.browser.find_element_by_name('password').send_keys('bradiscool\t\n')
# He is then immediately redirected to a page asking him to create a
# profile
self.browser.implicitly_wait(3)
self.assertIn('profile/create', self.browser.current_url)
# He provides his birthday and his gender
self.browser.find_element_by_name('birthday').send_keys('12/18/1963')
self.browser.find_element_by_name('gender').send_keys('M\t\n')
# He is now on the homepage again, this time he sees a post box
self.browser.implicitly_wait(3)
self.assertEqual(self.live_server_url + reverse('home'), self.browser.current_url)
self.assertIn('new_post', self.browser.page_source)
示例10: clean_username
def clean_username(self):
"""
Validate that the username is alphanumeric and is not already
in use.
"""
existing = UserModel().objects.filter(username__iexact=self.cleaned_data['username'])
if existing.exists():
raise forms.ValidationError(_("A user with that username already exists."))
else:
return self.cleaned_data['username']
示例11: clean_username
def clean_username(self):
"""
Validate that the username is alphanumeric and is not already
in use.
"""
kwargs = {UserModel().USERNAME_FIELD: self.cleaned_data['username']}
existing = UserModel().objects.filter(**kwargs)
if existing.exists():
raise forms.ValidationError(_("A user with that username already exists."))
else:
return self.cleaned_data['username']
示例12: clean_email
def clean_email(self):
if self.instance.pk != None:
existing_user = UserModel().objects.filter(username__iexact=self.cleaned_data['email'])
existing = Rolnik.objects.get(pk=self.instance.pk)
if existing_user.exists() and existing.user != existing_user[0]:
raise forms.ValidationError(_("This email belongs to someone else."))
return self.cleaned_data['email']
existing = UserModel().objects.filter(username__iexact=self.cleaned_data['email'])
if existing.exists():
raise forms.ValidationError(_("A user with that username already exists."))
else:
return self.cleaned_data['email']
示例13: register
def register(self, request, **cleaned_data):
username, email, password, first_name, last_name = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1'], cleaned_data['first_name'], cleaned_data['last_name']
theuser = UserModel().objects.create_user(username = username,
password = password,
email = email,
first_name = first_name,
last_name = last_name
)
theuser.save()
profile = UserProfile(user = theuser, location = cleaned_data['location'], career = cleaned_data['career'])
profile.save()
#(username, email, password, first_name, last_name)
new_user = authenticate(username=username, password=password)
login(request, new_user)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
return new_user
示例14: create_inactive_user
def create_inactive_user(self, username, email, password,
site, send_email=True):
"""
Create a new, inactive ``User``, generate a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.
By default, an activation email will be sent to the new
user. To disable this, pass ``send_email=False``.
"""
new_user = UserModel().objects.create_user(username, email, password)
new_user.is_active = False
new_user.save()
registration_profile = self.create_profile(new_user)
if send_email:
registration_profile.send_activation_email(site)
return new_user
示例15: create_inactive_user
def create_inactive_user(self, site, new_user=None, send_email=True, request=None, **user_info):
"""
Create a new, inactive ``User``, generate a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.
By default, an activation email will be sent to the new
user. To disable this, pass ``send_email=False``.
Additionally, if email is sent and ``request`` is supplied,
it will be passed to the email template.
"""
if new_user == None:
password = user_info.pop('password')
new_user = UserModel()(**user_info)
new_user.set_password( password )
new_user.is_active = True
new_user.save()
#user_for_choice = Student(student_text = new_user.username)
#user_for_choice.save()
registration_profile = self.create_profile(new_user)
if send_email:
registration_profile.send_activation_email(site, request)
return new_user