Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile form #30

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions member_manager/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from member_manager.tests.page import PageTest
from member_manager.tests.profile import ProfileTest
from member_manager.tests.profile_add import ProfileAddViewTest
from member_manager.tests.profile_form import ProfileFormTest
from member_manager.tests.profile_skill import ProfileSkillTest
from member_manager.tests.published import PublishedListFilterTest
Expand Down
28 changes: 28 additions & 0 deletions member_manager/tests/profile_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""ProfileAddViewTest class"""

from django.contrib.auth.models import AnonymousUser
from django.test import RequestFactory, TestCase

from member_manager.views.profile_add import ProfileAddView


class ProfileAddViewTest(TestCase):
"""ProfileAddViewTest tests the ProfileAddView class"""

@classmethod
def setUpTestData(cls):
request_factory = RequestFactory()
cls.request = request_factory.get('/member_manager/profile')
cls.request.user = AnonymousUser()
cls.request.session = {}
cls.data = {'first_name': 'foo', 'last_name': 'bar',
'email': '[email protected]', 'phone': '0987654321'}

def test_form_valid(self):
"""Tests form_valid"""
view_i = ProfileAddView(success_url='/availability',
**{'request': self.request})
form_class = view_i.get_form_class()
form = form_class(data=self.data)
self.assertTrue(view_i.form_valid(form))
self.assertEqual(self.request.session['profile_id'], 1)
4 changes: 2 additions & 2 deletions member_manager/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.shortcuts import render
"""MemberManager views"""

# Create your views here.
from member_manager.views.profile_add import ProfileAddView
24 changes: 24 additions & 0 deletions member_manager/views/profile_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""ProfileAddView class"""

from django.forms import modelform_factory

from common_files.views.timestamp import TimestampCreateView
from member_manager.forms.profile import ProfileForm
from member_manager.models.profile import Profile


class ProfileAddView(TimestampCreateView):
"""ProfileAddView"""

form_class = modelform_factory(Profile, form=ProfileForm,
fields=['first_name', 'last_name',
'pronouns', 'email', 'phone',
'join_reason', 'how_heard',
'how_heard_other'])
template_name = 'member_manager/profile_add_form.html'

def form_valid(self, form):
"""Save valid form and add profile_id to session."""
redirect = super().form_valid(form)
self.request.session['profile_id'] = self.object.id
return redirect