Esempio n. 1
0
    def get(self):
        key = self.request.params.get("_key")
        if key:
            template = ProblemTemplate.retrieve(ProblemTemplate, key)
            problemName = template.problemName
            self.variables = []
            for v in Variable.all().ancestor(template):
                varDomains = {"name": v.name, "type": Domain.internalToExternalType(v.domain.type)}
                self.variables.append(varDomains)
        else:
            problemName = self.request.params["problemName"]
            template = ProblemTemplate(problemName)
            problem = Category.allProblems[problemName]
            self.variables = []
            for v in problem.variables:
                varDomains = {"name": v.name, "type": Domain.internalToExternalType(Domain.ANY)}
                self.variables.append(varDomains)

        self.template_values = {
            "problemName": problemName,
            "template": template,
            "variables": self.variables,
            "deleted": False,
            "preview": "",
        }
        FormHandler.get(self)
Esempio n. 2
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)