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
bd3f45fe
Commit
bd3f45fe
authored
Feb 06, 2017
by
tasawernawaz
Committed by
Tasawer Nawaz
Feb 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix value error in instructor lookup ECOM-7083
parent
d99b003c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
12 deletions
+40
-12
course_discovery/apps/course_metadata/lookups.py
+1
-5
course_discovery/apps/course_metadata/models.py
+9
-0
course_discovery/apps/course_metadata/tests/test_lookups.py
+8
-1
course_discovery/apps/course_metadata/tests/test_models.py
+15
-0
course_discovery/apps/publisher/forms.py
+1
-1
course_discovery/apps/publisher/tests/test_forms.py
+4
-3
course_discovery/static/js/publisher/publisher.js
+2
-2
No files found.
course_discovery/apps/course_metadata/lookups.py
View file @
bd3f45fe
...
...
@@ -66,13 +66,9 @@ class PersonAutocomplete(autocomplete.Select2QuerySetView):
return
[]
def
get_result_label
(
self
,
result
):
profile_image
=
result
.
profile_image_url
if
hasattr
(
result
.
profile_image
,
'url'
):
profile_image
=
result
.
profile_image
.
url
context
=
{
'uuid'
:
result
.
uuid
,
'profile_image'
:
profile_image
,
'profile_image'
:
result
.
get_profile_image_url
,
'full_name'
:
result
.
full_name
,
'position'
:
result
.
position
if
hasattr
(
result
,
'position'
)
else
None
}
...
...
course_discovery/apps/course_metadata/models.py
View file @
bd3f45fe
...
...
@@ -222,6 +222,15 @@ class Person(TimeStampedModel):
def
full_name
(
self
):
return
' '
.
join
((
self
.
given_name
,
self
.
family_name
,))
@property
def
get_profile_image_url
(
self
):
url
=
self
.
profile_image_url
if
not
url
:
if
self
.
profile_image
and
hasattr
(
self
.
profile_image
,
'url'
):
url
=
self
.
profile_image
.
url
return
url
class
Position
(
TimeStampedModel
):
""" Position model.
...
...
course_discovery/apps/course_metadata/tests/test_lookups.py
View file @
bd3f45fe
...
...
@@ -163,7 +163,7 @@ class AutocompleteTests(TestCase):
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
))
self
.
_assert_response
(
response
,
0
)
def
test_instructor_label
(
self
):
def
test_instructor_
position_in_
label
(
self
):
""" Verify that instructor label contains position of instructor if it exists."""
position_title
=
'professor'
PositionFactory
.
create
(
person
=
self
.
instructors
[
0
],
title
=
position_title
,
organization
=
self
.
organizations
[
0
])
...
...
@@ -174,6 +174,13 @@ class AutocompleteTests(TestCase):
position
=
position_title
,
organization
=
self
.
organizations
[
0
]
.
name
))
def
test_instructor_image_in_label
(
self
):
""" Verify that instructor label contains profile image url.
"""
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
))
self
.
assertContains
(
response
,
self
.
instructors
[
0
]
.
get_profile_image_url
)
self
.
assertContains
(
response
,
self
.
instructors
[
1
]
.
get_profile_image_url
)
def
_assert_response
(
self
,
response
,
expected_length
):
""" Assert autocomplete response. """
self
.
assertEqual
(
response
.
status_code
,
200
)
...
...
course_discovery/apps/course_metadata/tests/test_models.py
View file @
bd3f45fe
...
...
@@ -300,6 +300,21 @@ class PersonTests(TestCase):
expected
=
self
.
person
.
given_name
+
' '
+
self
.
person
.
family_name
self
.
assertEqual
(
self
.
person
.
full_name
,
expected
)
def
test_get_profile_image_url
(
self
):
"""
Verify that property returns profile_image_url if profile_image_url
exists other wise it returns uploaded image url.
"""
self
.
assertEqual
(
self
.
person
.
get_profile_image_url
,
self
.
person
.
profile_image_url
)
# create another person with out profile_image_url
person
=
factories
.
PersonFactory
(
profile_image_url
=
None
)
self
.
assertEqual
(
person
.
get_profile_image_url
,
person
.
profile_image
.
url
)
# create another person with out profile_image_url and profile_image
person
=
factories
.
PersonFactory
(
profile_image_url
=
None
,
profile_image
=
None
)
self
.
assertFalse
(
person
.
get_profile_image_url
)
def
test_str
(
self
):
""" Verify casting an instance to a string returns the person's full name. """
self
.
assertEqual
(
str
(
self
.
person
),
self
.
person
.
full_name
)
...
...
course_discovery/apps/publisher/forms.py
View file @
bd3f45fe
...
...
@@ -26,7 +26,7 @@ class UserModelChoiceField(forms.ModelChoiceField):
class
PersonModelMultipleChoice
(
forms
.
ModelMultipleChoiceField
):
def
label_from_instance
(
self
,
obj
):
context
=
{
'profile_image'
:
obj
.
profile_image_url
,
'profile_image'
:
obj
.
get_
profile_image_url
,
'full_name'
:
obj
.
full_name
}
return
str
(
render_to_string
(
'publisher/_personFieldLabel.html'
,
context
=
context
))
...
...
course_discovery/apps/publisher/tests/test_forms.py
View file @
bd3f45fe
...
...
@@ -33,14 +33,15 @@ class PersonModelMultipleChoiceTests(TestCase):
Verify that PersonModelMultipleChoice returns `full_name` and `profile_image_url` as choice label.
"""
course_form
=
CustomCourseRunForm
()
course_form
.
fields
[
'staff'
]
.
empty_label
=
None
person
=
PersonFactory
()
course_form
.
fields
[
'staff'
]
.
queryset
=
Person
.
objects
.
all
()
course_form
.
fields
[
'staff'
]
.
empty_label
=
None
# we need to loop through choices because it is a ModelChoiceIterator
for
__
,
choice_label
in
course_form
.
fields
[
'staff'
]
.
choices
:
expected
=
'<img src="{
profile_image
}"/><span>{full_name}</span>'
.
format
(
expected
=
'<img src="{
url
}"/><span>{full_name}</span>'
.
format
(
full_name
=
person
.
full_name
,
profile_image
=
person
.
profile_image_url
url
=
person
.
get_
profile_image_url
)
self
.
assertEqual
(
choice_label
.
strip
(),
expected
)
course_discovery/static/js/publisher/publisher.js
View file @
bd3f45fe
...
...
@@ -191,9 +191,9 @@ function closeModal(event, modal) {
$
(
document
).
on
(
'change'
,
'#id_staff'
,
function
(
e
)
{
var
id
=
this
.
value
,
$instructorSelector
=
$
(
'.instructor-select'
),
var
$instructorSelector
=
$
(
'.instructor-select'
),
$instructor
=
$instructorSelector
.
find
(
'.select2-selection__choice'
),
id
=
$instructor
.
find
(
'.instructor-option'
).
last
().
prop
(
"id"
),
image_source
,
name
;
$instructorSelector
.
find
(
'.select2-selection__clear'
).
remove
();
...
...
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