Skip to content

Commit 433b3ef

Browse files
Merge pull request #47 from edx/hammad/ENT-4156
ENT-4156 | Update taxonomy models to pull skill tag descriptions
2 parents ce33e15 + 561f6bc commit 433b3ef

File tree

14 files changed

+334
-88
lines changed

14 files changed

+334
-88
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Change Log
1414
Unreleased
1515
--------------------
1616

17+
[1.4.1] - 2021-02-19
18+
--------------------
19+
20+
* added description field in Skill model and update the refresh_course_skill command to save skill description.
21+
* Pinning EMSI skills API version to 7.35
22+
1723
[1.4.0] - 2021-02-17
1824
--------------------
1925

taxonomy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
# 2. MINOR version when you add functionality in a backwards compatible manner, and
1616
# 3. PATCH version when you make backwards compatible bug fixes.
1717
# More details can be found at https://semver.org/
18-
__version__ = '1.4.0'
18+
__version__ = '1.4.1'
1919

2020
default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name

taxonomy/emsi_client.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class EMSISkillsApiClient(JwtEMSIApiClient):
115115
Object builds an API client to make calls to get the skills from course text data.
116116
"""
117117

118-
API_BASE_URL = JwtEMSIApiClient.API_BASE_URL + '/skills'
118+
API_BASE_URL = JwtEMSIApiClient.API_BASE_URL + '/skills/versions/7.35'
119119

120120
def __init__(self):
121121
"""
@@ -134,12 +134,11 @@ def get_course_skills(self, course_text_data):
134134
Returns:
135135
dict: A dictionary containing details of all the skills.
136136
"""
137+
data = {
138+
'text': course_text_data
139+
}
137140
try:
138-
data = {
139-
'text': course_text_data
140-
}
141-
response = self.client.versions.latest.extract.post(data)
142-
141+
response = self.client.extract.post(data)
143142
return self.traverse_data(response)
144143
except (SlumberBaseException, ConnectionError, Timeout) as error:
145144
LOGGER.exception(
@@ -153,6 +152,15 @@ def traverse_data(response):
153152
"""
154153
Transform data to a more useful format.
155154
"""
155+
for skill_details in response['data']:
156+
# append skill description in skill data extracted from "wikipediaExtract" tag
157+
try:
158+
desc = next(tag['value'] for tag in skill_details['skill']['tags'] if tag['key'] == 'wikipediaExtract')
159+
except StopIteration:
160+
LOGGER.warning('[TAXONOMY] "wikipediaExtract" key not found in skill: %s', skill_details['skill']['id'])
161+
desc = ''
162+
skill_details['skill']['description'] = desc
163+
156164
return response
157165

158166

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.18 on 2021-02-19 03:46
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('taxonomy', '0008_auto_20210216_0710'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='skill',
15+
name='description',
16+
field=models.TextField(blank=True, default='', help_text='A short description for the skill received from API.'),
17+
),
18+
]

taxonomy/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Skill(TimeStampedModel):
3535
'The name of the skill.'
3636
)
3737
)
38+
description = models.TextField(
39+
blank=True,
40+
help_text='A short description for the skill received from API.',
41+
default='',
42+
)
3843
info_url = models.URLField(
3944
verbose_name=_('Skill Information URL'),
4045
blank=True,

taxonomy/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
LOGGER = logging.getLogger(__name__)
1212

1313

14-
def update_skills_data(course_key, confidence, skill_data):
14+
def update_skills_data(course_key, skill_external_id, confidence, skill_data):
1515
"""
1616
Persist the skills data in the database.
1717
"""
18-
skill, __ = Skill.objects.update_or_create(**skill_data)
18+
skill, __ = Skill.objects.update_or_create(external_id=skill_external_id, defaults=skill_data)
1919

2020
if not is_course_skill_blacklisted(course_key, skill.id):
2121
CourseSkills.objects.update_or_create(
@@ -42,15 +42,16 @@ def process_skills_data(course, course_skills, should_commit_to_db):
4242
try:
4343
confidence = float(record['confidence'])
4444
skill = record['skill']
45+
skill_external_id = skill['id']
4546
skill_data = {
46-
'external_id': skill['id'],
4747
'name': skill['name'],
4848
'info_url': skill['infoUrl'],
4949
'type_id': skill['type']['id'],
5050
'type_name': skill['type']['name'],
51+
'description': skill['description']
5152
}
5253
if should_commit_to_db:
53-
update_skills_data(course['key'], confidence, skill_data)
54+
update_skills_data(course['key'], skill_external_id, confidence, skill_data)
5455
except KeyError:
5556
LOGGER.error('[TAXONOMY] Missing keys in skills data for course_key: %s', course['key'])
5657
failures.add((course['uuid'], course['key']))

test_utils/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Meta:
2929
info_url = factory.LazyAttribute(lambda x: FAKER.uri())
3030
type_id = factory.LazyAttribute(lambda x: FAKER.slug())
3131
type_name = factory.LazyAttribute(lambda x: FAKER.text(max_nb_chars=20))
32+
description = factory.LazyAttribute(lambda x: FAKER.text(max_nb_chars=200))
3233

3334

3435
# pylint: disable=no-member

0 commit comments

Comments
 (0)