Skip to content

Commit

Permalink
Merge pull request #65 from edx/hammad/ENT-4141
Browse files Browse the repository at this point in the history
ENT-4141: Added APIs for taxonomy connector models.
  • Loading branch information
HammadAhmadWaqas authored Aug 10, 2021
2 parents 5e2b0bc + 54083d3 commit 350e6c3
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 4 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ omit =
*admin.py
*static*
*templates*
*urls.py
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Change Log
Unreleased
--------------------

[1.13.0] - 2021-08-9
---------------------

* Added Skill, Job and JobPostings viewsets.

[1.12.2] - 2021-08-5
---------------------

Expand Down
20 changes: 17 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ To install ``taxonomy-connector``, for example, in Course Discovery, follow thes
#. Changes made into the taxonomy repository will now be picked up by your host environment.


Note:
In order to communicate with EMSI service, you need to set the values of ``client_id`` and ``client_secret``. These values are picked up from the host environment so you need to pass them in ``.yaml`` file of the host environment.
Notes:

- In order to communicate with EMSI service, you need to set the values of ``client_id`` and ``client_secret``. These values are picked up from the host environment so you need to pass them in ``.yaml`` file of the host environment.
- Also, to make taxonomy work, the host platform must add an implementation of data providers written in ``./taxonomy/providers``
- Taxonomy APIs use throttle rate set in ``DEFAULT_THROTTLE_RATES`` settings by default. Custom Throttle rate can by set by adding ``ScopedRateThrottle`` class in ``DEFAULT_THROTTLE_CLASSES`` settings and ``taxonomy-api-throttle-scope`` key in ``DEFAULT_THROTTLE_RATES``

Also, to make taxonomy work, the host platform must add an implementation of data providers written in ``./taxonomy/providers``

.. code-block:: python
REST_FRAMEWORK = {
'DEFAULT_THROTTLE_CLASSES': (
'rest_framework.throttling.UserRateThrottle',
'rest_framework.throttling.ScopedRateThrottle'
),
'DEFAULT_THROTTLE_RATES': {
'user': '100/hour',
'taxonomy-api-throttle-scope': '60/min', # custom throttle rate for taxonomy api
},
}
Developer Notes
Expand Down
2 changes: 1 addition & 1 deletion taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# 2. MINOR version when you add functionality in a backwards compatible manner, and
# 3. PATCH version when you make backwards compatible bug fixes.
# More details can be found at https://semver.org/
__version__ = '1.12.2'
__version__ = '1.13.0'

default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name
8 changes: 8 additions & 0 deletions taxonomy/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Taxonomy v1 API URLs.
"""
from django.urls import include, path

urlpatterns = [
path('v1/', include('taxonomy.api.v1.urls')),
]
61 changes: 61 additions & 0 deletions taxonomy/api/v1/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Taxonomy API serializers.
"""
from rest_framework.serializers import ModelSerializer

from taxonomy.models import CourseSkills, Job, JobPostings, JobSkills, Skill


class JobSerializer(ModelSerializer):

class Meta:
model = Job
fields = '__all__'


class SkillSerializer(ModelSerializer):

class Meta:
model = Skill
fields = '__all__'


class JobSkillSerializer(ModelSerializer):
skill = SkillSerializer()

class Meta:
model = JobSkills
exclude = ('id', 'created', 'modified', 'job')


class JobsListSerializer(ModelSerializer):
skills = JobSkillSerializer(source='jobskills_set.all', many=True)

class Meta:
model = Job
fields = '__all__'
extra_fields = ('skills',)


class CourseSkillsSerializer(ModelSerializer):

class Meta:
model = CourseSkills
exclude = ('id', 'created', 'modified', 'is_blacklisted', 'skill')


class SkillListSerializer(ModelSerializer):
courses = CourseSkillsSerializer(source='courseskills_set.all', many=True)

class Meta:
model = Skill
fields = '__all__'
extra_fields = ('courses',)


class JobPostingsSerializer(ModelSerializer):
job = JobSerializer()

class Meta:
model = JobPostings
fields = '__all__'
13 changes: 13 additions & 0 deletions taxonomy/api/v1/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Taxonomy v1 API URLs.
"""
from rest_framework.routers import DefaultRouter

from taxonomy.api.v1.views import JobPostingsViewSet, JobsViewSet, SkillViewSet

router = DefaultRouter()
router.register(r'skills', SkillViewSet, basename='skill')
router.register(r'jobs', JobsViewSet, basename='job')
router.register(r'jobpostings', JobPostingsViewSet, basename='jobposting')

urlpatterns = router.urls
68 changes: 68 additions & 0 deletions taxonomy/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Taxonomy API views.
"""
from rest_framework import permissions
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.viewsets import GenericViewSet

from django.db.models import Prefetch

from taxonomy.api.v1.serializers import JobPostingsSerializer, JobsListSerializer, SkillListSerializer
from taxonomy.models import CourseSkills, Job, JobPostings, Skill


class TaxonomyAPIViewSetMixin:
"""
Taxonomy APIs ViewSet Mixin.
"""
permission_classes = (permissions.IsAuthenticated,)
throttle_scope = 'taxonomy-api-throttle-scope'


class SkillViewSet(TaxonomyAPIViewSetMixin, RetrieveModelMixin, ListModelMixin, GenericViewSet):
"""
ViewSet to list and retrieve all Skills in the system.
"""

serializer_class = SkillListSerializer

def get_queryset(self):
"""
Get all the skills with prefetch_related objects.
"""
return Skill.objects.all().prefetch_related(
Prefetch(
'courseskills_set',
queryset=CourseSkills.objects.filter(is_blacklisted=False)
)
)


class JobsViewSet(TaxonomyAPIViewSetMixin, RetrieveModelMixin, ListModelMixin, GenericViewSet):
"""
ViewSet to list and retrieve all Jobs in the system.
"""
serializer_class = JobsListSerializer

def get_queryset(self):
"""
Get all the jobs with prefetch_related objects.
"""
return Job.objects.all().prefetch_related(
'jobskills_set', 'jobskills_set__skill'
)


class JobPostingsViewSet(TaxonomyAPIViewSetMixin, RetrieveModelMixin, ListModelMixin, GenericViewSet):
"""
ViewSet to list and retrieve all JobPostings in the system.
"""
serializer_class = JobPostingsSerializer

def get_queryset(self):
"""
Get all the jobpostings with prefetch_related objects.
"""
return JobPostings.objects.all().select_related(
'job'
)
8 changes: 8 additions & 0 deletions taxonomy/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Taxonomy v1 API URLs.
"""
from django.urls import include, path

urlpatterns = [
path('api/', include('taxonomy.api.urls')),
]

0 comments on commit 350e6c3

Please sign in to comment.