Skip to content

Commit

Permalink
Merge pull request #271 from edx/jenkins/cleanup-python-code-ca42f35
Browse files Browse the repository at this point in the history
Python Code Cleanup
  • Loading branch information
UsamaSadiq authored Jan 19, 2021
2 parents 1f8dcc7 + 8c19e57 commit cd54e79
Show file tree
Hide file tree
Showing 40 changed files with 477 additions and 1,077 deletions.
23 changes: 13 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
language: python

python:
- 3.5
- 3.8

- '3.8'
env:
- TOXENV=django22
- TOXENV=quality

- TOXENV=quality
- TOXENV=django22
- TOXENV=django30
- TOXENV=django31
matrix:
allow_failures:
- python: 3.8
env: TOXENV=django31
install:
- pip install -r requirements/travis.txt
- pip install -r requirements/travis.txt
script:
- tox
- tox
after_success: coveralls
# Set password via "travis encrypt --add deploy.password"; for details, see
# https://docs.travis-ci.com/user/deployment/pypi
Expand All @@ -22,7 +25,7 @@ deploy:
skip_upload_docs: true
on:
tags: true
python: 3.5
condition: "$TOXENV = quality"
python: 3.8
condition: $TOXENV = quality
password:
secure: JGKw0H2Hl1i3OuJ+54hGX/YImhWe+MvkkeFZDynpBKir8XD+E/fbz2lvvmggIrMsawkE5qlOjK8f4d4LMzwL51Ln0EmuIkhUceXLDihrEymZu97uAWbT5qR55RrfwZk/qaYV8JHAszBD3yLA5VOyDLTiDt9s2ilZDQqQqecX514=
2 changes: 1 addition & 1 deletion edxval/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class VideoImageAdmin(admin.ModelAdmin):

