-
Notifications
You must be signed in to change notification settings - Fork 27
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
Organization specific transcript credentials state #99
Changes from all commits
adc7696
4ad6348
4b7f0f2
1ed30a3
ad1c2da
b27cdc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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')]), | ||
), | ||
] |
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', | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @muhammad-ammar we don't need to verify provider on pre-save signal. Model will automatically raises Exception if the you try to save it with a Provider which is not in its choices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not happening. Model allows to save the incorrect data if I remove the signal. |
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice. |
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if this is the best way to show record name ? |
||
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 | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_length=50
to be consistent with edx-pipelineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been done in #102