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


Python UserForm.is_valid方法代码示例

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


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

示例1: ValidUserFormTest

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
class ValidUserFormTest(FormTest):

    def setUp(self):
        super(ValidUserFormTest, self).setUp()

        self.user_form = UserForm(self.data)
        self.user_form.is_valid()
        self.new_user = self.user_form.save()

    def test_form_must_be_valid(self):
        self.assertTrue(self.user_form.is_valid())

    def test_save_user(self):
        self.assertIsInstance(self.new_user, User)

    def test_should_store_first_name(self):
        self.assertEqual(self.new_user.first_name, 'Valder Gallo')

    def test_should_store_last_name(self):
        self.assertEqual(self.new_user.last_name, 'Jr')

    def test_should_store_email(self):
        self.assertEqual(self.new_user.email, self.data.get('email'))

    def test_should_store_username(self):
        self.assertEqual(self.new_user.username, 'valdergallojr')
开发者ID:mcosta,项目名称:associados,代码行数:28,代码来源:test_forms.py

示例2: MemberFormTest

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
class MemberFormTest(TestCase):

    def setUp(self):
        self.data = {
        'full_name': 'Valder Gallo Jr',
        'organization': 'Home',
        'cpf': '94463643104',
        'email': '[email protected]',
        'phone': '1199492911',
        'city': 'Sao Paulo',
        'state': 'SP',
        'category': '1',
        'relationship': 'think',
        'mailling': 1,
        'contact': 1,
        }
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()

    def test_clean_full_name_firstname(self):
        self.assertEqual(self.user_form.cleaned_data.get('first_name'), 'Valder')

    def test_clean_full_name_lastname(self):
        self.assertEqual(self.user_form.cleaned_data.get('last_name'), 'Gallo Jr')

    def test_clean_organization(self):
        self.assertIsInstance(self.member_form.cleaned_data.get('organization'), Organization)

    def test_clean_city(self):
        self.assertIsInstance(self.member_form.cleaned_data.get('city'), City)

    def test_save(self):
        new_user = self.user_form.save()
        self.assertIsInstance(new_user, User)

    def test_created_object_city(self):
        user_instance = self.user_form.save()
        self.member_form.save(user_instance)
        city = City.objects.get()
        self.assertEqual(city.name, self.data.get('city'))

    def test_created_object_organization(self):
        user_instance = self.user_form.save()
        self.member_form.save(user_instance)
        organization = Organization.objects.get()
        self.assertEqual(organization.name, self.data.get('organization'))

    def test_should_create_an_user(self):
        user_instance = self.user_form.save()
        self.member_form.save(user_instance)
        self.assertEqual(user_instance.get_full_name(), self.data.get('full_name'))
开发者ID:koblitz,项目名称:associados,代码行数:56,代码来源:test_forms.py

示例3: ValidMemberFormTest

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
class ValidMemberFormTest(FormTest):

    def setUp(self):
        super(ValidMemberFormTest, self).setUp()

        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)

    def test_form_must_be_valid(self):
        self.assertTrue(self.member_form.is_valid())

    def test_should_create_an_user(self):
        self.assertEqual(self.user_instance.get_full_name(), self.data.get('full_name'))
        self.assertIsInstance(self.member_instance.user, User)

    def test_should_store_a_city(self):
        city = City.objects.get(name='Sao Paulo', state='SP')
        self.assertEqual(self.member_instance.city, city)

    def test_should_store_organization(self):
        organization = Organization.objects.get(name='Home')
        self.assertEqual(self.member_instance.organization, organization)

    def test_should_store_cpf(self):
        self.assertEqual(self.member_instance.cpf, self.data.get('cpf'))

    def test_should_store_phone(self):
        self.assertEqual(self.member_instance.phone, '11-9949-2911')

    def test_should_store_address(self):
        self.assertEqual(self.member_instance.address, self.data.get('address'))

    def test_should_store_public_key(self):
        self.assertEqual(self.member_instance.public_key, self.data.get('public_key'))

    def test_should_store_category(self):
        category = Category.objects.get(id=self.data.get('category'))
        self.assertEqual(self.member_instance.category, category)

    def test_should_store_relation_with_community(self):
        self.assertEqual(self.member_instance.relation_with_community, self.data.get('relation_with_community'))

    def test_should_store_mailing(self):
        self.assertEqual(self.member_instance.mailing, self.data.get('mailing'))

    def test_should_store_partner(self):
        self.assertEqual(self.member_instance.partner, self.data.get('partner'))
