This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #6 from edx-solutions/aamishbaloch/YONK-852
YONK-852: Course Settings added to provide support to set language
- Loading branch information
Showing
7 changed files
with
176 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
import openedx.core.djangoapps.xmodule_django.models | ||
import model_utils.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('course_metadata', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CourseSetting', | ||
fields=[ | ||
('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)), | ||
('id', openedx.core.djangoapps.xmodule_django.models.CourseKeyField(max_length=255, serialize=False, primary_key=True)), | ||
('languages', models.TextField(help_text=b'A comma-separated list of language codes to release to the public.', blank=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.AlterField( | ||
model_name='courseaggregatedmetadata', | ||
name='id', | ||
field=openedx.core.djangoapps.xmodule_django.models.CourseKeyField(max_length=255, serialize=False, primary_key=True), | ||
), | ||
] |
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,25 @@ | ||
import ast | ||
|
||
from rest_framework import serializers | ||
from openedx.core.lib.api.serializers import CourseKeyField | ||
from course_metadata.models import CourseSetting | ||
|
||
|
||
class StringListField(serializers.ListField): | ||
child = serializers.CharField(max_length=255) | ||
|
||
def to_representation(self, data): | ||
""" | ||
List of object instances -> List of dicts of primitive datatypes. | ||
""" | ||
if isinstance(data, basestring): | ||
data = ast.literal_eval(data) | ||
return data | ||
|
||
|
||
class CourseSettingSerializer(serializers.ModelSerializer): | ||
id = CourseKeyField(required=False) | ||
languages = StringListField() | ||
|
||
class Meta: | ||
model = CourseSetting |
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,15 @@ | ||
from django.conf import settings | ||
from django.conf.urls import patterns, url | ||
|
||
from . import views | ||
|
||
COURSE_ID_PATTERN = settings.COURSE_ID_PATTERN | ||
|
||
urlpatterns = patterns( | ||
'', | ||
url( | ||
r'^{}/settings$'.format(COURSE_ID_PATTERN), | ||
views.CourseSettingView.as_view(), | ||
name='additional-course-settings', | ||
), | ||
) |
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,36 @@ | ||
from opaque_keys.edx.keys import CourseKey | ||
from edx_solutions_api_integration.permissions import SecureRetrieveUpdateAPIView | ||
from course_metadata.models import CourseSetting | ||
from course_metadata.serializers import CourseSettingSerializer | ||
|
||
|
||
class CourseSettingView(SecureRetrieveUpdateAPIView): | ||
""" | ||
**Use Case** | ||
Create course settings | ||
**Example Requests** | ||
POST /api/server/courses_metadata/{course_id}/settings | ||
**Request Params** | ||
**POST** | ||
-id: course id | ||
-langauges: A comma-separated list of language codes. Example: ['it', 'de-at', 'es', 'pt-br'] | ||
**Response Values** | ||
**POST** | ||
If the request is successful, the request returns an HTTP 200 "OK" response. | ||
""" | ||
serializer_class = CourseSettingSerializer | ||
queryset = CourseSetting.objects.all() | ||
|
||
def get_object(self): | ||
course_id = CourseKey.from_string(self.kwargs['course_id']) | ||
setting, __ = CourseSetting.objects.get_or_create(id=course_id) | ||
return setting |
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