コード例 #1
0
ファイル: account.py プロジェクト: gmacleod/lifetracker
  def get(self): # this should really be post, all these db-writes
    # unpack the values from the query string
    program = self.request.get('program')
    sms = self.request.get('sms', None) 
    invite_code_name = self.request.get('invite_code', None)

    user = self.get_user(invite_code_name)
    if not user:
      return

    if sms != None and len(sms) == 10:
      # need to check that no one has this phone number yet
      # also, validate the phone number somewhat
      user.phone = sms
      user.query_medium = 'sms' # favour sms over email
      user.put()

    metrics = None

    if program == 'casual':
      metrics = json.loads(open('scripts/casual_program.json').read())
    else:
      metrics = json.loads(open('scripts/moderate_program.json').read())

    for metric in metrics:
      if metric == None:
        continue

      # add the metric
      name = metric["name"]
      frequency = int(metric["frequency"])
      text = metric['text']
      user_email = self.request.get('user_email')
      format = metric['format']
      template = TemplateMetric.get_by_name(name)

      query = Query(
        name = name,
        # we should really do normalization inside the Query constructor,
        # but it will take some time to figure out how, lacking a nearby
        # python badass
        normalized_name = Query.normalize_name(name), 
        text = text,
        frequency = frequency,
        user = user,
        format = format,
        template = template,
      )

      query.put()
    
    self.redirect('/dashboard?first_time=true')
コード例 #2
0
ファイル: data.py プロジェクト: gmacleod/lifetracker
  def post(self):
    user = self.get_user()
    if not user:
      return

    name = self.request.get("name")
    frequency = int(self.request.get("frequency"))
    text = self.request.get('text')
    user_email = self.request.get('user_email') 
    format = self.request.get('format').lower()
    template_id = self.request.get('template_id')
    # for now, default to always 
    ask_when = ['morning', 'afternoon', 'evening']

    user = User.get_by_email(user_email)

    query = Query(
      name = name,
      # we should really do normalization inside the Query constructor,
      # but it will take some time to figure out how, lacking a nearby
      # python badass
      normalized_name = Query.normalize_name(name), 
      text = text,
      frequency = frequency,
      user = user,
      format = format,
      ask_when = ask_when,
    )
  
    if str(template_id) != "0":
      query.template = db.get(template_id)

    query.put()

    ActionLog.log('NewMetric', user)

    self.response.out.write(query.key());