开发者ID:douglas,项目名称:associados,代码行数:54,代码来源:test_forms.py

示例4: member_form

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
def member_form(request):
    try:
        member = Member.objects.get(user=request.user)
    except Member.DoesNotExist:
        member = Member()
    user_form = UserForm(request.POST or None, instance=request.user)
    member_form = MemberForm(request.POST or None, instance=member)
    if request.POST:
        if member_form.is_valid() and user_form.is_valid():
            member_form.save(user=request.user)
            user_form.save()
            messages.add_message(request, messages.INFO, _('Your data was updated successfully'))
            return HttpResponseRedirect(reverse('members-dashboard'))
        else:
            messages.add_message(
                request, messages.ERROR,
                _('An error occurred while trying to save your data. check the form below. '))

    return render(
        request,
        "members/member_form.html", {
            "member_form": member_form,
            'user_form': user_form
        }
    )
开发者ID:fmondaini,项目名称:associados,代码行数:27,代码来源:views.py

示例5: ValidMemberFormTest

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
class ValidMemberFormTest(MemberFormTest):
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)

    def test_form_must_be_valid(self):
        self.assertTrue(self.member_form.is_valid())

    def test_should_store_location(self):
        self.assertEqual(self.member_instance.location, 'Sao Paulo')

    def test_should_store_organization(self):
        organization = Organization.objects.get(name='Home')
        self.assertEqual(self.member_instance.organization, organization)

    def test_should_store_cpf(self):
        self.assertEqual(self.member_instance.cpf, self.data.get('cpf'))

    def test_should_store_phone(self):
        self.assertEqual(self.member_instance.phone, '11-9949-2911')

    def test_should_store_address(self):
        self.assertEqual(self.member_instance.address, self.data.get('address'))

    def test_should_store_category(self):
        category = Category.objects.get(id=self.data.get('category'))
        self.assertEqual(self.member_instance.category, category)

    def test_should_store_relation_with_community(self):
        self.assertEqual(self.member_instance.relation_with_community, self.data.get('relation_with_community'))

    def test_should_store_mailing(self):
        self.assertEqual(self.member_instance.mailing, self.data.get('mailing'))

    def test_should_store_partner(self):
        self.assertEqual(self.member_instance.partner, self.data.get('partner'))
开发者ID:pythonbrasil,项目名称:associados,代码行数:43,代码来源:test_forms.py

示例6: InvalidUserFormTest

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
class InvalidUserFormTest(UserFormTest):
    def setUp(self):
        self.user_form = UserForm({})

    def test_must_be_invalid(self):
        self.assertFalse(self.user_form.is_valid())

    def test_with_no_data_should_return_email_error(self):
        self.assertTrue(self.user_form.errors.has_key('email'))

    def test_with_no_data_should_return_full_name_error(self):
        self.assertTrue(self.user_form.errors.has_key('full_name'))
开发者ID:cadu-leite,项目名称:associados,代码行数:14,代码来源:test_forms.py

示例7: register

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
def register(request):
    member_form = MemberForm(request.POST or None)
    user_form = UserForm(request.POST or None)
    if request.method == 'POST' and user_form.is_valid() and member_form.is_valid():
        user = user_form.save()
        member_form.save(user)

    return render(request,
        'flatpages/form.html',
            {
            'flatpage': {'title': u'Pedido de associação à APyB'},
            'user_form': user_form,
            'member_form': member_form,
            })
开发者ID:koblitz,项目名称:associados,代码行数:16,代码来源:views.py

示例8: register

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
def register(request):
    member_form = MemberForm(request.POST or None)
    user_form = UserForm(request.POST or None)
    saved = False

    if request.method == 'POST' and user_form.is_valid() and member_form.is_valid():
        user = user_form.save()
        member_form.save(user)
        saved = True

    return render(request,
        'members/member_register.html',
            {
            'saved': saved,
            'user_form': user_form,
            'member_form': member_form,
            })
