当前位置: 首页>>代码示例>>Python>>正文


Python users.UserModel类代码示例

本文整理汇总了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']
开发者ID:matsinvasion,项目名称:markshelp,代码行数:7,代码来源:forms.py

示例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
开发者ID:tnbt27,项目名称:Registration_Profile_Search_boilerplate,代码行数:25,代码来源:models.py

示例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'))
开发者ID:UsefNait,项目名称:Stage_QA,代码行数:29,代码来源:admin_approval_backend.py

示例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)
开发者ID:Raouloq,项目名称:rmap,代码行数:25,代码来源:default_backend.py

示例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
开发者ID:hanks42,项目名称:django-registration,代码行数:27,代码来源:default_backend.py

示例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)
开发者ID:MUDASSARHASHMI,项目名称:django-registration,代码行数:26,代码来源:default_backend.py

示例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)
开发者ID:CommerceDataService,项目名称:ITA_Principal_Travel,代码行数:8,代码来源:test_travel.py

示例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]'}
开发者ID:JostCrow,项目名称:django-registration,代码行数:9,代码来源:admin_actions.py

示例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)
开发者ID:jackieaskins,项目名称:The-Social-Network,代码行数:54,代码来源:test_new_user_access.py

示例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']
开发者ID:tnbt27,项目名称:Registration_Profile_Search_boilerplate,代码行数:11,代码来源:forms.py

示例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']
开发者ID:Andertaker,项目名称:django-registration,代码行数:12,代码来源:forms.py

示例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']
开发者ID:pan-mroku,项目名称:plodyrolne,代码行数:12,代码来源:models.py

示例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
开发者ID:junyangchen,项目名称:bixplorer,代码行数:20,代码来源:views.py

示例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
开发者ID:jimblanc,项目名称:django-registration,代码行数:21,代码来源:models.py

示例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
开发者ID:York-Lee,项目名称:recommendation-letter,代码行数:28,代码来源:models.py


注:本文中的registration.users.UserModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。