parameters: (request, questionpaper_id=None, attempt_num=None, course_id=None,
            module_id=None)
docstring: Check the user cedentials and if any quiz is available,
      start the exam.
docstring_summary: Check the user cedentials and if any quiz is available,
      start the exam.
docstring_tokens: Check the user cedentials and if any quiz is available start the exam .
function: def start(request, questionpaper_id=None, attempt_num=None, course_id=None,
            module_id=None):
      """Check the user cedentials and if any quiz is available,
      start the exam."""
      user = request.user
      # check conditions
      try:
          quest_paper = QuestionPaper.objects.get(id=questionpaper_id)
      except QuestionPaper.DoesNotExist:
          msg = 'Quiz not found, please contact your '\
              'instructor/administrator.'
          if is_moderator(user):
              return prof_manage(request, msg=msg)
          return view_module(request, module_id=module_id, course_id=course_id,
                             msg=msg)
      if not quest_paper.has_questions():
          msg = 'Quiz does not have Questions, please contact your '\
              'instructor/administrator.'
          if is_moderator(user):
              return prof_manage(request, msg=msg)
          return view_module(request, module_id=module_id, course_id=course_id,
                             msg=msg)
      course = Course.objects.get(id=course_id)
      learning_module = course.learning_module.get(id=module_id)
      learning_unit = learning_module.learning_unit.get(quiz=quest_paper.quiz.id)
  
      # unit module active status
      if not learning_module.active:
          return view_module(request, module_id, course_id)
  
      # unit module prerequiste check
      if learning_module.has_prerequisite():
          if not learning_module.is_prerequisite_complete(user, course):
              msg = "You have not completed the module previous to {0}".format(
                  learning_module.name)
              return course_modules(request, course_id, msg)
  
      if learning_module.check_prerequisite_passes:
          if not learning_module.is_prerequisite_passed(user, course):
              msg = (
                  "You have not successfully passed the module"
                  " previous to {0}".format(learning_module.name)
              )
              return course_modules(request, course_id, msg)
  
      # is user enrolled in the course
      if not course.is_enrolled(user):
          msg = 'You are not enrolled in {0} course'.format(course.name)
          if is_moderator(user) and course.is_trial:
              return prof_manage(request, msg=msg)
          return quizlist_user(request, msg=msg)
  
      # if course is active and is not expired
      if not course.active or not course.is_active_enrollment():
          msg = "{0} is either expired or not active".format(course.name)
          if is_moderator(user) and course.is_trial:
              return prof_manage(request, msg=msg)
          return quizlist_user(request, msg=msg)
  
      # is quiz is active and is not expired
      if quest_paper.quiz.is_expired() or not quest_paper.quiz.active:
          msg = "{0} is either expired or not active".format(
              quest_paper.quiz.description)
          if is_moderator(user) and course.is_trial:
              return prof_manage(request, msg=msg)
          return view_module(request, module_id=module_id, course_id=course_id,
                             msg=msg)
  
      # prerequisite check and passing criteria for quiz
      if learning_unit.has_prerequisite():
          if not learning_unit.is_prerequisite_complete(
                  user, learning_module, course):
              msg = "You have not completed the previous Lesson/Quiz/Exercise"
              if is_moderator(user) and course.is_trial:
                  return prof_manage(request, msg=msg)
              return view_module(request, module_id=module_id,
                                 course_id=course_id, msg=msg)
  
      # update course status with current unit
      _update_unit_status(course_id, user, learning_unit)
  
      # if any previous attempt
      last_attempt = AnswerPaper.objects.get_user_last_attempt(
          quest_paper, user, course_id)
  
      if last_attempt:
          if last_attempt.is_attempt_inprogress():
              return show_question(
                  request, last_attempt.current_question(), last_attempt,
                  course_id=course_id, module_id=module_id,
                  previous_question=last_attempt.current_question()
              )
          attempt_number = last_attempt.attempt_number + 1
      else:
          attempt_number = 1
  
      # allowed to start
      if not quest_paper.can_attempt_now(user, course_id)[0]:
          msg = quest_paper.can_attempt_now(user, course_id)[1]
          if is_moderator(user):
              return prof_manage(request, msg=msg)
          return complete(
              request, msg, last_attempt.attempt_number, quest_paper.id,
              course_id=course_id, module_id=module_id
          )
  
      if attempt_num is None and not quest_paper.quiz.is_exercise:
          context = {
              'user': user,
              'questionpaper': quest_paper,
              'attempt_num': attempt_number,
              'course': course,
              'module': learning_module,
          }
          if is_moderator(user):
              context["status"] = "moderator"
          return my_render_to_response(request, 'yaksh/intro.html', context)
      else:
          ip = request.META['REMOTE_ADDR']
          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_number,
                                                   course_id)
          if new_paper.status == 'inprogress':
              return show_question(
                  request, new_paper.current_question(),
                  new_paper, course_id=course_id,
                  module_id=module_id, previous_question=None
              )
          else:
              msg = 'You have already finished the quiz!'
              raise Http404(msg)
