diff options
author | ankitjavalkar | 2017-11-15 16:50:24 +0530 |
---|---|---|
committer | ankitjavalkar | 2018-01-04 11:37:20 +0530 |
commit | c883413f4e7ef4642f9d18a0d383612f6abd9391 (patch) | |
tree | 7029aadd60d8fa6aa14b4c4bd20efd7bbdafe244 | |
parent | feb295b4107a95621e9430f5c7042cfde4674cc0 (diff) | |
download | online_test-c883413f4e7ef4642f9d18a0d383612f6abd9391.tar.gz online_test-c883413f4e7ef4642f9d18a0d383612f6abd9391.tar.bz2 online_test-c883413f4e7ef4642f9d18a0d383612f6abd9391.zip |
- Add python-decouple package to requirements
- Use sane defaults and python-decouple in yaksh.settings module
- Replace hard coded localhost domain name referring to code server with dynamic settings variable
-rw-r--r-- | online_test/settings.py | 16 | ||||
-rw-r--r-- | requirements/requirements-codeserver.txt | 1 | ||||
-rw-r--r-- | yaksh/models.py | 10 | ||||
-rw-r--r-- | yaksh/settings.py | 11 | ||||
-rw-r--r-- | yaksh/views.py | 7 |
5 files changed, 29 insertions, 16 deletions
diff --git a/online_test/settings.py b/online_test/settings.py index 790083e..3cd36a4 100644 --- a/online_test/settings.py +++ b/online_test/settings.py @@ -8,8 +8,10 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """ from yaksh.pipeline.settings import AUTH_PIPELINE -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +from decouple import config + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # The directory where user data can be saved. This directory will be @@ -21,12 +23,11 @@ OUTPUT_DIR = os.path.join(BASE_DIR, "yaksh_data", "output") # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '0=fsi3g5dw*7ze1cyh441_e^5^$2ay@&z(5(n7mhir0xb267=6' +SECRET_KEY = config('SECRET_KEY', default='dUmMy_s3cR3t_k3y')#'0=fsi3g5dw*7ze1cyh441_e^5^$2ay@&z(5(n7mhir0xb267=6' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True - ALLOWED_HOSTS = [] URL_ROOT = '' @@ -67,8 +68,13 @@ WSGI_APPLICATION = 'online_test.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + #'ENGINE': 'django.db.backends.sqlite3', + 'ENGINE': 'django.db.backends.{0}'.format( + config('DB_ENGINE', default='sqlite3') + ), + 'NAME': config('DB_NAME', default=os.path.join(BASE_DIR, 'db.sqlite3')) + #os.path.join(BASE_DIR, 'db.sqlite3'), + }, } diff --git a/requirements/requirements-codeserver.txt b/requirements/requirements-codeserver.txt index a4f419c..e9585fa 100644 --- a/requirements/requirements-codeserver.txt +++ b/requirements/requirements-codeserver.txt @@ -1,4 +1,5 @@ pytest +python-decouple six requests tornado diff --git a/yaksh/models.py b/yaksh/models.py index 1d24bda..bc0b4f1 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -29,10 +29,10 @@ import tempfile from textwrap import dedent from ast import literal_eval from .file_utils import extract_files, delete_files -from yaksh.code_server import(submit, - get_result as get_result_from_code_server - ) -from yaksh.settings import SERVER_POOL_PORT +from yaksh.code_server import ( + submit, get_result as get_result_from_code_server +) +from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from django.conf import settings from django.forms.models import model_to_dict @@ -1705,7 +1705,7 @@ class AnswerPaper(models.Model): elif question.type == 'code' or question.type == "upload": user_dir = self.user.profile.get_user_dir() - url = 'http://localhost:%s' % server_port + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) submit(url, uid, json_data, user_dir) result = {'uid': uid, 'status': 'running'} return result diff --git a/yaksh/settings.py b/yaksh/settings.py index d500d93..e414e75 100644 --- a/yaksh/settings.py +++ b/yaksh/settings.py @@ -2,16 +2,21 @@ settings for yaksh app. """ +from decouple import config + # The number of code server processes to run.. -N_CODE_SERVERS = 5 +N_CODE_SERVERS = config('N_CODE_SERVERS', default=5, cast=int) # The server pool port. This is the server which returns available server # ports so as to minimize load. This is some random number where no other # service is running. It should be > 1024 and less < 65535 though. -SERVER_POOL_PORT = 53579 +SERVER_POOL_PORT = config('EMAIL_PORT', default=55555, cast=int) + +SERVER_HOST_NAME = config('SERVER_HOST_NAME', default='http://localhost') +#'localhost' # Timeout for the code to run in seconds. This is an integer! -SERVER_TIMEOUT = 4 +SERVER_TIMEOUT = config('SERVER_TIMEOUT', default=4, cast=int) # The root of the URL, for example you might be in the situation where you # are not hosted as host.org/exam/ but as host.org/foo/exam/ for whatever diff --git a/yaksh/views.py b/yaksh/views.py index a4d9e78..a001ffd 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -35,7 +35,7 @@ except ImportError: from io import BytesIO as string_io import re # Local imports. -from yaksh.code_server import get_result as get_result_from_code_server, SERVER_POOL_PORT +from yaksh.code_server import get_result as get_result_from_code_server, from yaksh.models import ( Answer, AnswerPaper, AssignmentUpload, Course, FileUpload, FloatTestCase, HookTestCase, IntegerTestCase, McqTestCase, Profile, @@ -51,6 +51,7 @@ from yaksh.forms import ( UploadFileForm, get_object_form, FileForm, QuestionPaperForm, LessonForm, LessonFileForm, LearningModuleForm, ExerciseForm ) +from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .settings import URL_ROOT from .file_utils import extract_files, is_csv from .send_emails import send_user_mail, generate_activation_key, send_bulk_mail @@ -782,7 +783,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, ) if current_question.type in ['code', 'upload']: if paper.time_left() <= 0 and not paper.question_paper.quiz.is_exercise: - url = 'http://localhost:%s' % SERVER_POOL_PORT + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) result_details = get_result_from_code_server(url, uid, block=True) result = json.loads(result_details.get('result')) next_question, error_message, paper = _update_paper(request, uid, @@ -807,7 +808,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, @csrf_exempt def get_result(request, uid, course_id, module_id): result = {} - url = 'http://localhost:%s' % SERVER_POOL_PORT + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) result_state = get_result_from_code_server(url, uid) result['status'] = result_state.get('status') if result['status'] == 'done': |