diff options
author | Prabhu Ramachandran | 2016-04-13 16:58:00 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-04-13 16:58:00 +0530 |
commit | 97bdb23fbacc3e625beb96efdf58431f42604a81 (patch) | |
tree | 06d3cd76a3f38b4ceb8ba7e93d64db12ba9f5b7f | |
parent | 2dfef7f76cb04b34901650dc9ae0f41ef394d6ba (diff) | |
parent | 523390f284b93e10af35058931b06eed1550700c (diff) | |
download | online_test-97bdb23fbacc3e625beb96efdf58431f42604a81.tar.gz online_test-97bdb23fbacc3e625beb96efdf58431f42604a81.tar.bz2 online_test-97bdb23fbacc3e625beb96efdf58431f42604a81.zip |
Merge pull request #91 from prathamesh920/migration_to_django_1_9
Migration from django 1.6 to django 1.9
-rw-r--r-- | online_test/settings.py | 16 | ||||
-rw-r--r-- | online_test/urls.py | 4 | ||||
-rw-r--r-- | requirements.txt | 4 | ||||
-rw-r--r-- | setup.py | 4 | ||||
-rw-r--r-- | yaksh/forms.py | 5 | ||||
-rw-r--r-- | yaksh/models.py | 2 | ||||
-rw-r--r-- | yaksh/tests.py | 2 | ||||
-rw-r--r-- | yaksh/urls.py | 114 | ||||
-rw-r--r-- | yaksh/views.py | 10 |
9 files changed, 85 insertions, 76 deletions
diff --git a/online_test/settings.py b/online_test/settings.py index 3993744..adc3dc3 100644 --- a/online_test/settings.py +++ b/online_test/settings.py @@ -22,7 +22,6 @@ SECRET_KEY = '0=fsi3g5dw*7ze1cyh441_e^5^$2ay@&z(5(n7mhir0xb267=6' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] @@ -69,7 +68,6 @@ DATABASES = { # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ -AUTH_PROFILE_MODULE = 'yaksh.Profile' LANGUAGE_CODE = 'en-us' @@ -99,4 +97,16 @@ EMAIL_HOST_USER = 'email_host_user' DEFAULT_FROM_EMAIL = EMAIL_HOST_USER -TEMPLATE_DIRS = ['yaksh/templates',] +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'DIRS': '[yaksh/templates]', + 'OPTIONS': { + 'context_processors': [ + 'django.contrib.auth.context_processors.auth', + ], + 'debug': True, + } + }, +] diff --git a/online_test/urls.py b/online_test/urls.py index 0415511..9c55574 100644 --- a/online_test/urls.py +++ b/online_test/urls.py @@ -3,11 +3,11 @@ from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() -urlpatterns = patterns('', +urlpatterns = [ # Examples: # url(r'^$', 'online_test.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^exam/', include('yaksh.urls')), -) +] diff --git a/requirements.txt b/requirements.txt index d4328cc..f717e09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -django==1.6, +django==1.9.5, mysql-python==1.2.5, -django-taggit==0.12.2,
\ No newline at end of file +django-taggit==0.18.1, @@ -23,9 +23,9 @@ setup( description='A django app to conduct online tests.', long_description=README, install_requires=[ - 'django==1.6', + 'django==1.9.5', 'mysql-python==1.2.5', - 'django-taggit==0.12.2', + 'django-taggit==0.18.1', ], classifiers=[ 'Development Status :: 4 - Beta', diff --git a/yaksh/forms.py b/yaksh/forms.py index 6ad388f..84cf1c4 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -136,12 +136,14 @@ class QuizForm(forms.ModelForm): super(QuizForm, self).__init__(*args, **kwargs) self.fields['prerequisite'] = forms.ModelChoiceField( queryset=Quiz.objects.filter(course__creator=user)) + self.fields['prerequisite'].required = False self.fields['course'] = forms.ModelChoiceField( queryset=Course.objects.filter(creator=user)) class Meta: model = Quiz + fields = '__all__' class QuestionForm(forms.ModelForm): @@ -150,6 +152,7 @@ class QuestionForm(forms.ModelForm): class Meta: model = Question + fields = '__all__' class RandomQuestionForm(forms.Form): @@ -176,7 +179,7 @@ class QuestionFilterForm(forms.Form): (choices=question_types)) -TestCaseFormSet = inlineformset_factory(Question, TestCase,\ +TestCaseFormSet = inlineformset_factory(Question, TestCase, fields='__all__', can_order=False, can_delete=False, extra=1) diff --git a/yaksh/models.py b/yaksh/models.py index 856698f..9b92791 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -70,7 +70,7 @@ class Course(models.Model): students = models.ManyToManyField(User, related_name='students') requests = models.ManyToManyField(User, related_name='requests') rejected = models.ManyToManyField(User, related_name='rejected') - created_on = models.DateTimeField(default=datetime.now()) + created_on = models.DateTimeField(auto_now_add=True) def request(self, *users): self.requests.add(*users) diff --git a/yaksh/tests.py b/yaksh/tests.py index d8e108a..d6d1d91 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -1,4 +1,4 @@ -from django.utils import unittest +import unittest from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, TestCase, Course import json diff --git a/yaksh/urls.py b/yaksh/urls.py index 3a75947..b2f894f 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -1,75 +1,77 @@ from django.conf.urls import patterns, url +from yaksh import views +from django.contrib.auth.views import password_reset, password_reset_confirm,\ + password_reset_done, password_reset_complete -urlpatterns = patterns('django.contrib.auth.views', - url(r'^forgotpassword/$', 'password_reset', name="password_reset"), +urlpatterns = [ + url(r'^forgotpassword/$', password_reset, name="password_reset"), url(r'^password_reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', - 'password_reset_confirm', name='password_reset_confirm'), - url(r'^password_reset/mail_sent/$', 'password_reset_done', + password_reset_confirm, name='password_reset_confirm'), + url(r'^password_reset/mail_sent/$', password_reset_done, name='password_reset_done'), - url(r'^password_reset/complete/$', 'password_reset_complete', + url(r'^password_reset/complete/$', password_reset_complete, name='password_reset_complete'), -) -urlpatterns += patterns('yaksh.views', - url(r'^$', 'index'), - url(r'^login/$', 'user_login'), - url(r'^quizzes/$', 'quizlist_user'), - url(r'^results/$', 'results_user'), - url(r'^start/$', 'start'), - url(r'^start/(?P<questionpaper_id>\d+)/$', 'start'), - url(r'^start/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$', 'start'), - url(r'^quit/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$', 'quit'), - url(r'^complete/$', 'complete'), +] +urlpatterns += [ + url(r'^$', views.index), + url(r'^login/$', views.user_login), + url(r'^quizzes/$', views.quizlist_user), + url(r'^results/$', views.results_user), + url(r'^start/$', views.start), + url(r'^start/(?P<questionpaper_id>\d+)/$', views.start), + url(r'^start/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$', views.start), + url(r'^quit/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$', views.quit), + url(r'^complete/$', views.complete), url(r'^complete/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$',\ - 'complete'), - url(r'^register/$', 'user_register'), - url(r'^(?P<q_id>\d+)/check/$', 'check'), + views.complete), + url(r'^register/$', views.user_register), + url(r'^(?P<q_id>\d+)/check/$', views.check), url(r'^(?P<q_id>\d+)/check/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$',\ - 'check'), + views.check), url(r'^(?P<q_id>\d+)/skip/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$', - 'skip'), + views.skip), url(r'^(?P<q_id>\d+)/skip/(?P<next_q>\d+)/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$', - 'skip'), - url(r'^enroll_request/(?P<course_id>\d+)/$', 'enroll_request'), - url(r'^self_enroll/(?P<course_id>\d+)/$', 'self_enroll'), + views.skip), + url(r'^enroll_request/(?P<course_id>\d+)/$', views.enroll_request), + url(r'^self_enroll/(?P<course_id>\d+)/$', views.self_enroll), - url(r'^manage/$', 'prof_manage'), - url(r'^manage/addquestion/$', 'add_question'), - url(r'^manage/addquestion/(?P<question_id>\d+)/$', 'add_question'), - url(r'^manage/addquiz/$', 'add_quiz'), - url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', 'add_quiz'), - url(r'^manage/gradeuser/$', 'show_all_users'), + url(r'^manage/$', views.prof_manage), + url(r'^manage/addquestion/$', views.add_question), + url(r'^manage/addquestion/(?P<question_id>\d+)/$', views.add_question), + url(r'^manage/addquiz/$', views.add_quiz), + url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', views.add_quiz), + url(r'^manage/gradeuser/$', views.show_all_users), url(r'^manage/gradeuser/(?P<username>.*)/(?P<questionpaper_id>\d+)/$', - 'grade_user'), - url(r'^manage/gradeuser/(?P<username>.*)/$', 'grade_user'), - url(r'^manage/questions/$', 'show_all_questions'), - url(r'^manage/monitor/$', 'monitor'), - url(r'^manage/showquestionpapers/$', 'show_all_questionpapers'), + views.grade_user), + url(r'^manage/gradeuser/(?P<username>.*)/$', views.grade_user), + url(r'^manage/questions/$', views.show_all_questions), + url(r'^manage/monitor/$', views.monitor), + url(r'^manage/showquestionpapers/$', views.show_all_questionpapers), url(r'^manage/showquestionpapers/(?P<questionpaper_id>\d+)/$',\ - 'show_all_questionpapers'), - url(r'^manage/monitor/(?P<questionpaper_id>\d+)/$', 'monitor'), + views.show_all_questionpapers), + url(r'^manage/monitor/(?P<questionpaper_id>\d+)/$', views.monitor), url(r'^manage/user_data/(?P<username>.*)/(?P<questionpaper_id>\d+)/$', - 'user_data'), - url(r'^manage/user_data/(?P<username>.*)/$', 'user_data'), - url(r'^manage/designquestionpaper/$', 'design_questionpaper'), + views.user_data), + url(r'^manage/user_data/(?P<username>.*)/$', views.user_data), + url(r'^manage/designquestionpaper/$', views.design_questionpaper), url(r'^manage/designquestionpaper/(?P<questionpaper_id>\d+)/$',\ - 'design_questionpaper'), + views.design_questionpaper), url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/$', - 'show_statistics'), + views.show_statistics), url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/(?P<attempt_number>\d+)/$', - 'show_statistics'), + views.show_statistics), url(r'^manage/monitor/download_csv/(?P<questionpaper_id>\d+)/$', - 'download_csv'), - url(r'manage/courses/$', 'courses'), - url(r'manage/add_course/$', 'add_course'), - url(r'manage/course_detail/(?P<course_id>\d+)/$', 'course_detail'), - url(r'manage/enroll/(?P<course_id>\d+)/(?P<user_id>\d+)/$', 'enroll'), + views.download_csv), + url(r'manage/courses/$', views.courses), + url(r'manage/add_course/$', views.add_course), + url(r'manage/course_detail/(?P<course_id>\d+)/$', views.course_detail), + url(r'manage/enroll/(?P<course_id>\d+)/(?P<user_id>\d+)/$', views.enroll), url(r'manage/enroll/rejected/(?P<course_id>\d+)/(?P<user_id>\d+)/$', - 'enroll', {'was_rejected': True}), - url(r'manage/reject/(?P<course_id>\d+)/(?P<user_id>\d+)/$', 'reject'), + views.enroll, {'was_rejected': True}), + url(r'manage/reject/(?P<course_id>\d+)/(?P<user_id>\d+)/$', views.reject), url(r'manage/enrolled/reject/(?P<course_id>\d+)/(?P<user_id>\d+)/$', - 'reject', {'was_enrolled': True}), - url(r'manage/toggle_status/(?P<course_id>\d+)/$', 'toggle_course_status'), - url(r'^ajax/questionpaper/(?P<query>.+)/$', 'ajax_questionpaper'), - url(r'^ajax/questions/filter/$', 'ajax_questions_filter'), - -) + views.reject, {'was_enrolled': True}), + url(r'manage/toggle_status/(?P<course_id>\d+)/$', views.toggle_course_status), + url(r'^ajax/questionpaper/(?P<query>.+)/$', views.ajax_questionpaper), + url(r'^ajax/questions/filter/$', views.ajax_questions_filter), +] diff --git a/yaksh/views.py b/yaksh/views.py index c65fb26..8b0a131 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -359,9 +359,7 @@ def start(request, questionpaper_id=None, attempt_num=None): context_instance=ci) else: ip = request.META['REMOTE_ADDR'] - try: - profile = user.get_profile() - except Profile.DoesNotExist: + if not hasattr(user, 'profile'): msg = 'You do not have a profile and cannot take the quiz!' raise Http404(msg) new_paper = quest_paper.make_answerpaper(user, ip, attempt_num) @@ -724,11 +722,7 @@ def get_user_data(username, questionpaper_id=None): '-attempt_number') data = {} - try: - profile = user.get_profile() - except Profile.DoesNotExist: - # Admin user may have a paper by accident but no profile. - profile = None + profile = user.profile if hasattr(user, 'profile') else None data['user'] = user data['profile'] = profile data['papers'] = papers |