开发者ID:mcosta,项目名称:associados,代码行数:19,代码来源:views.py

示例9: register

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
def register(request):
    member_form = MemberForm(request.POST or None)
    user_form = UserForm(request.POST or None)
    saved = False

    if request.method == 'POST' and user_form.is_valid() and member_form.is_valid():
        user = user_form.save()
        member = member_form.save(user)
        saved = True
        return HttpResponseRedirect(reverse('payment', kwargs={'member_id':member.id}))

    return render(request,
        'members/member_register.html',
            {
            'saved': saved,
            'user_form': user_form,
            'member_form': member_form,
            })
开发者ID:yuripiratello,项目名称:associados,代码行数:20,代码来源:views.py

示例10: member_form

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
def member_form(request):
    try:
        member = Member.objects.get(user=request.user)
    except Member.DoesNotExist:
        member = Member()
    user_form = UserForm(request.POST or None, instance=request.user)
    member_form = MemberForm(request.POST or None, instance=member)
    if request.POST:
        if member_form.is_valid() and user_form.is_valid():
            member_form.save(user=request.user)
            user_form.save()
            messages.add_message(request, messages.INFO, 'Seus dados foram atualizados com sucesso')
            return HttpResponseRedirect(reverse('members-dashboard'))
        else:
            messages.add_message(request, messages.ERROR, 'Ocorreu um erro ao tentar salvar seus dados. verifique o form abaixo.')

    return render(request,
        "members/member_form.html", {
            "member_form": member_form,
            'user_form': user_form
        }
    )
开发者ID:cadu-leite,项目名称:associados,代码行数:24,代码来源:views.py

示例11: ValidMemberFormTest

# 需要导入模块: from app.members.forms import UserForm [as 别名]
# 或者: from app.members.forms.UserForm import is_valid [as 别名]
class ValidMemberFormTest(MemberFormTest):
    def setUp(self):
        self.user_form = UserForm(self.data)
        self.user_form.is_valid()

        self.member_form = MemberForm(self.data)
        self.member_form.is_valid()
        self.user_instance = self.user_form.save()
        self.member_instance = self.member_form.save(self.user_instance)

    def test_form_must_be_valid(self):
        self.assertTrue(self.member_form.is_valid())

    def test_should_store_location(self):
        self.assertEqual(self.member_instance.location, 'Sao Paulo')

    def test_should_store_organization(self):
        organization = Organization.objects.get(name='Home')
        self.assertEqual(self.member_instance.organization, organization)

    def test_should_store_cpf(self):
        self.assertEqual(self.member_instance.cpf, self.data.get('cpf'))

    def test_should_store_phone(self):
        self.assertEqual(self.member_instance.phone, '11-9949-2911')

    def test_should_store_address(self):
        self.assertEqual(self.member_instance.address, self.data.get('address'))

    def test_should_store_category(self):
        category = Category.objects.get(id=self.data.get('category'))
        self.assertEqual(self.member_instance.category, category)

    def test_change_category_with_pending_payments(self):
        payment = Payment.objects.create(
            member=self.member_instance,
            type=PaymentType.objects.get(id=1)
        )

        transaction = Transaction.objects.create(
            payment=payment,
            status=0,
            code='fakecode',
            price='0.0'
        )

        self.member_instance.save()

        member_form = MemberForm(instance=self.member_instance, data={'category': 2})

        self.assertFalse(self.member_instance.get_payment_status())
        self.assertFalse(member_form.is_valid())

        self.assertEqual(member_form.errors['category'], [u"You can't change your category with pending payments"])

    def test_should_store_relation_with_community(self):
        self.assertEqual(self.member_instance.relation_with_community, self.data.get('relation_with_community'))

    def test_should_store_mailing(self):
        self.assertEqual(self.member_instance.mailing, self.data.get('mailing'))

    def test_should_store_partner(self):
        self.assertEqual(self.member_instance.partner, self.data.get('partner'))
开发者ID:MoisesTedeschi,项目名称:associados,代码行数:65,代码来源:test_forms.py


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