Skip to content

Commit

Permalink
Send the Accept-Language header all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave St.Germain committed Nov 29, 2018
1 parent 11726a1 commit e5dc501
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Proctoring System configuration endpoint
}

The keys in the rules object should be machine readable. The values are human readable. PS should respect the HTTP request ``Accept-Language``
header and translate all human readable rules into the requested language.
header and translate all human readable rules and instructions into the requested language.

If a download_url is included in the response, Open edX will redirect learners to the address before the proctoring session starts. The address will include ``attempt={attempt_id}`` in the query string.

Expand Down
11 changes: 7 additions & 4 deletions edx_proctoring/backends/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,20 @@ def get_instructor_url(self, course_id, user, exam_id=None, attempt_id=None):

def _get_language_headers(self):
"""
Makes the Accept-Language header based on the currently active language
Returns a dictionary of the Accept-Language headers
"""
# This import is here because developers writing backends which subclass this class
# may want to import this module and use the other methods, without having to run in the context
# of django settings, etc.
from django.conf import settings
from django.utils.translation import get_language

headers = {}
current_lang = get_language()
default_lang = settings.LANGUAGE_CODE
lang_header = default_lang
if current_lang and current_lang != default_lang:
headers['Accept-Language'] = '{};{}'.format(current_lang, default_lang)
return headers
lang_header = '{};{}'.format(current_lang, default_lang)
return {'Accept-Language': lang_header}

def _make_attempt_request(self, exam, attempt, method='POST', status=None, **payload):
"""
Expand Down
3 changes: 2 additions & 1 deletion edx_proctoring/backends/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import responses

from django.test import TestCase
from django.utils.translation import activate

from edx_proctoring.backends.rest import BaseRestProctoringProvider

Expand Down Expand Up @@ -88,10 +89,10 @@ def test_get_attempt(self):
)
external_attempt = self.provider.get_attempt(attempt)
self.assertEqual(external_attempt, attempt)
self.assertEqual(responses.calls[1].request.headers['Accept-Language'], 'en-us')

@responses.activate
def test_get_attempt_i18n(self):
from django.utils.translation import activate
activate('es')
attempt = {
'id': 1,
Expand Down

0 comments on commit e5dc501

Please sign in to comment.