コード例 #1
0
    def __init__(
            self,
            questionFile,
            enableMathJax=True,
            registerAll=False,
            adminIP='127.0.0.1',
            monitorClass=TrivialMonitor,
            mathJaxPath='/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
            configPath='cp.conf',
            rootPath='',
            shutdownFunc=None,
            **kwargs):
        if configPath:
            self.app = cherrypy.tree.mount(self, '/', configPath)
            try:
                cherrypy.config.update(self.app.config['global'])
            except KeyError:
                pass
        self.enableMathJax = enableMathJax
        if enableMathJax:
            if configPath and mathJaxPath is not None and \
               mathJaxPath.startswith('/') and \
               not check_static_path(self.app.config, mathJaxPath):
                warnings.warn('''mathJaxPath %s not accessible.  Check config.
                Falling back to MathJax CDN...''' % mathJaxPath)
                mathJaxPath = None
            if mathJaxPath is None:  # fallback to MathJax CDN
                mathJaxPath = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
            webui.Document._defaultHeader = '''<script type="text/javascript"
  src="%s">
</script>
''' % mathJaxPath
        self.adminIP = adminIP
        self.root = rootPath
        self.shutdownFunc = shutdownFunc
        self.courseDB = CourseDB(questionFile,
                                 enableMath=enableMathJax,
                                 **kwargs)
        self._registerHTML = forms.register_form()
        self.registerAll = registerAll
        self._loginHTML = forms.login_form()
        self._reloadHTML = redirect(rootPath + '/index')
        self.questions = {}
        if questionFile:
            self.serve_question(self.courseDB.questions[0])
        self.monitor = monitorClass()