-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'openedx:master' into aht007/Ansible-to-Docker
- Loading branch information
Showing
22 changed files
with
767 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import logging | ||
import re | ||
|
||
from django.conf import settings | ||
from google.oauth2.service_account import Credentials | ||
from googleapiclient.discovery import build | ||
|
||
from course_discovery.apps.course_metadata.constants import GOOGLE_CLIENT_API_SCOPE | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class GoogleAPIClient: | ||
""" | ||
API Client for Google API to communicate with drive files | ||
""" | ||
|
||
def __init__(self): | ||
try: | ||
credentials = Credentials.from_service_account_info( | ||
settings.GOOGLE_SERVICE_ACCOUNT_CREDENTIALS, scopes=GOOGLE_CLIENT_API_SCOPE | ||
) | ||
credentials = credentials.with_subject(settings.LOADER_INGESTION_CONTACT_EMAIL) | ||
self.service = build('drive', 'v3', credentials=credentials) | ||
logger.info('[Connection Successful]: Successful connection with google service account') | ||
except Exception as ex: # pylint: disable=broad-except | ||
logger.exception(f'[Connection Failed]: Failed to connect with google service account error_message: {ex}') | ||
|
||
def get_file_metadata(self, url): | ||
try: | ||
file_id = self.get_file_id_from_url(url) | ||
file = self.service.files().get(fileId=file_id).execute() # pylint: disable=no-member | ||
logger.info(f'[File Found]: Found google file {file_id} on requesting {url}') | ||
return file | ||
except Exception as ex: # pylint: disable=broad-except | ||
logger.exception(f'[File Not Found]: No file found for id: {file_id} error_message: {ex}') | ||
return None | ||
|
||
@staticmethod | ||
def get_file_id_from_url(url): | ||
match = re.search(r'id=(\w+)', url) or re.search(r'/(?:file/d/|uc\?id=)([-\w]{25,})(?:[&/]|$)', url) | ||
return match.group(1) if match else None | ||
|
||
def download_file_by_url(self, url): | ||
content = None | ||
try: | ||
file_id = self.get_file_id_from_url(url) | ||
request = self.service.files().get_media(fileId=file_id) # pylint: disable=no-member | ||
content = request.execute() | ||
logger.info(f'[File Downloaded]: Downloading google file {file_id}') | ||
except Exception as ex: # pylint: disable=broad-except | ||
logger.exception(f'[File Not Downloaded]: No file found for id: {file_id} error_message: {ex}') | ||
return content |
50 changes: 50 additions & 0 deletions
50
course_discovery/apps/course_metadata/migrations/0308_auto_20230111_1300.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 3.2.16 on 2023-01-11 13:00 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django_extensions.db.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('course_metadata', '0307_additional_metadata_end_date'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Source', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), | ||
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), | ||
('name', models.CharField(help_text='Name of the external source.', max_length=255)), | ||
('slug', django_extensions.db.fields.AutoSlugField(blank=True, editable=False, help_text='Leave this field blank to have the value generated automatically.', populate_from='name')), | ||
('description', models.CharField(blank=True, help_text='Description of the external source.', max_length=255)), | ||
], | ||
options={ | ||
'get_latest_by': 'modified', | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='course', | ||
name='product_source', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='courses', to='course_metadata.source'), | ||
), | ||
migrations.AddField( | ||
model_name='historicalcourse', | ||
name='product_source', | ||
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='course_metadata.source'), | ||
), | ||
migrations.AddField( | ||
model_name='historicalprogram', | ||
name='product_source', | ||
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='course_metadata.source'), | ||
), | ||
migrations.AddField( | ||
model_name='program', | ||
name='product_source', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='programs', to='course_metadata.source'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
...ery/apps/course_metadata/migrations/0309_alter_additionalmetadata_course_term_override.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.16 on 2023-01-17 20:18 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('course_metadata', '0308_auto_20230111_1300'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='additionalmetadata', | ||
name='course_term_override', | ||
field=models.CharField(blank=True, default=None, help_text='This field allows for override the default course term', max_length=20, null=True, verbose_name='Course override'), | ||
), | ||
] |
Oops, something went wrong.