Пример #1
0
 def post(self):
   mobile = self.request.get('mobile')
   browser = self.request.get('browser')
   logging.info("Mobile: %s, User Agent: %s Browser %s" % (mobile, self.request.user_agent, browser))
   self.response.headers['Content-Type'] = 'text/html'
   if bool(RE_MOBILE_NUMBER.search(mobile)) and len(mobile) == 10 and mobile != '9876543210':
     path = os.path.join(os.path.dirname(__file__), "../registration_done.html")
     learner = Learner.retrieve(Learner, mobile)
     if not learner:
       learner = Learner()
       learner.MobileNumber = db.PhoneNumber(mobile)
       learner.UserAgent = self.request.user_agent
       learner.Channel = 'WEB' if (browser == 'true') else 'APP'
       learner.MotherTongue = 1 # Hindi
       learner.Status = simplejson.dumps({'id': str(mobile)})
       learner.put()
       self.response.headers['Set-Cookie'] =  Cookie.get_maza_cookie_str(learner.Status)
       if browser == 'false':
         self.redirect('/' + mobile)
     else: 
       # Learner already existed, take him to lesson 1
       self.redirect('/' + mobile);
   else:
     path = os.path.join(os.path.dirname(__file__), "../registration_fail.html")
   self.response.out.write(template.render(path, {'mobile' : mobile}))
Пример #2
0
  def get(self):
    key = self.request.params.get('_key')
    idval = self.request.params.get(Learner.id_field)
    learner = None
    if key:
      learner = Learner.retrieve(Learner, key)
    elif idval:
      learner = Learner.retrieve(Learner, idval)

    if not learner:
      learner = Learner()
      if idval:
        learner.MobileNumber = db.PhoneNumber(idval)
      
    self.template_values = {
      'learner' : learner,
      'deleted': False,
    }
    FormHandler.get(self)
Пример #3
0
 def parse_maza(cookies):
   # Retrieve tracking cookie to find stats for this user
   
   if not 'maza' in cookies:
     return (None, None, None)
   
   cookie = urllib.unquote(cookies['maza'])
   if cookie:
     try:
       tracker = simplejson.loads(cookie)
       mobile = tracker['id']
       learner = Learner.retrieve(Learner, mobile)
       return (cookie, mobile, learner)
     except simplejson.JSONDecodeError:
       pass
   return (None, None, None)
Пример #4
0
  def get(self, mobile_number):
    learner = Learner.retrieve(Learner, mobile_number)
    if not learner:
      self.redirect('/') # redirect to registration.
      return
      
    jsonData = {
      'learner' : { 'MobileNumber' : learner.MobileNumber},
      'lesson': Lesson1Data.get_data()
    }
    jsonDataStr = simplejson.dumps(jsonData)
    self.response.headers['Content-Type'] = 'text/html'
    self.response.headers['Cache-Control'] = 'max-age=3600'
    self.response.headers['Set-Cookie'] =  Cookie.get_maza_cookie_str(learner.Status)

    filename = os.path.join(os.path.dirname(__file__), "../html/lesson1.html")
    f = open(filename, "r")
    text = f.read()
    self.response.out.write(text.replace('{{JSONDATA}}', jsonDataStr))