コード例 #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()
コード例 #2
0
ファイル: web.py プロジェクト: cjlee112/socraticqs
    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()
コード例 #3
0
class Server(object):
    '''provides dynamic interfaces for students and instructor.
    Intended to be run from Python console, retaining control via the
    console thread; the cherrypy server runs using background threads.'''
    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()

    def serve_question(self, question):
        'set the question to be posed to the students'
        self.question = question
        question.courseDB = self.courseDB
        question.server = self
        self.questions[question.id] = question  # add to our lookup

    def start(self):
        'start cherrypy server as background thread, retaining control of main thread'
        self.threadID = thread.start_new_thread(self.serve_forever, ())

    def serve_forever(self):
        cherrypy.engine.start()

    # student interfaces
    def index(self):
        try:
            uid = cherrypy.session['UID']
        except KeyError:
            if self.registerAll:
                return self._registerHTML
            else:
                return self._loginHTML

        try:
            return self.question._viewHTML['answer']
        except AttributeError:
            return """The instructor has not yet assigned a question.
            Please click your browser's refresh button when your
            instructor tells you to load the first question."""

    index.exposed = True

    def login_form(self):
        return self._loginHTML

    login_form.exposed = True

    def login(self, username, uid):
        username = username.lower()
        try:
            uid = int(uid)
        except ValueError:
            return """Your UID must be an integer! Please click your
            browser's Back button and correct your UID."""
        try:
            self.courseDB.authenticate(uid, username)
        except ValueError, e:
            return str(e) + ' <A HREF="index">Continue</A>'
        self.courseDB.login(uid, username)
        return self._reloadHTML
コード例 #4
0
ファイル: web.py プロジェクト: cjlee112/socraticqs
class Server(object):
    '''provides dynamic interfaces for students and instructor.
    Intended to be run from Python console, retaining control via the
    console thread; the cherrypy server runs using background threads.'''
    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()
    
    def serve_question(self, question):
        'set the question to be posed to the students'
        self.question = question
        question.courseDB = self.courseDB
        question.server = self
        self.questions[question.id] = question # add to our lookup
        
    def start(self):
        'start cherrypy server as background thread, retaining control of main thread'
        self.threadID = thread.start_new_thread(self.serve_forever, ())

    def serve_forever(self):
        cherrypy.engine.start()

    # student interfaces
    def index(self):
        try:
            uid = cherrypy.session['UID']
        except KeyError:
            if self.registerAll:
                return self._registerHTML
            else:
                return self._loginHTML
            
        try:
            return self.question._viewHTML['answer']
        except AttributeError:
            return """The instructor has not yet assigned a question.
            Please click your browser's refresh button when your
            instructor tells you to load the first question."""
    index.exposed = True

    def login_form(self):
        return self._loginHTML
    login_form.exposed = True

    def login(self, username, uid):
        username = username.lower()
        try:
            uid = int(uid)
        except ValueError:
            return """Your UID must be an integer! Please click your
            browser's Back button and correct your UID."""
        try:
            self.courseDB.authenticate(uid, username)
        except ValueError, e:
            return str(e) + ' <A HREF="index">Continue</A>'
        self.courseDB.login(uid, username)
        return self._reloadHTML