Skip to content

Commit

Permalink
Merge pull request #99 from edx/ammar/org-specific-credentials-state
Browse files Browse the repository at this point in the history
Organization specific transcript credentials state
  • Loading branch information
Muzaffar yousaf committed Oct 26, 2017
2 parents 92c935e + b27cdc0 commit 13c7186
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 193 deletions.
12 changes: 10 additions & 2 deletions edxval/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
Admin file for django app edxval.
"""
from django import forms
from django.contrib import admin

from .models import (CourseVideo, EncodedVideo, Profile, TranscriptPreference,
Video, VideoImage, VideoTranscript)
Video, VideoImage, VideoTranscript, ThirdPartyTranscriptCredentialsState)


class ProfileAdmin(admin.ModelAdmin): # pylint: disable=C0111
Expand Down Expand Up @@ -81,9 +80,18 @@ class TranscriptPreferenceAdmin(admin.ModelAdmin):
model = TranscriptPreference


class ThirdPartyTranscriptCredentialsStateAdmin(admin.ModelAdmin):
list_display = ('org', 'provider', 'exists', 'created', 'modified')

model = ThirdPartyTranscriptCredentialsState
verbose_name = 'Organization Transcript Credential State'
verbose_name_plural = 'Organization Transcript Credentials State'


admin.site.register(Profile, ProfileAdmin)
admin.site.register(Video, VideoAdmin)
admin.site.register(VideoTranscript, VideoTranscriptAdmin)
admin.site.register(TranscriptPreference, TranscriptPreferenceAdmin)
admin.site.register(VideoImage, VideoImageAdmin)
admin.site.register(CourseVideo, CourseVideoAdmin)
admin.site.register(ThirdPartyTranscriptCredentialsState, ThirdPartyTranscriptCredentialsStateAdmin)
43 changes: 42 additions & 1 deletion edxval/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from edxval.models import (CourseVideo, EncodedVideo, Profile,
TranscriptFormat, TranscriptPreference,
TranscriptProviderType, Video, VideoImage,
VideoTranscript)
VideoTranscript, ThirdPartyTranscriptCredentialsState)
from edxval.serializers import TranscriptPreferenceSerializer, TranscriptSerializer, VideoSerializer
from edxval.utils import THIRD_PARTY_TRANSCRIPTION_PLANS

Expand Down Expand Up @@ -143,6 +143,47 @@ def update_video_status(edx_video_id, status):
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):
"""
Returns whether the transcripts are available for a video.
Expand Down
32 changes: 32 additions & 0 deletions edxval/migrations/0007_transcript_credentials_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- 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')]),
),
]
21 changes: 21 additions & 0 deletions edxval/migrations/0008_auto_20171026_0359.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('edxval', '0007_transcript_credentials_state'),
]

operations = [
migrations.RemoveField(
model_name='subtitle',
name='video',
),
migrations.DeleteModel(
name='Subtitle',
),
]
82 changes: 41 additions & 41 deletions edxval/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,47 +482,6 @@ def __unicode__(self):
return u'{lang} Transcript for {video}'.format(lang=self.language_code, video=self.video_id)


SUBTITLE_FORMATS = (
('srt', 'SubRip'),
('sjson', 'SRT JSON')
)


class Subtitle(models.Model):
"""
Subtitle for video
Attributes:
video: the video that the subtitles are for
fmt: the format of the subttitles file
"""
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
video = models.ForeignKey(Video, related_name="subtitles")
fmt = models.CharField(max_length=20, db_index=True, choices=SUBTITLE_FORMATS)
language = models.CharField(max_length=8, db_index=True)
content = models.TextField(default='')

def __str__(self):
return '%s Subtitle for %s' % (self.language, self.video)

def get_absolute_url(self):
"""
Returns the full url link to the edx_video_id
"""
return reverse('subtitle-content', args=[self.video.edx_video_id, self.language])

@property
def content_type(self):
"""
Sjson is returned as application/json, otherwise text/plain
"""
if self.fmt == 'sjson':
return 'application/json'
else:
return 'text/plain'


class Cielo24Turnaround(object):
"""
Cielo24 turnarounds.
Expand Down Expand Up @@ -612,6 +571,47 @@ def __unicode__(self):
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)
def video_status_update_callback(sender, **kwargs): # pylint: disable=unused-argument
"""
Expand Down
Loading

0 comments on commit 13c7186

Please sign in to comment.