-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from edx/hammad/ENT-4141
ENT-4141: Added APIs for taxonomy connector models.
- Loading branch information
Showing
9 changed files
with
182 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ omit = | |
*admin.py | ||
*static* | ||
*templates* | ||
*urls.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
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,8 @@ | ||
""" | ||
Taxonomy v1 API URLs. | ||
""" | ||
from django.urls import include, path | ||
|
||
urlpatterns = [ | ||
path('v1/', include('taxonomy.api.v1.urls')), | ||
] |
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,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__' |
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,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 |
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,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' | ||
) |
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,8 @@ | ||
""" | ||
Taxonomy v1 API URLs. | ||
""" | ||
from django.urls import include, path | ||
|
||
urlpatterns = [ | ||
path('api/', include('taxonomy.api.urls')), | ||
] |