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


Python models.User方法代码示例

本文整理汇总了Python中accounts.models.User方法的典型用法代码示例。如果您正苦于以下问题:Python models.User方法的具体用法?Python models.User怎么用?Python models.User使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在accounts.models的用法示例。


在下文中一共展示了models.User方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_signs_up_sets_language

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_signs_up_sets_language(self):
        data = {
            'username': 'sherlock',
            'email': 'sherlock.holmes@bbc.uk',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'es'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 302
        assert User.objects.count() == 1
        assert 'account/accountverification/' in response.location
        assert translation.get_language() == 'es'

        # Reset language for following tests
        translation.activate('en') 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:18,代码来源:test_views_default.py

示例2: test_sign_up_with_invalid_phone_number

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_sign_up_with_invalid_phone_number(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=400,
            uri='http://localhost:8000',
            msg=('Unable to create record: The "To" number +15555555555 is '
                 'not a valid phone number.'),
            method='POST',
            code=21211
        )
        data = {
            'username': 'sherlock',
            'phone': '+15555555555',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'en'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 200
        assert TWILIO_ERRORS[21211] in response.content
        assert User.objects.count() == 0
        assert VerificationDevice.objects.count() == 0
        assert len(mail.outbox) == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:24,代码来源:test_views_default.py

示例3: test_twilio_error_500

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_twilio_error_500(self, send_sms):
        send_sms.side_effect = TwilioRestException(
            status=500,
            uri='http://localhost:8000',
            msg=('Account not active'),
            method='POST',
            code=20005
        )
        data = {
            'username': 'sherlock',
            'phone': '+15555555555',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'en'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 200
        assert TWILIO_ERRORS['default'] in response.content
        self.request(method='POST', post_data=data)
        assert User.objects.count() == 0
        assert VerificationDevice.objects.count() == 0
        assert len(mail.outbox) == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:24,代码来源:test_views_default.py

示例4: test_signs_up_with_invalid

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_signs_up_with_invalid(self):
        data = {
            'username': 'sherlock',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 200
        assert User.objects.count() == 0
        assert VerificationDevice.objects.count() == 0
        assert len(mail.outbox) == 0 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:13,代码来源:test_views_default.py

示例5: test_signs_up_with_phone_only

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_signs_up_with_phone_only(self):
        data = {
            'username': 'sherlock',
            'phone': '+919327768250',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'en'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 302
        assert User.objects.count() == 1
        assert VerificationDevice.objects.count() == 1
        assert len(mail.outbox) == 0
        assert 'account/accountverification/' in response.location 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:16,代码来源:test_views_default.py

示例6: test_signs_up_with_email_only

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_signs_up_with_email_only(self):
        data = {
            'username': 'sherlock',
            'email': 'sherlock.holmes@bbc.uk',
            'password': '221B@bakerstreet',
            'full_name': 'Sherlock Holmes',
            'language': 'en'
        }
        response = self.request(method='POST', post_data=data)
        assert response.status_code == 302
        assert User.objects.count() == 1
        assert VerificationDevice.objects.count() == 0
        assert len(mail.outbox) == 1
        assert 'account/accountverification/' in response.location 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:16,代码来源:test_views_default.py

示例7: test_with_organizations_and_projects

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_with_organizations_and_projects(self):
        user = UserFactory.create()
        org1, org2 = OrganizationFactory.create_batch(2)

        proj1, proj2 = ProjectFactory.create_batch(2, organization=org1)
        proj3 = ProjectFactory.create(organization=org2)
        proj4 = ProjectFactory.create(organization=org2, archived=False)

        ProjectRole.objects.create(project=proj1, user=user, role='DC')
        is_not_admin_org1 = OrganizationRole.objects.create(
            organization=org1, user=user, admin=False).admin
        is_admin_org2 = OrganizationRole.objects.create(
            organization=org2, user=user, admin=True).admin

        response = self.request(user=user)

        assert response.status_code == 200
        assert response.content == self.render_content(
            user_orgs_and_projects=[
                (org1, is_not_admin_org1, [
                    (proj2, 'Public User'),
                    (proj1, 'Data Collector')]),
                (org2, is_admin_org2, [
                    (proj3, 'Administrator'),
                    (proj4, 'Administrator')]),
                ]) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:28,代码来源:test_views_default.py

示例8: get_queryset

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def get_queryset(self):
        # Since we are querying on the organizations of each user, we should
        # prefetch the organizations when querying for all users instead of
        # doing a separate organizations query for every user
        return User.objects.prefetch_related('organizations') 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:7,代码来源:default.py

示例9: get_perms_objects

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def get_perms_objects(self):
        return [get_object_or_404(User, username=self.kwargs['user'])] 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:4,代码来源:default.py

示例10: post

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def post(self, request, user):
        userobj = get_object_or_404(User, username=user)
        userobj.is_active = self.new_state
        userobj.save()
        return redirect('user:list') 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:7,代码来源:default.py

示例11: to_representation

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def to_representation(self, instance):
        if isinstance(instance, User):
            rep = UserSerializer(instance).data
            rep[self.Meta.role_key] = self.get_role_json(instance)
            return rep 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:7,代码来源:serializers.py

示例12: validate_username

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def validate_username(self, value):
        error = ""
        if self.instance:
            self.user = self.instance
        else:
            users = User.objects.filter(
                Q(username=value) | Q(email=value) | Q(phone=value))
            users_count = len(users)

            if users_count == 0:
                error = _(
                    "User with username or email or phone {} does not exist")
            elif users_count > 1:
                error = _(
                    "More than one user found for username or email or"
                    " phone {}")
            else:
                self.user = users[0]

            if error:
                raise serializers.ValidationError(error.format(value))

            try:
                self.get_roles_object(self.user)
                raise serializers.ValidationError(
                    _("Not able to add member. The role already exists."))
            except self.Meta.role_model.DoesNotExist:
                pass 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:30,代码来源:serializers.py

示例13: validate

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def validate(self, data):
        if ((self.instance and self.instance.is_superuser) or
                self.org_role.admin):
            raise serializers.ValidationError(
                _("User {username} is an organization admin, the role cannot "
                  "be updated.").format(username=self.instance.username))
        return super().validate(data) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:9,代码来源:serializers.py

示例14: test_add_user_with_invalid_data

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_add_user_with_invalid_data(self):
        self.project = ProjectFactory.create()
        response = self.request(post_data={'username': 'some-user'},
                                method='POST',
                                user=self.user)
        assert response.status_code == 400
        assert self.project.users.count() == 0
        assert ('User with username or email or phone some-user does not exist'
                in response.content['username']) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:11,代码来源:test_views_api_projects.py

示例15: test_delete_user

# 需要导入模块: from accounts import models [as 别名]
# 或者: from accounts.models import User [as 别名]
def test_delete_user(self):
        self.test_user = UserFactory.create()
        self.project = ProjectFactory.create(add_users=[self.test_user])
        response = self.request(method='DELETE', user=self.user)
        assert response.status_code == 204
        assert self.project.users.count() == 0
        assert User.objects.filter(username=self.test_user.username).exists() 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:9,代码来源:test_views_api_projects.py


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