def echo(self, msg):
     if msg.getSpeechAct() != "experiment":
         #Not our hack - just echo back
         resp = self.makeResponse(msg, None, INFORM_ACT)
         resp.setVerb("HOLLA BACK")
         return resp
     
     #Special, hacky case: create an experiment context
     dt = datetime.now().isoformat()
     
     #Look by ID and name (we're expecting name)
     ctx = UserContext.findContext("DemoExperiment")
     if not ctx:
         ctx = UserContext(name="DemoExperiment")
         ctx.setPrefValue("ContextCreated", dt)
     
     ctx.setPrefValue("ContextUpdated", dt)
     
     #Add all users (and set an experimental context variable for them)
     for user in UserData.objects():
         user.setPrefValue(ctx.getName(), "UserAdded", dt)
         user.save()
         ctx.addUser(user.getId())
     ctx.save()
     
     resp = self.makeResponse(msg, None, INFORM_ACT)
     resp.setVerb("HOLLA BACK")
     resp.setSpeechAct(resp.getSpeechAct() + " => Created context " + ctx.getId())
     return resp
Ejemplo n.º 2
0
    def echo(self, msg):
        if msg.getSpeechAct() != "experiment":
            #Not our hack - just echo back
            resp = self.makeResponse(msg, None, INFORM_ACT)
            resp.setVerb("HOLLA BACK")
            return resp

        #Special, hacky case: create an experiment context
        dt = datetime.now().isoformat()

        #Look by ID and name (we're expecting name)
        ctx = UserContext.findContext("DemoExperiment")
        if not ctx:
            ctx = UserContext(name="DemoExperiment")
            ctx.setPrefValue("ContextCreated", dt)

        ctx.setPrefValue("ContextUpdated", dt)

        #Add all users (and set an experimental context variable for them)
        for user in UserData.objects():
            user.setPrefValue(ctx.getName(), "UserAdded", dt)
            user.save()
            ctx.addUser(user.getId())
        ctx.save()

        resp = self.makeResponse(msg, None, INFORM_ACT)
        resp.setVerb("HOLLA BACK")
        resp.setSpeechAct(resp.getSpeechAct() + " => Created context " +
                          ctx.getId())
        return resp
 def _findContext(self, msg, errorOnMissing=True):
     """Find and return the context matching the msg - throw an exception on error"""
     ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
     ctx = None
     if ctxId:
         #Note that the helper we call looks for ID *and* name
         ctx = UserContext.findContext(ctxId)
     if not ctx and errorOnMissing:
         raise ProcessingExcept("Error: No context with id/name = %s"%(ctxId,))
     else:
         return ctx
Ejemplo n.º 4
0
 def _findContext(self, msg, errorOnMissing=True):
     """Find and return the context matching the msg - throw an exception on error"""
     ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
     ctx = None
     if ctxId:
         #Note that the helper we call looks for ID *and* name
         ctx = UserContext.findContext(ctxId)
     if not ctx and errorOnMissing:
         raise ProcessingExcept("Error: No context with id/name = %s"%(ctxId,))
     else:
         return ctx
 def makeContext(self, msg):
     ctxName = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
     ctx = UserContext.findContext(ctxName)
     hasContext = msg.getResult()
     if hasContext and ctx:
         return self.makeResponse(msg, True, CONFIRM_ACT)
     elif hasContext and not ctx:
         #Look by ID and name (we're expecting name)
         dt = datetime.now().isoformat()
         ctx = UserContext(name=ctxName)
         ctx.setPrefValue("ContextCreated", dt)
         ctx.setPrefValue("ContextUpdated", dt)
         ctx.save()
         return self.makeResponse(msg, True, CONFIRM_ACT)
     elif not hasContext and ctx:
         # Disallow deleting contexts from here
         return self.makeResponse(msg, False, DISCONFIRM_ACT)
     else: 
         return self.makeResponse(msg, False, CONFIRM_ACT)
Ejemplo n.º 6
0
 def makeContext(self, msg):
     ctxName = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
     ctx = UserContext.findContext(ctxName)
     hasContext = msg.getResult()
     if hasContext and ctx:
         return self.makeResponse(msg, True, CONFIRM_ACT)
     elif hasContext and not ctx:
         #Look by ID and name (we're expecting name)
         dt = datetime.now().isoformat()
         ctx = UserContext(name=ctxName)
         ctx.setPrefValue("ContextCreated", dt)
         ctx.setPrefValue("ContextUpdated", dt)
         ctx.save()
         return self.makeResponse(msg, True, CONFIRM_ACT)
     elif not hasContext and ctx:
         # Disallow deleting contexts from here
         return self.makeResponse(msg, False, DISCONFIRM_ACT)
     else:
         return self.makeResponse(msg, False, CONFIRM_ACT)