Beispiel #1
0
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
        }
    )
Beispiel #2
0
    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 add_member():
    form = MemberForm()
    if form.validate_on_submit():
        data = Members(name=form.member_name.data, contact=form.contact_no.data, email=form.email.data,
                       dob=form.dob.data)
        db.session.add(data)
        db.session.commit()
        flash("Member added successfully")
    return render_template("add_member.html", form=form)
Beispiel #4
0
class CreateNewMember(MemberFormTest):
    def setUp(self):
        self.member_form = MemberForm(self.data)

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

    def test_save_form(self):
        user = User.objects.create(username='******')
        self.member_form.is_valid()
        self.member_form.save(user)
        self.assertEqual(Member.objects.count(), 1)
Beispiel #5
0
class CreateNewMember(MemberFormTest):
    def setUp(self):
        self.member_form = MemberForm(self.data)

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

    def test_save_form(self):
        user = User.objects.create(username='******')
        self.member_form.is_valid()
        self.member_form.save(user)
        self.assertEqual(Member.objects.count(), 1)
Beispiel #6
0
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'))
Beispiel #7
0
def member_form(request):

    if request.user:
        member = Member.objects.get(pk=request.user.pk)
    else:
        member = None

    form = MemberForm(request.POST or None, instance=member, user=request.user)
    if request.POST:
        if form.is_valid():
            form.save(user=request.user)

    return render(request, "members/member_form.html", {"form": form})
Beispiel #8
0
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,
            })
Beispiel #9
0
    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)
Beispiel #10
0
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,
            })
Beispiel #11
0
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,
            })
def edit_member(id):
    form = MemberForm()
    member = Members.query.get_or_404(id)

    if form.validate_on_submit():
        Members.query.filter_by(id=id).update(
            {Members.name: form.member_name.data, Members.contact: form.contact_no.data,
             Members.email: form.email.data, Members.dob: form.dob.data})
        db.session.commit()
        flash("member details edited successfully")
        return redirect(url_for('members_bp.edit_member', id=member.id))

    form.member_name.default = member.name
    form.contact_no.default = member.contact
    form.email.default = member.email
    form.dob.default = member.dob
    form.process()
    return render_template("edit_member.html", form=form, member=member)
Beispiel #13
0
class MemberFormTest(TestCase):

    def setUp(self):
        self.data = {
        'full_name': 'Valder Gallo Jr',
        'organization': 'Home',
        'cpf': '94463643104',
        'email': '*****@*****.**',
        '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'))
Beispiel #14
0
    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)
Beispiel #15
0
    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"])
Beispiel #16
0
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'))
Beispiel #17
0
    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"])
Beispiel #18
0
class InvalidMemberFormTest(MemberFormTest):
    def setUp(self):
        self.member_form = MemberForm({})

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

    def test_with_no_data_should_return_category_error(self):
        self.assertIn('category', self.member_form.errors)

    def test_with_no_data_should_return_cpf_error(self):
        self.assertIn('cpf', self.member_form.errors)
Beispiel #19
0
class InvalidMemberFormTest(MemberFormTest):
    def setUp(self):
        self.member_form = MemberForm({})

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

    def test_with_no_data_should_return_category_error(self):
        self.assertIn('category', self.member_form.errors)

    def test_with_no_data_should_return_cpf_error(self):
        self.assertIn('cpf', self.member_form.errors)
Beispiel #20
0
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
        }
    )
Beispiel #21
0
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
        }
    )
Beispiel #22
0
    def setUp(self):
        self.data = {
        'full_name': 'Valder Gallo Jr',
        'organization': 'Home',
        'cpf': '94463643104',
        'email': '*****@*****.**',
        '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()
Beispiel #23
0
class InvalidUserFormTest(MemberFormTest):
    def setUp(self):
        super(InvalidUserFormTest, self).setUp()
        self.member_form = MemberForm({})

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

    def test_with_no_data_should_return_category_error(self):
        self.assertTrue(self.member_form.errors.has_key('category'))

    def test_with_no_data_should_return_organization_error(self):
        self.assertTrue(self.member_form.errors.has_key('organization'))

    def test_with_no_data_should_return_state_error(self):
        self.assertTrue(self.member_form.errors.has_key('state'))

    def test_with_no_data_should_return_cpf_error(self):
        self.assertTrue(self.member_form.errors.has_key('cpf'))

    def test_with_no_data_should_return_city_error(self):
        self.assertTrue(self.member_form.errors.has_key('city'))
Beispiel #24
0
 def setUp(self):
     super(InvalidMemberFormTest, self).setUp()
     self.member_form = MemberForm({})
Beispiel #25
0
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'))
Beispiel #26
0
 def setUp(self):
     self.member_form = MemberForm({})
Beispiel #27
0
 def setUp(self):
     self.member_form = MemberForm(self.data)
Beispiel #28
0
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'))
Beispiel #29
0
 def setUp(self):
     self.member_form = MemberForm(self.data)
Beispiel #30
0
 def setUp(self):
     self.member_form = MemberForm({})