function_tokens: def start ( request , questionpaper_id = None , attempt_num = None , course_id = None , module_id = None ) : user = request . user # check conditions try : quest_paper = QuestionPaper . objects . get ( id = questionpaper_id ) except QuestionPaper . DoesNotExist : msg = 'Quiz not found, please contact your ' 'instructor/administrator.' if is_moderator ( user ) : return prof_manage ( request , msg = msg ) return view_module ( request , module_id = module_id , course_id = course_id , msg = msg ) if not quest_paper . has_questions ( ) : msg = 'Quiz does not have Questions, please contact your ' 'instructor/administrator.' if is_moderator ( user ) : return prof_manage ( request , msg = msg ) return view_module ( request , module_id = module_id , course_id = course_id , msg = msg ) course = Course . objects . get ( id = course_id ) learning_module = course . learning_module . get ( id = module_id ) learning_unit = learning_module . learning_unit . get ( quiz = quest_paper . quiz . id ) # unit module active status if not learning_module . active : return view_module ( request , module_id , course_id ) # unit module prerequiste check if learning_module . has_prerequisite ( ) : if not learning_module . is_prerequisite_complete ( user , course ) : msg = "You have not completed the module previous to {0}" . format ( learning_module . name ) return course_modules ( request , course_id , msg ) if learning_module . check_prerequisite_passes : if not learning_module . is_prerequisite_passed ( user , course ) : msg = ( "You have not successfully passed the module" " previous to {0}" . format ( learning_module . name ) ) return course_modules ( request , course_id , msg ) # is user enrolled in the course if not course . is_enrolled ( user ) : msg = 'You are not enrolled in {0} course' . format ( course . name ) if is_moderator ( user ) and course . is_trial : return prof_manage ( request , msg = msg ) return quizlist_user ( request , msg = msg ) # if course is active and is not expired if not course . active or not course . is_active_enrollment ( ) : msg = "{0} is either expired or not active" . format ( course . name ) if is_moderator ( user ) and course . is_trial : return prof_manage ( request , msg = msg ) return quizlist_user ( request , msg = msg ) # is quiz is active and is not expired if quest_paper . quiz . is_expired ( ) or not quest_paper . quiz . active : msg = "{0} is either expired or not active" . format ( quest_paper . quiz . description ) if is_moderator ( user ) and course . is_trial : return prof_manage ( request , msg = msg ) return view_module ( request , module_id = module_id , course_id = course_id , msg = msg ) # prerequisite check and passing criteria for quiz if learning_unit . has_prerequisite ( ) : if not learning_unit . is_prerequisite_complete ( user , learning_module , course ) : msg = "You have not completed the previous Lesson/Quiz/Exercise" if is_moderator ( user ) and course . is_trial : return prof_manage ( request , msg = msg ) return view_module ( request , module_id = module_id , course_id = course_id , msg = msg ) # update course status with current unit _update_unit_status ( course_id , user , learning_unit ) # if any previous attempt last_attempt = AnswerPaper . objects . get_user_last_attempt ( quest_paper , user , course_id ) if last_attempt : if last_attempt . is_attempt_inprogress ( ) : return show_question ( request , last_attempt . current_question ( ) , last_attempt , course_id = course_id , module_id = module_id , previous_question = last_attempt . current_question ( ) ) attempt_number = last_attempt . attempt_number + 1 else : attempt_number = 1 # allowed to start if not quest_paper . can_attempt_now ( user , course_id ) [ 0 ] : msg = quest_paper . can_attempt_now ( user , course_id ) [ 1 ] if is_moderator ( user ) : return prof_manage ( request , msg = msg ) return complete ( request , msg , last_attempt . attempt_number , quest_paper . id , course_id = course_id , module_id = module_id ) if attempt_num is None and not quest_paper . quiz . is_exercise : context = { 'user' : user , 'questionpaper' : quest_paper , 'attempt_num' : attempt_number , 'course' : course , 'module' : learning_module , } if is_moderator ( user ) : context [ "status" ] = "moderator" return my_render_to_response ( request , 'yaksh/intro.html' , context ) else : ip = request . META [ 'REMOTE_ADDR' ] 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_number , course_id ) if new_paper . status == 'inprogress' : return show_question ( request , new_paper . current_question ( ) , new_paper , course_id = course_id , module_id = module_id , previous_question = None ) else : msg = 'You have already finished the quiz!' raise Http404 ( msg )