Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-val
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
edx-val
Commits
adc76966
Commit
adc76966
authored
Sep 20, 2017
by
muhammad-ammar
Committed by
Qubad786
Oct 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Organization specific transcript credentials state
EDUCATOR-1376
parent
92c935e1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
187 additions
and
4 deletions
+187
-4
edxval/admin.py
+8
-2
edxval/api.py
+42
-1
edxval/migrations/0007_transcript_credentials_state.py
+32
-0
edxval/models.py
+41
-0
edxval/tests/test_api.py
+64
-1
No files found.
edxval/admin.py
View file @
adc76966
"""
"""
Admin file for django app edxval.
Admin file for django app edxval.
"""
"""
from
django
import
forms
from
django.contrib
import
admin
from
django.contrib
import
admin
from
.models
import
(
CourseVideo
,
EncodedVideo
,
Profile
,
TranscriptPreference
,
from
.models
import
(
CourseVideo
,
EncodedVideo
,
Profile
,
TranscriptPreference
,
Video
,
VideoImage
,
VideoTranscript
)
Video
,
VideoImage
,
VideoTranscript
,
ThirdPartyTranscriptCredentialsState
)
class
ProfileAdmin
(
admin
.
ModelAdmin
):
# pylint: disable=C0111
class
ProfileAdmin
(
admin
.
ModelAdmin
):
# pylint: disable=C0111
...
@@ -81,9 +80,16 @@ class TranscriptPreferenceAdmin(admin.ModelAdmin):
...
@@ -81,9 +80,16 @@ class TranscriptPreferenceAdmin(admin.ModelAdmin):
model
=
TranscriptPreference
model
=
TranscriptPreference
class
ThirdPartyTranscriptCredentialsStateAdmin
(
admin
.
ModelAdmin
):
model
=
ThirdPartyTranscriptCredentialsState
verbose_name
=
'Organization Transcript Credential State'
verbose_name_plural
=
'Organization Transcript Credentials State'
admin
.
site
.
register
(
Profile
,
ProfileAdmin
)
admin
.
site
.
register
(
Profile
,
ProfileAdmin
)
admin
.
site
.
register
(
Video
,
VideoAdmin
)
admin
.
site
.
register
(
Video
,
VideoAdmin
)
admin
.
site
.
register
(
VideoTranscript
,
VideoTranscriptAdmin
)
admin
.
site
.
register
(
VideoTranscript
,
VideoTranscriptAdmin
)
admin
.
site
.
register
(
TranscriptPreference
,
TranscriptPreferenceAdmin
)
admin
.
site
.
register
(
TranscriptPreference
,
TranscriptPreferenceAdmin
)
admin
.
site
.
register
(
VideoImage
,
VideoImageAdmin
)
admin
.
site
.
register
(
VideoImage
,
VideoImageAdmin
)
admin
.
site
.
register
(
CourseVideo
,
CourseVideoAdmin
)
admin
.
site
.
register
(
CourseVideo
,
CourseVideoAdmin
)
admin
.
site
.
register
(
ThirdPartyTranscriptCredentialsState
,
ThirdPartyTranscriptCredentialsStateAdmin
)
edxval/api.py
View file @
adc76966
...
@@ -17,7 +17,7 @@ from edxval.exceptions import (InvalidTranscriptFormat,
...
@@ -17,7 +17,7 @@ from edxval.exceptions import (InvalidTranscriptFormat,
from
edxval.models
import
(
CourseVideo
,
EncodedVideo
,
Profile
,
from
edxval.models
import
(
CourseVideo
,
EncodedVideo
,
Profile
,
TranscriptFormat
,
TranscriptPreference
,
TranscriptFormat
,
TranscriptPreference
,
TranscriptProviderType
,
Video
,
VideoImage
,
TranscriptProviderType
,
Video
,
VideoImage
,
VideoTranscript
)
VideoTranscript
,
ThirdPartyTranscriptCredentialsState
)
from
edxval.serializers
import
TranscriptPreferenceSerializer
,
TranscriptSerializer
,
VideoSerializer
from
edxval.serializers
import
TranscriptPreferenceSerializer
,
TranscriptSerializer
,
VideoSerializer
from
edxval.utils
import
THIRD_PARTY_TRANSCRIPTION_PLANS
from
edxval.utils
import
THIRD_PARTY_TRANSCRIPTION_PLANS
...
@@ -143,6 +143,47 @@ def update_video_status(edx_video_id, status):
...
@@ -143,6 +143,47 @@ def update_video_status(edx_video_id, status):
video
.
save
()
video
.
save
()
def
get_transcript_credentials_state_for_org
(
org
,
provider
=
None
):
"""
Returns transcript credentials state for an org
Arguments:
org (unicode): course organization
provider (unicode): transcript provider
Returns:
dict: provider name and their credential existance map
{
u'Cielo24': True
}
{
u'3PlayMedia': False,
u'Cielo24': True
}
"""
query_filter
=
{
'org'
:
org
}
if
provider
:
query_filter
[
'provider'
]
=
provider
return
{
credential
.
provider
:
credential
.
exists
for
credential
in
ThirdPartyTranscriptCredentialsState
.
objects
.
filter
(
**
query_filter
)
}
def
update_transcript_credentials_state_for_org
(
org
,
provider
,
exists
):
"""
Updates transcript credentials state for a course organization.
Arguments:
org (unicode): course organization
provider (unicode): transcript provider
exists (bool): state of credentials
"""
ThirdPartyTranscriptCredentialsState
.
update_or_create
(
org
,
provider
,
exists
)
def
is_transcript_available
(
video_id
,
language_code
=
None
):
def
is_transcript_available
(
video_id
,
language_code
=
None
):
"""
"""
Returns whether the transcripts are available for a video.
Returns whether the transcripts are available for a video.
...
...
edxval/migrations/0007_transcript_credentials_state.py
0 → 100644
View file @
adc76966
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-10-10 08:15
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
django.utils.timezone
import
model_utils.fields
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'edxval'
,
'0006_auto_20171009_0725'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'ThirdPartyTranscriptCredentialsState'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'created'
,
model_utils
.
fields
.
AutoCreatedField
(
default
=
django
.
utils
.
timezone
.
now
,
editable
=
False
,
verbose_name
=
'created'
)),
(
'modified'
,
model_utils
.
fields
.
AutoLastModifiedField
(
default
=
django
.
utils
.
timezone
.
now
,
editable
=
False
,
verbose_name
=
'modified'
)),
(
'org'
,
models
.
CharField
(
max_length
=
32
,
verbose_name
=
b
'Course Organization'
)),
(
'provider'
,
models
.
CharField
(
choices
=
[(
b
'Custom'
,
b
'Custom'
),
(
b
'3PlayMedia'
,
b
'3PlayMedia'
),
(
b
'Cielo24'
,
b
'Cielo24'
)],
max_length
=
20
,
verbose_name
=
b
'Transcript Provider'
)),
(
'exists'
,
models
.
BooleanField
(
default
=
False
,
help_text
=
b
'Transcript credentials state'
)),
],
),
migrations
.
AlterUniqueTogether
(
name
=
'thirdpartytranscriptcredentialsstate'
,
unique_together
=
set
([(
'org'
,
'provider'
)]),
),
]
edxval/models.py
View file @
adc76966
...
@@ -612,6 +612,47 @@ class TranscriptPreference(TimeStampedModel):
...
@@ -612,6 +612,47 @@ class TranscriptPreference(TimeStampedModel):
return
u'{course_id} - {provider}'
.
format
(
course_id
=
self
.
course_id
,
provider
=
self
.
provider
)
return
u'{course_id} - {provider}'
.
format
(
course_id
=
self
.
course_id
,
provider
=
self
.
provider
)
class
ThirdPartyTranscriptCredentialsState
(
TimeStampedModel
):
"""
State of transcript credentials for a course organization
"""
class
Meta
:
unique_together
=
(
'org'
,
'provider'
)
org
=
models
.
CharField
(
verbose_name
=
'Course Organization'
,
max_length
=
32
)
provider
=
models
.
CharField
(
verbose_name
=
'Transcript Provider'
,
max_length
=
20
,
choices
=
TranscriptProviderType
.
CHOICES
,
)
exists
=
models
.
BooleanField
(
default
=
False
,
help_text
=
'Transcript credentials state'
)
@classmethod
def
update_or_create
(
cls
,
org
,
provider
,
exists
):
"""
Update or create credentials state.
"""
instance
,
created
=
cls
.
objects
.
update_or_create
(
org
=
org
,
provider
=
provider
,
defaults
=
{
'exists'
:
exists
},
)
return
instance
,
created
def
__unicode__
(
self
):
"""
Returns unicode representation of provider credentials state for an organization.
NOTE: Message will look like below:
edX has Cielo24 credentials
edX doesn't have 3PlayMedia credentials
"""
return
u'{org} {state} {provider} credentials'
.
format
(
org
=
self
.
org
,
provider
=
self
.
provider
,
state
=
'has'
if
self
.
exists
else
"doesn't have"
)
@receiver
(
models
.
signals
.
post_save
,
sender
=
Video
)
@receiver
(
models
.
signals
.
post_save
,
sender
=
Video
)
def
video_status_update_callback
(
sender
,
**
kwargs
):
# pylint: disable=unused-argument
def
video_status_update_callback
(
sender
,
**
kwargs
):
# pylint: disable=unused-argument
"""
"""
...
...
edxval/tests/test_api.py
View file @
adc76966
...
@@ -25,7 +25,7 @@ from edxval.api import (InvalidTranscriptFormat, InvalidTranscriptProvider,
...
@@ -25,7 +25,7 @@ from edxval.api import (InvalidTranscriptFormat, InvalidTranscriptProvider,
VideoSortField
)
VideoSortField
)
from
edxval.models
import
(
LIST_MAX_ITEMS
,
CourseVideo
,
EncodedVideo
,
Profile
,
from
edxval.models
import
(
LIST_MAX_ITEMS
,
CourseVideo
,
EncodedVideo
,
Profile
,
TranscriptFormat
,
TranscriptProviderType
,
Video
,
TranscriptFormat
,
TranscriptProviderType
,
Video
,
VideoImage
,
VideoTranscript
,
TranscriptPreference
)
VideoImage
,
VideoTranscript
,
TranscriptPreference
,
ThirdPartyTranscriptCredentialsState
)
from
edxval.tests
import
APIAuthTestCase
,
constants
from
edxval.tests
import
APIAuthTestCase
,
constants
from
edxval
import
utils
from
edxval
import
utils
...
@@ -2045,3 +2045,66 @@ class TranscriptPreferencesTest(TestCase):
...
@@ -2045,3 +2045,66 @@ class TranscriptPreferencesTest(TestCase):
# Verify that there should be 2 preferences exists
# Verify that there should be 2 preferences exists
self
.
assertEqual
(
TranscriptPreference
.
objects
.
count
(),
2
)
self
.
assertEqual
(
TranscriptPreference
.
objects
.
count
(),
2
)
@ddt
class
TranscripCredentialsStateTest
(
TestCase
):
"""
ThirdPartyTranscriptCredentialsState Tests
"""
def
setUp
(
self
):
"""
Tests setup
"""
ThirdPartyTranscriptCredentialsState
.
objects
.
create
(
org
=
'edX'
,
provider
=
'Cielo24'
,
exists
=
True
)
ThirdPartyTranscriptCredentialsState
.
objects
.
create
(
org
=
'edX'
,
provider
=
'3PlayMedia'
,
exists
=
False
)
@data
(
{
'org'
:
'MAX'
,
'provider'
:
'Cielo24'
,
'exists'
:
True
},
{
'org'
:
'MAX'
,
'provider'
:
'3PlayMedia'
,
'exists'
:
True
},
{
'org'
:
'edx'
,
'provider'
:
'3PlayMedia'
,
'exists'
:
True
},
)
@unpack
def
test_credentials_state_update
(
self
,
**
kwargs
):
"""
Verify that `update_transcript_credentials_state_for_org` method works as expected
"""
api
.
update_transcript_credentials_state_for_org
(
**
kwargs
)
credentials_state
=
ThirdPartyTranscriptCredentialsState
.
objects
.
get
(
org
=
kwargs
[
'org'
])
for
key
in
kwargs
:
self
.
assertEqual
(
getattr
(
credentials_state
,
key
),
kwargs
[
key
])
@data
(
{
'org'
:
'edX'
,
'provider'
:
'Cielo24'
,
'result'
:
{
u'Cielo24'
:
True
}
},
{
'org'
:
'edX'
,
'provider'
:
'3PlayMedia'
,
'result'
:
{
u'3PlayMedia'
:
False
}
},
{
'org'
:
'edX'
,
'provider'
:
None
,
'result'
:
{
u'3PlayMedia'
:
False
,
u'Cielo24'
:
True
}
},
{
'org'
:
'does_not_exist'
,
'provider'
:
'does_not_exist'
,
'result'
:
{}
},
)
@unpack
def
test_get_credentials_state
(
self
,
org
,
provider
,
result
):
"""
Verify that `get_transcript_credentials_state_for_org` method works as expected
"""
credentials_state
=
api
.
get_transcript_credentials_state_for_org
(
org
=
org
,
provider
=
provider
)
self
.
assertEqual
(
credentials_state
,
result
)
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