def get_course_video(self, obj):
""" get course video """
return u'"{course_id}" -- "{edx_video_id}" '.format(
return '"{course_id}" -- "{edx_video_id}" '.format(
course_id=obj.course_video.course_id,
edx_video_id=obj.course_video.video.edx_video_id
)
Expand Down
47 changes: 23 additions & 24 deletions edxval/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
The internal API for VAL.
"""
Expand Down Expand Up @@ -160,11 +159,11 @@ def update_video(video_data):
"""
try:
video = _get_video(video_data.get("edx_video_id"))
except Video.DoesNotExist:
error_message = u"Video not found when trying to update video with edx_video_id: {0}".format(
except Video.DoesNotExist as no_video_error:
error_message = "Video not found when trying to update video with edx_video_id: {}".format(
video_data.get("edx_video_id")
)
raise ValVideoNotFoundError(error_message) # pylint: disable=raise-missing-from
raise ValVideoNotFoundError(error_message) from no_video_error

serializer = VideoSerializer(video, data=video_data)
if serializer.is_valid():
Expand All @@ -187,11 +186,11 @@ def update_video_status(edx_video_id, status):
"""
try:
video = _get_video(edx_video_id)
except Video.DoesNotExist:
error_message = u"Video not found when trying to update video status with edx_video_id: {0}".format(
except Video.DoesNotExist as no_video_error:
error_message = "Video not found when trying to update video status with edx_video_id: {}".format(
edx_video_id
)
raise ValVideoNotFoundError(error_message) # pylint: disable=raise-missing-from
raise ValVideoNotFoundError(error_message) from no_video_error

video.status = status
video.save()
Expand Down Expand Up @@ -380,11 +379,11 @@ def create_or_update_video_transcript(video_id, language_code, metadata, file_da

file_format = metadata.get('file_format')
if file_format and file_format not in list(dict(TranscriptFormat.CHOICES).keys()):
raise InvalidTranscriptFormat('{} transcript format is not supported'.format(file_format))
raise InvalidTranscriptFormat(f'{file_format} transcript format is not supported')

provider = metadata.get('provider')
if provider and provider not in list(dict(TranscriptProviderType.CHOICES).keys()):
raise InvalidTranscriptProvider('{} transcript provider is not supported'.format(provider))
raise InvalidTranscriptProvider(f'{provider} transcript provider is not supported')

try:
# Video should be present in edxval in order to attach transcripts to it.
Expand Down Expand Up @@ -502,12 +501,12 @@ def update_video_image(edx_video_id, course_id, image_data, file_name):
course_video = CourseVideo.objects.select_related('video').get(
course_id=course_id, video__edx_video_id=edx_video_id
)
except ObjectDoesNotExist:
error_message = u'VAL: CourseVideo not found for edx_video_id: {0} and course_id: {1}'.format(
except ObjectDoesNotExist as no_video_error:
error_message = 'VAL: CourseVideo not found for edx_video_id: {} and course_id: {}'.format(
edx_video_id,
course_id
)
raise ValVideoNotFoundError(error_message) # pylint: disable=raise-missing-from
raise ValVideoNotFoundError(error_message) from no_video_error

video_image, _ = VideoImage.create_or_update(course_video, file_name, image_data)
return video_image.image_url()
Expand All @@ -530,7 +529,7 @@ def create_profile(profile_name):
profile.full_clean()
profile.save()
except ValidationError as err:
raise ValCannotCreateError(err.message_dict) # pylint: disable=raise-missing-from
raise ValCannotCreateError(err.message_dict) from err


def _get_video(edx_video_id):
Expand All @@ -545,13 +544,13 @@ def _get_video(edx_video_id):
.prefetch_related(Prefetch("encoded_videos", queryset=encoded_videos)) \
.prefetch_related("courses") \
.get(edx_video_id=edx_video_id)
except Video.DoesNotExist:
error_message = u"Video not found for edx_video_id: {0}".format(edx_video_id)
raise ValVideoNotFoundError(error_message) # pylint: disable=raise-missing-from
except Exception:
error_message = u"Could not get edx_video_id: {0}".format(edx_video_id)
except Video.DoesNotExist as no_video_error:
error_message = f"Video not found for edx_video_id: {edx_video_id}"
raise ValVideoNotFoundError(error_message) from no_video_error
except Exception as exc:
error_message = f"Could not get edx_video_id: {edx_video_id}"
logger.exception(error_message)
raise ValInternalError(error_message) # pylint: disable=raise-missing-from
raise ValInternalError(error_message) from exc


def get_video_info(edx_video_id):
Expand Down Expand Up @@ -833,10 +832,10 @@ def get_video_info_for_course_and_profiles(course_id, profiles):
profile__profile_name__in=profiles,
video__courses__course_id=course_id
).select_related()
except Exception:
error_message = u"Could not get encoded videos for course: {0}".format(course_id)
except Exception as exc:
error_message = f"Could not get encoded videos for course: {course_id}"
logger.exception(error_message)
raise ValInternalError(error_message) # pylint: disable=raise-missing-from
raise ValInternalError(error_message) from exc

# DRF serializers were causing extra queries for some reason...
return_dict = {}
Expand Down Expand Up @@ -1098,7 +1097,7 @@ def import_from_xml(xml, edx_video_id, resource_fs, static_dir, external_transcr
return edx_video_id
except ValidationError as err:
logger.exception(xml)
raise ValCannotCreateError(err.message_dict) # pylint: disable=raise-missing-from
raise ValCannotCreateError(err.message_dict) from err
except Video.DoesNotExist:
pass

Expand Down Expand Up @@ -1253,7 +1252,7 @@ def create_transcript_objects(xml, edx_video_id, resource_fs, static_dir, extern
try:
file_format = transcript.attrib['file_format']
language_code = transcript.attrib['language_code']
transcript_file_name = u'{edx_video_id}-{language_code}.{file_format}'.format(
transcript_file_name = '{edx_video_id}-{language_code}.{file_format}'.format(
edx_video_id=edx_video_id,
language_code=language_code,
file_format=file_format
Expand Down
13 changes: 5 additions & 8 deletions edxval/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.core.validators
import edxval.models
from django.db import migrations, models
Expand Down Expand Up @@ -35,7 +32,7 @@ class Migration(migrations.Migration):
name='Profile',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('profile_name', models.CharField(unique=True, max_length=50, validators=[django.core.validators.RegexValidator(regex=u'^[a-zA-Z0-9\\-_]*$', message=u'profile_name has invalid characters', code=u'invalid profile_name')])),
('profile_name', models.CharField(unique=True, max_length=50, validators=[django.core.validators.RegexValidator(regex='^[a-zA-Z0-9\\-_]*$', message='profile_name has invalid characters', code='invalid profile_name')])),
],
),
migrations.CreateModel(
Expand All @@ -44,17 +41,17 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('fmt', models.CharField(db_index=True, max_length=20, choices=[(u'srt', u'SubRip'), (u'sjson', u'SRT JSON')])),
('fmt', models.CharField(db_index=True, max_length=20, choices=[('srt', 'SubRip'), ('sjson', 'SRT JSON')])),
('language', models.CharField(max_length=8, db_index=True)),
('content', models.TextField(default=u'')),
('content', models.TextField(default='')),
],
),
migrations.CreateModel(
name='Video',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(auto_now_add=True)),
('edx_video_id', models.CharField(unique=True, max_length=100, validators=[django.core.validators.RegexValidator(regex=u'^[a-zA-Z0-9\\-_]*$', message=u'edx_video_id has invalid characters', code=u'invalid edx_video_id')])),
('edx_video_id', models.CharField(unique=True, max_length=100, validators=[django.core.validators.RegexValidator(regex='^[a-zA-Z0-9\\-_]*$', message='edx_video_id has invalid characters', code='invalid edx_video_id')])),
('client_video_id', models.CharField(db_index=True, max_length=255, blank=True)),
('duration', models.FloatField(validators=[django.core.validators.MinValueValidator(0)])),
('status', models.CharField(max_length=255, db_index=True)),
Expand Down Expand Up @@ -82,6 +79,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='coursevideo',
unique_together=set([('course_id', 'video')]),
unique_together={('course_id', 'video')},
),
]
3 changes: 0 additions & 3 deletions edxval/migrations/0002_data__default_profiles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations, models

DEFAULT_PROFILES = [
Expand Down
5 changes: 1 addition & 4 deletions edxval/migrations/0003_coursevideo_is_hidden.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations, models


Expand All @@ -14,6 +11,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='coursevideo',
name='is_hidden',
field=models.BooleanField(default=False, help_text=u'Hide video for course.'),
field=models.BooleanField(default=False, help_text='Hide video for course.'),
),
]
2 changes: 1 addition & 1 deletion edxval/migrations/0003_delete_transcriptcredentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterUniqueTogether(
name='TranscriptCredentials',
unique_together=set([]),
unique_together=set(),
),
migrations.DeleteModel(
name='TranscriptCredentials',
Expand Down
3 changes: 0 additions & 3 deletions edxval/migrations/0004_data__add_hls_profile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations, models

HLS_PROFILE = 'hls'
Expand Down
3 changes: 0 additions & 3 deletions edxval/migrations/0005_videoimage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.utils.timezone
import edxval.models
import model_utils.fields
Expand Down
25 changes: 11 additions & 14 deletions edxval/migrations/0006_auto_20171009_0725.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


import django.utils.timezone
import edxval.models
import model_utils.fields
Expand All @@ -20,13 +17,13 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('course_id', models.CharField(unique=True, max_length=255, verbose_name=u'Course ID')),
('provider', models.CharField(max_length=20, verbose_name=u'Provider', choices=[(u'Custom', u'Custom'), (u'3PlayMedia', u'3PlayMedia'), (u'Cielo24', u'Cielo24')])),
('cielo24_fidelity', models.CharField(blank=True, max_length=20, null=True, verbose_name=u'Cielo24 Fidelity', choices=[(u'MECHANICAL', u'Mechanical, 75% Accuracy'), (u'PREMIUM', u'Premium, 95% Accuracy'), (u'PROFESSIONAL', u'Professional, 99% Accuracy')])),
('cielo24_turnaround', models.CharField(blank=True, max_length=20, null=True, verbose_name=u'Cielo24 Turnaround', choices=[(u'STANDARD', u'Standard, 48h'), (u'PRIORITY', u'Priority, 24h')])),
('three_play_turnaround', models.CharField(blank=True, max_length=20, null=True, verbose_name=u'3PlayMedia Turnaround', choices=[(u'extended_service', u'10-Day/Extended'), (u'default', u'4-Day/Default'), (u'expedited_service', u'2-Day/Expedited'), (u'rush_service', u'24 hour/Rush'), (u'same_day_service', u'Same Day')])),
('preferred_languages', edxval.models.ListField(default=[], verbose_name=u'Preferred Languages', max_items=50, blank=True)),
('video_source_language', models.CharField(help_text=u'This specifies the speech language of a Video.', max_length=50, null=True, verbose_name=u'Video Source Language', blank=True)),
('course_id', models.CharField(unique=True, max_length=255, verbose_name='Course ID')),
('provider', models.CharField(max_length=20, verbose_name='Provider', choices=[('Custom', 'Custom'), ('3PlayMedia', '3PlayMedia'), ('Cielo24', 'Cielo24')])),
('cielo24_fidelity', models.CharField(blank=True, max_length=20, null=True, verbose_name='Cielo24 Fidelity', choices=[('MECHANICAL', 'Mechanical, 75% Accuracy'), ('PREMIUM', 'Premium, 95% Accuracy'), ('PROFESSIONAL', 'Professional, 99% Accuracy')])),
('cielo24_turnaround', models.CharField(blank=True, max_length=20, null=True, verbose_name='Cielo24 Turnaround', choices=[('STANDARD', 'Standard, 48h'), ('PRIORITY', 'Priority, 24h')])),
('three_play_turnaround', models.CharField(blank=True, max_length=20, null=True, verbose_name='3PlayMedia Turnaround', choices=[('extended_service', '10-Day/Extended'), ('default', '4-Day/Default'), ('expedited_service', '2-Day/Expedited'), ('rush_service', '24 hour/Rush'), ('same_day_service', 'Same Day')])),
('preferred_languages', edxval.models.ListField(default=[], verbose_name='Preferred Languages', max_items=50, blank=True)),
('video_source_language', models.CharField(help_text='This specifies the speech language of a Video.', max_length=50, null=True, verbose_name='Video Source Language', blank=True)),
],
options={
'abstract': False,
Expand All @@ -38,15 +35,15 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('video_id', models.CharField(help_text=u'It can be an edx_video_id or an external video id', max_length=255)),
('video_id', models.CharField(help_text='It can be an edx_video_id or an external video id', max_length=255)),
('transcript', edxval.models.CustomizableFileField(null=True, blank=True)),
('language_code', models.CharField(max_length=50, db_index=True)),
('provider', models.CharField(default=u'Custom', max_length=30, choices=[(u'Custom', u'Custom'), (u'3PlayMedia', u'3PlayMedia'), (u'Cielo24', u'Cielo24')])),
('file_format', models.CharField(db_index=True, max_length=20, choices=[(u'srt', u'SubRip'), (u'sjson', u'SRT JSON')])),
('provider', models.CharField(default='Custom', max_length=30, choices=[('Custom', 'Custom'), ('3PlayMedia', '3PlayMedia'), ('Cielo24', 'Cielo24')])),
('file_format', models.CharField(db_index=True, max_length=20, choices=[('srt', 'SubRip'), ('sjson', 'SRT JSON')])),
],
),
migrations.AlterUniqueTogether(
name='videotranscript',
unique_together=set([('video_id', 'language_code')]),
unique_together={('video_id', 'language_code')},
),
]
9 changes: 4 additions & 5 deletions edxval/migrations/0007_transcript_credentials_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-10-10 08:15


Expand All @@ -20,13 +19,13 @@ class Migration(migrations.Migration):
('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=u'Course Organization')),
('provider', models.CharField(choices=[(u'Custom', u'Custom'), (u'3PlayMedia', u'3PlayMedia'), (u'Cielo24', u'Cielo24')], max_length=20, verbose_name=u'Transcript Provider')),
('exists', models.BooleanField(default=False, help_text=u'Transcript credentials state')),
('org', models.CharField(max_length=32, verbose_name='Course Organization')),
('provider', models.CharField(choices=[('Custom', 'Custom'), ('3PlayMedia', '3PlayMedia'), ('Cielo24', 'Cielo24')], max_length=20, verbose_name='Transcript Provider')),
('exists', models.BooleanField(default=False, help_text='Transcript credentials state')),
],
),
migrations.AlterUniqueTogether(
name='thirdpartytranscriptcredentialsstate',
unique_together=set([('org', 'provider')]),
unique_together={('org', 'provider')},
),
]
3 changes: 0 additions & 3 deletions edxval/migrations/0008_remove_subtitles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations, models


Expand Down
3 changes: 1 addition & 2 deletions edxval/migrations/0009_auto_20171127_0406.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-27 09:06


Expand All @@ -15,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='transcriptpreference',
name='three_play_turnaround',
field=models.CharField(blank=True, choices=[(u'extended', u'10-Day/Extended'), (u'standard', u'4-Day/Standard'), (u'expedited', u'2-Day/Expedited'), (u'rush', u'24 hour/Rush'), (u'same_day', u'Same Day'), (u'two_hour', u'2 Hour')], max_length=20, null=True, verbose_name=u'3PlayMedia Turnaround'),
field=models.CharField(blank=True, choices=[('extended', '10-Day/Extended'), ('standard', '4-Day/Standard'), ('expedited', '2-Day/Expedited'), ('rush', '24 hour/Rush'), ('same_day', 'Same Day'), ('two_hour', '2 Hour')], max_length=20, null=True, verbose_name='3PlayMedia Turnaround'),
),
]
7 changes: 2 additions & 5 deletions edxval/migrations/0010_add_video_as_foreign_key.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


from django.db import migrations, models


Expand All @@ -13,7 +10,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterUniqueTogether(
name='videotranscript',
unique_together=set([('language_code',)]),
unique_together={('language_code',)},
),
migrations.RemoveField(
model_name='videotranscript',
Expand All @@ -26,6 +23,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='videotranscript',
unique_together=set([('video', 'language_code')]),
unique_together={('video', 'language_code')},
),
]
Loading

0 comments on commit cd54e79

Please sign in to comment.