Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
50197ac6
Commit
50197ac6
authored
Dec 30, 2016
by
tasawernawaz
Committed by
Tasawer Nawaz
Jan 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed institution drop down validation ECOM-6709
parent
57a8f840
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
20 deletions
+40
-20
course_discovery/apps/publisher/forms.py
+11
-8
course_discovery/apps/publisher/tests/test_forms.py
+24
-0
course_discovery/apps/publisher/tests/test_views.py
+1
-9
course_discovery/apps/publisher/views.py
+4
-3
No files found.
course_discovery/apps/publisher/forms.py
View file @
50197ac6
...
...
@@ -6,7 +6,12 @@ from django.utils.translation import ugettext_lazy as _
from
course_discovery.apps.course_metadata.choices
import
CourseRunPacing
from
course_discovery.apps.course_metadata.models
import
Person
,
Organization
from
course_discovery.apps.publisher.models
import
Course
,
CourseRun
,
Seat
,
User
from
course_discovery.apps.publisher.models
import
Course
,
CourseRun
,
Seat
,
User
,
OrganizationExtension
class
UserModelChoiceField
(
forms
.
ModelChoiceField
):
def
label_from_instance
(
self
,
obj
):
return
obj
.
get_full_name
()
class
BaseCourseForm
(
forms
.
ModelForm
):
...
...
@@ -56,7 +61,7 @@ class CustomCourseForm(CourseForm):
number
=
forms
.
CharField
(
label
=
_
(
'Course Number'
),
required
=
True
)
# users will be loaded through AJAX call based on organization
team_admin
=
forms
.
ModelChoiceField
(
team_admin
=
User
ModelChoiceField
(
queryset
=
User
.
objects
.
none
(),
required
=
True
,
label
=
_
(
'Organization Course Admin'
),
)
...
...
@@ -71,12 +76,10 @@ class CustomCourseForm(CourseForm):
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
team_admin_id
=
kwargs
.
pop
(
'team_admin_id'
,
None
)
if
team_admin_id
:
try
:
self
.
declared_fields
[
'team_admin'
]
.
queryset
=
User
.
objects
.
filter
(
id
=
team_admin_id
)
except
Exception
:
# pylint: disable=broad-except
pass
organization
=
kwargs
.
pop
(
'organization'
,
None
)
if
organization
:
org_extension
=
OrganizationExtension
.
objects
.
get
(
organization
=
organization
)
self
.
declared_fields
[
'team_admin'
]
.
queryset
=
User
.
objects
.
filter
(
groups__name
=
org_extension
.
group
)
super
(
CustomCourseForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
course_discovery/apps/publisher/tests/test_forms.py
0 → 100644
View file @
50197ac6
from
django.test
import
TestCase
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.core.tests.factories
import
UserFactory
from
course_discovery.apps.publisher.forms
import
CustomCourseForm
class
UserModelChoiceFieldTests
(
TestCase
):
"""
Tests for the publisher model "UserModelChoiceField".
"""
def
test_course_form
(
self
):
"""
Verify that UserModelChoiceField returns `full_name` as choice label.
"""
course_form
=
CustomCourseForm
()
user
=
UserFactory
(
username
=
'test_user'
,
full_name
=
'Test Full Name'
)
course_form
.
fields
[
'team_admin'
]
.
queryset
=
User
.
objects
.
all
()
course_form
.
fields
[
'team_admin'
]
.
empty_label
=
None
# we need to loop through choices because it is a ModelChoiceIterator
for
__
,
choice_label
in
course_form
.
fields
[
'team_admin'
]
.
choices
:
self
.
assertEqual
(
choice_label
,
user
.
full_name
)
course_discovery/apps/publisher/tests/test_views.py
View file @
50197ac6
...
...
@@ -46,6 +46,7 @@ class CreateUpdateCourseViewTests(TestCase):
self
.
user
=
UserFactory
()
self
.
organization_extension
=
factories
.
OrganizationExtensionFactory
()
self
.
group
=
self
.
organization_extension
.
group
self
.
user
.
groups
.
add
(
self
.
group
)
self
.
course
=
factories
.
CourseFactory
()
self
.
course_run
=
factories
.
CourseRunFactory
(
course
=
self
.
course
)
...
...
@@ -263,15 +264,6 @@ class CreateUpdateCourseViewTests(TestCase):
self
.
assertContains
(
response
,
'<select class="field-input input-select" id="id_organization" name="organization">'
)
def
test_create_with_invalid_team_admin
(
self
):
""" Verify that view returns status_code=400 with invalid team admin. """
data
=
{
'number'
:
'course_1'
,
'image'
:
''
}
course_dict
=
self
.
_post_data
(
data
,
self
.
course
,
self
.
course_run
,
self
.
seat
)
course_dict
[
'team_admin'
]
=
"-------"
response
=
self
.
client
.
post
(
reverse
(
'publisher:publisher_courses_new'
),
course_dict
,
files
=
data
[
'image'
])
self
.
assertEqual
(
response
.
status_code
,
400
)
@ddt.data
(
'contacted_partner_manager'
,
'pacing_type'
)
def
test_create_without_selecting_radio_buttons
(
self
,
button_field
):
"""
...
...
course_discovery/apps/publisher/views.py
View file @
50197ac6
...
...
@@ -179,9 +179,10 @@ class CreateCourseView(mixins.LoginRequiredMixin, CreateView):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
ctx
=
self
.
get_context_data
()
# add selected team admin into choice of ChoiceField
team_admin_id
=
self
.
request
.
POST
.
get
(
'team_admin'
)
course_form
=
self
.
course_form
(
request
.
POST
,
request
.
FILES
,
team_admin_id
=
team_admin_id
)
# pass selected organization to CustomCourseForm to populate related
# choices into institution admin field
organization
=
self
.
request
.
POST
.
get
(
'organization'
)
course_form
=
self
.
course_form
(
request
.
POST
,
request
.
FILES
,
organization
=
organization
)
run_form
=
self
.
run_form
(
request
.
POST
)
seat_form
=
self
.
seat_form
(
request
.
POST
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment