Пример #1
0
def member_update(request, id):
    """
    Allow member to update information in database.
    """
    member = get_object_or_404(Member, pk=id)
    if not logged_in_user_matches_requested_user(request, member):
        return render(request, "manage_members/member_permission_denied.html")

    member_form = MemberForm(request.POST or None, instance=member)
    if member_form.is_valid():
        member_form.save()
        _send_member_update_email_to_membership(member_form.instance)
        messages.success(request, 'Profile details updated.')
        return redirect('member_profile', id=id)
    return render(request, "manage_members/member_update_form.html", {
        'member': member,
        'member_form': member_form
    })
Пример #2
0
def _initialize_user_and_member_forms():
    """
    Initialize user and member forms with default values.
    """
    member_form = MemberForm(
        initial={
            'state': 'HI',
            'mailing_list': True,
            'wd_online': True,
            'arrl_member': True,
            'need_new_badge': True,
        })
    user_form = UserForm()
    return member_form, user_form
Пример #3
0
def new_member(request):
    """
    Allow new member to setup user information and account password.
    """
    if request.method == 'POST':
        member_form = MemberForm(request.POST)
        user_form = UserForm(request.POST)
        if member_form.is_valid() and user_form.is_valid():

            if _recaptcha_is_valid(request):

                # Save both forms without commiting yet
                member = member_form.save(commit=False)
                user = user_form.save(commit=False)

                _initially_setup_user_and_member(member, user)

                _send_activation_email_to_member(request, member)
                _send_new_member_email_to_membership(member)

                params = {
                    'name': member_form.cleaned_data['first_name'],
                }
                return redirect_params('member_thanks', params)

            else:  # Recaptcha failed
                messages.error(request, "Invalid reCAPTCHA. Please try again.")

    else:
        member_form, user_form = _initialize_user_and_member_forms()

    return render(
        request, "manage_members/member_new_form.html", {
            'member_form': member_form,
            'user_form': user_form,
            'site_key': settings.GOOGLE_RECAPTCHA_SITE_KEY,
        })
Пример #4
0
 def test_validate_missing_email_address_fails(self):
     self.test_data['email_address'] = ''
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #5
0
 def test_validate_invalid_zip_code_fails(self):
     self.test_data['zip_code'] = 'V3R 2E0'
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #6
0
 def test_validate_missing_phone_number_fails(self):
     self.test_data['phone'] = ''
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #7
0
 def test_validate_missing_city_fails(self):
     self.test_data['city'] = ''
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #8
0
 def test_validate_missing_zip_code_fails(self):
     self.test_data['zip_code'] = ''
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #9
0
 def test_validate_missing_last_name_fails(self):
     self.test_data['last_name'] = ''
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #10
0
 def test_validate_invalid_license_type_fails(self):
     self.test_data['license_type'] = 'X'
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #11
0
 def test_validate_missing_license_type_fails(self):
     # Prospective members with no license should contact membership to 
     # be added to member roll manually via admin panel.
     self.test_data['license_type'] = ''
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #12
0
 def test_validate_invalid_callsign_fails(self):
     self.test_data['callsign'] = 'NOCALL'
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), False)
Пример #13
0
 def test_validate_baseline_case_valid(self):
     form = MemberForm(self.test_data)
     self.assertEquals(form.is_valid(), True)