summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py81
1 files changed, 20 insertions, 61 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 5d2d560..23c5a88 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -114,7 +114,7 @@ def index(request, next_url=None):
"""The start page.
"""
user = request.user
- if user.is_authenticated():
+ if user.is_authenticated:
if is_moderator(user):
return my_redirect('/exam/manage/' if not next_url else next_url)
return my_redirect("/exam/quizzes/" if not next_url else next_url)
@@ -127,7 +127,7 @@ def user_register(request):
Create a user and corresponding profile and store roll_number also."""
user = request.user
- if user.is_authenticated():
+ if user.is_authenticated:
return my_redirect("/exam/quizzes/")
context = {}
if request.method == "POST":
@@ -402,7 +402,7 @@ def prof_manage(request, msg=None):
"""Take credentials of the user with professor/moderator
rights/permissions and log in."""
user = request.user
- if not user.is_authenticated():
+ if not user.is_authenticated:
return my_redirect('/exam/login')
if not is_moderator(user):
return my_redirect('/exam/')
@@ -411,14 +411,7 @@ def prof_manage(request, msg=None):
is_trial=False).distinct().order_by("-active")
paginator = Paginator(courses, 20)
page = request.GET.get('page')
- try:
- courses = paginator.page(page)
- except PageNotAnInteger:
- # If page is not an integer, deliver first page.
- courses = paginator.page(1)
- except EmptyPage:
- # If page is out of range (e.g. 9999), deliver last page of results.
- courses = paginator.page(paginator.num_pages)
+ courses = paginator.get_page(page)
messages.info(request, msg)
context = {'user': user, 'objects': courses}
return my_render_to_response(
@@ -431,7 +424,7 @@ def user_login(request):
user = request.user
context = {}
- if user.is_authenticated():
+ if user.is_authenticated:
return index(request)
next_url = request.GET.get('next')
@@ -1048,14 +1041,7 @@ def courses(request):
is_trial=False).order_by('-active').distinct()
paginator = Paginator(courses, 30)
page = request.GET.get('page')
- try:
- courses = paginator.page(page)
- except PageNotAnInteger:
- # If page is not an integer, deliver first page.
- courses = paginator.page(1)
- except EmptyPage:
- # If page is out of range (e.g. 9999), deliver last page of results.
- courses = paginator.page(paginator.num_pages)
+ courses = paginator.get_page(page)
context = {'objects': courses, 'created': True}
return my_render_to_response(request, 'yaksh/courses.html', context)
@@ -1240,12 +1226,7 @@ def monitor(request, quiz_id=None, course_id=None):
).order_by("-active").distinct()
paginator = Paginator(courses, 30)
page = request.GET.get('page')
- try:
- courses = paginator.page(page)
- except PageNotAnInteger:
- courses = paginator.page(1)
- except EmptyPage:
- courses = paginator.page(paginator.num_pages)
+ courses = paginator.get_page(page)
context = {
"papers": [], "objects": courses, "msg": "Monitor"
}
@@ -1270,9 +1251,10 @@ def monitor(request, quiz_id=None, course_id=None):
else:
attempt_numbers = []
latest_attempts = []
- papers = AnswerPaper.objects.filter(question_paper=q_paper,
- course_id=course_id).order_by(
- 'user__profile__roll_number'
+ papers = AnswerPaper.objects.filter(
+ question_paper_id=q_paper.first().id,
+ course_id=course_id).order_by(
+ 'user__profile__roll_number'
)
users = papers.values_list('user').distinct()
for auser in users:
@@ -1317,14 +1299,9 @@ def ajax_questions_filter(request):
filter_dict['language'] = str(language)
questions = Question.objects.get_queryset().filter(
**filter_dict).order_by('id')
- paginator = Paginator(questions, 10)
+ paginator = Paginator(questions, 30)
page = request.GET.get('page')
- try:
- questions = paginator.page(page)
- except PageNotAnInteger:
- questions = paginator.page(1)
- except EmptyPage:
- questions = paginator.page(paginator.num_pages)
+ questions = paginator.get_page(page)
return my_render_to_response(
request, 'yaksh/ajax_question_filter.html', {
'questions': questions,
@@ -1518,12 +1495,7 @@ def show_all_questions(request):
upload_form = UploadFileForm()
paginator = Paginator(questions, 30)
page = request.GET.get('page')
- try:
- questions = paginator.page(page)
- except PageNotAnInteger:
- questions = paginator.page(1)
- except EmptyPage:
- questions = paginator.page(paginator.num_pages)
+ questions = paginator.get_page(page)
context['questions'] = questions
context['objects'] = questions
context['all_tags'] = all_tags
@@ -1709,12 +1681,7 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
).order_by("-active").distinct()
paginator = Paginator(courses, 30)
page = request.GET.get('page')
- try:
- courses = paginator.page(page)
- except PageNotAnInteger:
- courses = paginator.page(1)
- except EmptyPage:
- courses = paginator.page(paginator.num_pages)
+ courses = paginator.get_page(page)
context = {"objects": courses, "msg": "grade"}
if quiz_id is not None:
@@ -1729,9 +1696,8 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
if not course.is_creator(current_user) and not \
course.is_teacher(current_user):
raise Http404('This course does not belong to you')
-
has_quiz_assignments = AssignmentUpload.objects.filter(
- question_paper_id=questionpaper_id
+ question_paper_id__in=questionpaper_id
).exists()
context = {
"users": user_details,
@@ -1751,7 +1717,7 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
except IndexError:
raise Http404('No attempts for paper')
has_user_assignments = AssignmentUpload.objects.filter(
- question_paper_id=questionpaper_id,
+ question_paper_id__in=questionpaper_id,
user_id=user_id
).exists()
user = User.objects.get(id=user_id)
@@ -1784,7 +1750,8 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
paper.save()
messages.success(request, "Student data saved successfully")
- course_status = CourseStatus.objects.filter(course=course, user=user)
+ course_status = CourseStatus.objects.filter(
+ course_id=course.id, user_id=user.id)
if course_status.exists():
course_status.first().set_grade()
@@ -2621,7 +2588,6 @@ def design_module(request, module_id, course_id=None):
if "Change" in request.POST:
order_list = request.POST.get("ordered_list")
- print(order_list)
if order_list:
order_list = order_list.split(",")
for order in order_list:
@@ -2977,14 +2943,7 @@ def course_status(request, course_id):
students_no = students.count()
paginator = Paginator(students, 100)
page = request.GET.get('page')
- try:
- students = paginator.page(page)
- except PageNotAnInteger:
- # If page is not an integer, deliver first page.
- students = paginator.page(1)
- except EmptyPage:
- # If page is out of range (e.g. 9999), deliver last page of results.
- students = paginator.page(paginator.num_pages)
+ students = paginator.get_page(page)
stud_details = [(student, course.get_grade(student),
course.get_completion_percent(student),