Ejemplo n.º 1
0
  def get(self):
    domainType = self.request.get('domain', default_value='whole')
    questionType = self.request.get('type', default_value='mc')
    highlightAnswer = int(self.request.get('answermode', default_value='1'))
    syllabus = self.request.get('syllabus', default_value='BODMAS rule')
    domain = Domain.defaultDomain(Domain.externalToInternalType(domainType))
    syllabusUnits = SyllabusUnit.all().filter("name = ", syllabus)
    knowledgeUnits = [s.knowledgeUnit for s in syllabusUnits]
    modelProblems = ModelProblem.findModelProblemsMatchingKnowledgeUnits(knowledgeUnits) 
    problems = []
    tags = self.request.get_all("tag")
    numquestions = int(self.request.get('numquestions', default_value=3))
    outputFormat = self.request.get('format', default_value='json')
    self.html_form = 'html/quiz.html' if outputFormat == 'html' else 'html/quiz.json'
    
    # At least one tag must match
    while len(problems) < numquestions:
      problem = GenerateQuestionForModelProblems(modelProblems, domain, tags, questionType, highlightAnswer, outputFormat)
      logging.info("Num problems generated = " + str(len(problems)))
      if problem:
        problems.append(problem)

    self.template_values = {
      'problems' : problems,
    }
    FormHandler.get(self)
Ejemplo n.º 2
0
  def get(self):
    current_user = users.get_current_user()
    user = User.retrieve(User, current_user.nickname())
#    session = sessions.Session(writer = "cookie")
    domainType = user.domainType
    questionType = user.questionType
    if not user.answermode:
      user.answermode = '1'
    highlightAnswer = int(self.request.get('answermode', default_value=user.answermode))
    domain = Domain.defaultDomain(Domain.externalToInternalType(domainType))
    syllabusUnits = db.get(user.syllabusUnitKeys)
    knowledgeUnits = [s.knowledgeUnit for s in syllabusUnits]
    modelProblems = ModelProblem.findModelProblemsMatchingKnowledgeUnits(knowledgeUnits) 
    problems = []
    tags = self.request.get_all("tag")
    numquestions = int(self.request.get('numquestions', default_value=user.numquestions))
    format = self.request.get('format', default_value='html')
    self.html_form = 'html/quiz.html' if format == 'html' else 'html/quiz.txt'
    # Allows sub-selection of templates by matching tags.
    # At least one tag must match
    while len(problems) < numquestions:
      problem = GenerateQuestionForModelProblems(modelProblems, domain, tags, questionType, highlightAnswer, format)
      if problem:
        problems.append(problem)

    self.template_values = {
      'problems' : problems,
    }
    FormHandler.get(self)
Ejemplo n.º 3
0
 def post(self):
     template = self.processPostData()
     template.put()
     key = self.request.params.get("_key")
     problemName = template.problemName
     action = self.request.params.get("action")
     if key:
         if action == "Delete":
             for variable in Variable.all().ancestor(template):
                 variable.delete()
             template.delete()
         else:
             for variable in Variable.all().ancestor(template):
                 type = self.request.params.get(variable.name)
                 variable.setDomain(Domain.defaultDomain(Domain.externalToInternalType(type)))
                 variable.put()
     else:
         problem = Category.allProblems[problemName]
         for v in problem.variables:
             type = self.request.params.get(v.name)
             vdomain = Domain.defaultDomain(Domain.externalToInternalType(type))
             variable = Variable(name=v.name, domain=vdomain, parent=template)
             variable.put()
     self.render(template)
Ejemplo n.º 4
0
 def render(self, template):
     action = self.request.params.get("action")
     if template:
         if action == "Submit" or action == "Delete":
             self.html_form = "html/template.html"
         variables = []
         preview = ""
         if action != "Delete":
             for v in Variable.all().ancestor(template):
                 varDomains = {"name": v.name, "type": Domain.internalToExternalType(v.domain.type)}
                 variables.append(varDomains)
             defaultVarDomain = Domain.defaultDomain(Domain.WHOLE_NUMBER)
             preview = template.generateProblemStatement(defaultVarDomain, "text", False)
         self.template_values = {
             "problemName": template.problemName,
             "template": template,
             "variables": variables,
             "deleted": action == "Delete",
             "preview": preview,
         }
     FormHandler.render(self, template)